From 2e2e6e276770e294407f395942466c26957a51bd Mon Sep 17 00:00:00 2001 From: Alan Ren Date: Mon, 16 Aug 2021 10:47:39 -0700 Subject: [PATCH] remove special case (#16779) --- .../contrib/query/browser/queryActions.ts | 99 +++++-------------- .../query/test/browser/queryActions.test.ts | 8 +- .../query/test/browser/queryEditor.test.ts | 4 +- 3 files changed, 30 insertions(+), 81 deletions(-) diff --git a/src/sql/workbench/contrib/query/browser/queryActions.ts b/src/sql/workbench/contrib/query/browser/queryActions.ts index 9fa32c576c..0eb9ec2986 100644 --- a/src/sql/workbench/contrib/query/browser/queryActions.ts +++ b/src/sql/workbench/contrib/query/browser/queryActions.ts @@ -26,8 +26,7 @@ import { } from 'sql/platform/connection/common/connectionManagement'; import { QueryEditor } from 'sql/workbench/contrib/query/browser/queryEditor'; import { IQueryModelService } from 'sql/workbench/services/query/common/queryModel'; -import { SelectBox } from 'sql/base/browser/ui/selectBox/selectBox'; -import { attachEditableDropdownStyler, attachSelectBoxStyler } from 'sql/platform/theme/common/styler'; +import { attachEditableDropdownStyler } from 'sql/platform/theme/common/styler'; import { Dropdown } from 'sql/base/parts/editableDropdown/browser/dropdown'; import { Task } from 'sql/workbench/services/tasks/browser/tasksRegistry'; import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService'; @@ -578,8 +577,6 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt private _isConnected: boolean; private _databaseListDropdown: HTMLElement; private _dropdown: Dropdown; - private _databaseSelectBox: SelectBox; - private _isInAccessibilityMode: boolean; private readonly _selectDatabaseString: string = nls.localize("selectDatabase", "Select Database"); // CONSTRUCTOR ///////////////////////////////////////////////////////// @@ -588,30 +585,17 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt @IContextViewService contextViewProvider: IContextViewService, @IConnectionManagementService private readonly connectionManagementService: IConnectionManagementService, @INotificationService private readonly notificationService: INotificationService, - @IConfigurationService private readonly configurationService: IConfigurationService, @ILogService private readonly logService: ILogService ) { super(); this._databaseListDropdown = $('.databaseListDropdown'); - this._isInAccessibilityMode = this.configurationService.getValue('editor.accessibilitySupport') === 'on'; - - if (this._isInAccessibilityMode) { - this._databaseSelectBox = new SelectBox([this._selectDatabaseString], this._selectDatabaseString, contextViewProvider, undefined, { ariaLabel: this._selectDatabaseString }); - this._databaseSelectBox.render(this._databaseListDropdown); - this._databaseSelectBox.onDidSelect(e => { this.databaseSelected(e.selected); }); - this._databaseSelectBox.disable(); - - } else { - this._dropdown = new Dropdown(this._databaseListDropdown, contextViewProvider, { - strictSelection: true, - placeholder: this._selectDatabaseString, - ariaLabel: this._selectDatabaseString - }); - this._register(this._dropdown.onValueChange(s => this.databaseSelected(s))); - this._register(this._dropdown.onFocus(() => this.onDropdownFocus())); - } - - // Register event handlers + this._dropdown = new Dropdown(this._databaseListDropdown, contextViewProvider, { + strictSelection: true, + placeholder: this._selectDatabaseString, + ariaLabel: this._selectDatabaseString + }); + this._register(this._dropdown.onValueChange(s => this.databaseSelected(s))); + this._register(this._dropdown.onFocus(() => this.onDropdownFocus())); this._register(this.connectionManagementService.onConnectionChanged(params => this.onConnectionChanged(params))); } @@ -621,12 +605,7 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt } public style(styles) { - if (this._isInAccessibilityMode) { - this._databaseSelectBox.style(styles); - } - else { - this._dropdown.style(styles); - } + this._dropdown.style(styles); } public setActionContext(context: any): void { @@ -637,27 +616,15 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt } public focus(): void { - if (this._isInAccessibilityMode) { - this._databaseSelectBox.focus(); - } else { - this._dropdown.focus(); - } + this._dropdown.focus(); } public blur(): void { - if (this._isInAccessibilityMode) { - this._databaseSelectBox.blur(); - } else { - this._dropdown.blur(); - } + this._dropdown.blur(); } public attachStyler(themeService: IThemeService): IDisposable { - if (this._isInAccessibilityMode) { - return attachSelectBoxStyler(this, themeService); - } else { - return attachEditableDropdownStyler(this, themeService); - } + return attachEditableDropdownStyler(this, themeService); } // EVENT HANDLERS FROM EDITOR ////////////////////////////////////////// @@ -670,13 +637,8 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt this._isConnected = false; this._currentDatabaseName = undefined; - if (this._isInAccessibilityMode) { - this._databaseSelectBox.disable(); - this._databaseSelectBox.setOptions([this._selectDatabaseString]); - } else { - this._dropdown.enabled = false; - this._dropdown.value = ''; - } + this._dropdown.enabled = false; + this._dropdown.value = ''; } // PRIVATE HELPERS ///////////////////////////////////////////////////// @@ -768,11 +730,7 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt } private resetDatabaseName() { - if (this._isInAccessibilityMode) { - this._databaseSelectBox.selectWithOptionName(this.getCurrentDatabaseName()); - } else { - this._dropdown.value = this.getCurrentDatabaseName(); - } + this._dropdown.value = this.getCurrentDatabaseName(); } private onConnectionChanged(connParams: IConnectionParams): void { @@ -825,24 +783,15 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt private updateConnection(databaseName: string): void { this._isConnected = true; this._currentDatabaseName = databaseName; - - if (this._isInAccessibilityMode) { - this.getDatabaseNames() - .then(databaseNames => { - this._databaseSelectBox.setOptions(databaseNames); - this._databaseSelectBox.selectWithOptionName(databaseName); - }).catch(onUnexpectedError); - } else { - // Set the value immediately to the initial database so the user can see that, and then - // populate the list with just that value to avoid displaying an error while we load - // the full list of databases - this._dropdown.value = databaseName; - this._dropdown.values = [databaseName]; - this._dropdown.enabled = true; - this.getDatabaseNames().then(databaseNames => { - this._dropdown.values = databaseNames; - }).catch(onUnexpectedError); - } + // Set the value immediately to the initial database so the user can see that, and then + // populate the list with just that value to avoid displaying an error while we load + // the full list of databases + this._dropdown.value = databaseName; + this._dropdown.values = [databaseName]; + this._dropdown.enabled = true; + this.getDatabaseNames().then(databaseNames => { + this._dropdown.values = databaseNames; + }).catch(onUnexpectedError); } // TESTING PROPERTIES ////////////////////////////////////////////////// diff --git a/src/sql/workbench/contrib/query/test/browser/queryActions.test.ts b/src/sql/workbench/contrib/query/test/browser/queryActions.test.ts index 20555ef7a2..430c46adf0 100644 --- a/src/sql/workbench/contrib/query/test/browser/queryActions.test.ts +++ b/src/sql/workbench/contrib/query/test/browser/queryActions.test.ts @@ -472,7 +472,7 @@ suite('SQL QueryAction Tests', () => { connectionManagementService.setup(x => x.changeDatabase(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns(() => Promise.resolve(true)); // If I query without having initialized anything, state should be clear - listItem = new ListDatabasesActionItem(editor.object, undefined, connectionManagementService.object, undefined, configurationService.object, undefined); + listItem = new ListDatabasesActionItem(editor.object, undefined, connectionManagementService.object, undefined, undefined); assert.equal(listItem.isEnabled(), false, 'do not expect dropdown enabled unless connected'); assert.equal(listItem.currentDatabaseName, undefined, 'do not expect dropdown to have entries unless connected'); @@ -505,7 +505,7 @@ suite('SQL QueryAction Tests', () => { connectionManagementService.setup(x => x.changeDatabase(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns(() => Promise.resolve(true)); // ... Create a database dropdown that has been connected - let listItem = new ListDatabasesActionItem(editor.object, undefined, connectionManagementService.object, undefined, configurationService.object, undefined); + let listItem = new ListDatabasesActionItem(editor.object, undefined, connectionManagementService.object, undefined, undefined); listItem.onConnected(); // If: I raise a connection changed event @@ -529,7 +529,7 @@ suite('SQL QueryAction Tests', () => { connectionManagementService.setup(x => x.changeDatabase(TypeMoq.It.isAnyString(), TypeMoq.It.isAnyString())).returns(() => Promise.resolve(true)); // ... Create a database dropdown that has been connected - let listItem = new ListDatabasesActionItem(editor.object, undefined, connectionManagementService.object, undefined, configurationService.object, undefined); + let listItem = new ListDatabasesActionItem(editor.object, undefined, connectionManagementService.object, undefined, undefined); listItem.onConnected(); // If: I raise a connection changed event for the 'wrong' URI @@ -554,7 +554,7 @@ suite('SQL QueryAction Tests', () => { connectionManagementService.setup(x => x.onConnectionChanged).returns(() => dbChangedEmitter.event); // ... Create a database dropdown - let listItem = new ListDatabasesActionItem(editor.object, undefined, connectionManagementService.object, undefined, configurationService.object, undefined); + let listItem = new ListDatabasesActionItem(editor.object, undefined, connectionManagementService.object, undefined, undefined); // If: I raise a connection changed event let eventParams = { diff --git a/src/sql/workbench/contrib/query/test/browser/queryEditor.test.ts b/src/sql/workbench/contrib/query/test/browser/queryEditor.test.ts index 0b72ce23cc..06e2b0ade8 100644 --- a/src/sql/workbench/contrib/query/test/browser/queryEditor.test.ts +++ b/src/sql/workbench/contrib/query/test/browser/queryEditor.test.ts @@ -64,7 +64,7 @@ suite('SQL QueryEditor Tests', () => { instantiationService.setup(x => x.createInstance(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns((classDef, editor, action) => { if (classDef.ID) { if (classDef.ID === 'listDatabaseQueryActionItem') { - return new ListDatabasesActionItem(editor, undefined, connectionManagementService.object, undefined, configurationService.object, undefined); + return new ListDatabasesActionItem(editor, undefined, connectionManagementService.object, undefined, undefined); } } // Default @@ -292,7 +292,7 @@ suite('SQL QueryEditor Tests', () => { queryActionInstantiationService.setup(x => x.createInstance(TypeMoq.It.isAny(), TypeMoq.It.isAny(), TypeMoq.It.isAny())) .returns((definition, editor, action, selectBox) => { if (definition.ID === 'listDatabaseQueryActionItem') { - let item = new ListDatabasesActionItem(editor, undefined, connectionManagementService.object, undefined, configurationService.object, undefined); + let item = new ListDatabasesActionItem(editor, undefined, connectionManagementService.object, undefined, undefined); return item; } // Default