Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Nov 23, 2024
1 parent b199ea6 commit c80f25e
Showing 1 changed file with 24 additions and 22 deletions.
46 changes: 24 additions & 22 deletions src/vs/workbench/contrib/chat/browser/chatSetup.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { Registry } from '../../../../platform/registry/common/platform.js';
import { IChatViewsWelcomeContributionRegistry, ChatViewsWelcomeExtensions } from './viewsWelcome/chatViewsWelcome.js';
import { IViewDescriptorService, ViewContainerLocation } from '../../../common/views.js';
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js';
import { $, addDisposableListener, EventType, getActiveElement } from '../../../../base/browser/dom.js';
import { $, addDisposableListener, EventType, getActiveElement, setVisibility } from '../../../../base/browser/dom.js';
import { ILogService, LogLevel } from '../../../../platform/log/common/log.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
import { IDialogService } from '../../../../platform/dialogs/common/dialogs.js';
Expand All @@ -43,7 +43,6 @@ import { defaultButtonStyles, defaultCheckboxStyles } from '../../../../platform
import { Button } from '../../../../base/browser/ui/button/button.js';
import { MarkdownRenderer } from '../../../../editor/browser/widget/markdownRenderer/browser/markdownRenderer.js';
import { MarkdownString } from '../../../../base/common/htmlContent.js';
import { coalesce } from '../../../../base/common/arrays.js';

const defaultChat = {
extensionId: product.defaultChatAgent?.extensionId ?? '',
Expand Down Expand Up @@ -368,61 +367,64 @@ class ChatSetupWelcomeContent extends Disposable {
this.element.appendChild($('p')).textContent = localize('setupHeader', "{0} is your AI pair programmer.", defaultChat.name);

// SKU Limited Sign-up
let telemetryCheckbox: Checkbox | undefined;
let detectionCheckbox: Checkbox | undefined;
if (this.options.entitlement !== ChatEntitlement.Unavailable) {
const skuHeader = localize({ key: 'skuHeader', comment: ['{Locked="]({0})"}'] }, "Setup will sign you up to {0} [limited access]({1}).", defaultChat.name, defaultChat.skusDocumentationUrl);
this.element.appendChild($('p')).appendChild(this._register(markdown.render(new MarkdownString(skuHeader, { isTrusted: true }))).element);
const skuHeader = localize({ key: 'skuHeader', comment: ['{Locked="]({0})"}'] }, "Setup will sign you up to {0} [limited access]({1}).", defaultChat.name, defaultChat.skusDocumentationUrl);
const skuHeaderElement = this.element.appendChild($('p')).appendChild(this._register(markdown.render(new MarkdownString(skuHeader, { isTrusted: true }))).element);

const telemetryLabel = localize('telemetryLabel', "Allow {0} to use my data, including Prompts, Suggestions, and Code Snippets, for product improvements", defaultChat.providerName);
telemetryCheckbox = this.createCheckBox(telemetryLabel, this.telemetryService.telemetryLevel === TelemetryLevel.NONE ? false : false);
const telemetryLabel = localize('telemetryLabel', "Allow {0} to use my data, including Prompts, Suggestions, and Code Snippets, for product improvements", defaultChat.providerName);
const { container: telemetryContainer, checkbox: telemetryCheckbox } = this.createCheckBox(telemetryLabel, this.telemetryService.telemetryLevel === TelemetryLevel.NONE ? false : false);

const detectionLabel = localize('detectionLabel', "Allow suggestions matching public code");
detectionCheckbox = this.createCheckBox(detectionLabel, true);
}
const detectionLabel = localize('detectionLabel', "Allow suggestions matching public code");
const { container: detectionContainer, checkbox: detectionCheckbox } = this.createCheckBox(detectionLabel, true);

// Setup Button
let setupRunning = false;

const buttonRow = this.element.appendChild($('p'));

const button = this._register(new Button(buttonRow, { ...defaultButtonStyles, supportIcons: true }));
this.updateControls(button, coalesce([telemetryCheckbox, detectionCheckbox]), false);
this.updateControls(button, [telemetryCheckbox, detectionCheckbox], false);

this._register(button.onDidClick(async () => {
setupRunning = true;
this.updateControls(button, coalesce([telemetryCheckbox, detectionCheckbox]), setupRunning);
this.updateControls(button, [telemetryCheckbox, detectionCheckbox], setupRunning);

try {
await this.setup(telemetryCheckbox?.checked, detectionCheckbox?.checked);
} finally {
setupRunning = false;
}

this.updateControls(button, coalesce([telemetryCheckbox, detectionCheckbox]), setupRunning);
this.updateControls(button, [telemetryCheckbox, detectionCheckbox], setupRunning);
}));

this._register(this.options.onDidChangeEntitlement(() => this.updateControls(button, coalesce([telemetryCheckbox, detectionCheckbox]), setupRunning)));

// Footer
const footer = localize({ key: 'privacyFooter', comment: ['{Locked="]({0})"}'] }, "By proceeding you agree to our [privacy statement]({0}). You can [learn more]({1}) about {2}.", defaultChat.privacyStatementUrl, defaultChat.documentationUrl, defaultChat.name);
this.element.appendChild($('p')).appendChild(this._register(markdown.render(new MarkdownString(footer, { isTrusted: true }))).element);

// Update based on entilement changes
this._register(this.options.onDidChangeEntitlement(() => {
if (setupRunning) {
return; // do not change when setup running
}
setVisibility(this.options.entitlement !== ChatEntitlement.Unavailable, skuHeaderElement, telemetryContainer, detectionContainer);
this.updateControls(button, [telemetryCheckbox, detectionCheckbox], setupRunning);
}));
}

private createCheckBox(label: string, checked: boolean): Checkbox {
const checkboxContainer = this.element.appendChild($('p'));
private createCheckBox(label: string, checked: boolean): { container: HTMLElement; checkbox: Checkbox } {
const container = this.element.appendChild($('p'));
const checkbox = this._register(new Checkbox(label, checked, defaultCheckboxStyles));
checkboxContainer.appendChild(checkbox.domNode);
container.appendChild(checkbox.domNode);

const telemetryCheckboxLabelContainer = checkboxContainer.appendChild($('div'));
const telemetryCheckboxLabelContainer = container.appendChild($('div'));
telemetryCheckboxLabelContainer.textContent = label;
this._register(addDisposableListener(telemetryCheckboxLabelContainer, EventType.CLICK, () => {
if (checkbox?.enabled) {
checkbox.checked = !checkbox.checked;
}
}));

return checkbox;
return { container, checkbox };
}

private updateControls(button: Button, checkboxes: Checkbox[], setupRunning: boolean): void {
Expand Down

0 comments on commit c80f25e

Please sign in to comment.