remove special case (#16779)

This commit is contained in:
Alan Ren
2021-08-16 10:47:39 -07:00
committed by GitHub
parent ea62adbb5c
commit 2e2e6e2767
3 changed files with 30 additions and 81 deletions

View File

@@ -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 //////////////////////////////////////////////////

View File

@@ -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 = <IConnectionParams>{

View File

@@ -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