Query Editor Refactor (#5528)

* query editor changes

* query editor changes

* finish converting query editor

* fix merge issue

* remove unused code

* fix tests

* fix tests

* remove editor context key class

* edit tests to test input state
This commit is contained in:
Anthony Dresser
2019-05-23 11:43:59 -07:00
committed by GitHub
parent cf8f8907ee
commit 5e8a52bcc0
18 changed files with 537 additions and 1183 deletions

View File

@@ -37,8 +37,8 @@ export abstract class QueryTaskbarAction extends Action {
private _classes: string[];
constructor(
protected _connectionManagementService: IConnectionManagementService,
protected editor: QueryEditor,
protected readonly connectionManagementService: IConnectionManagementService,
protected readonly editor: QueryEditor,
id: string,
enabledClass: string
) {
@@ -75,10 +75,10 @@ export abstract class QueryTaskbarAction extends Action {
* Public for testing only.
*/
public isConnected(editor: QueryEditor): boolean {
if (!editor || !editor.currentQueryInput) {
if (!editor || !editor.input) {
return false;
}
return this._connectionManagementService.isConnected(editor.currentQueryInput.uri);
return this.connectionManagementService.isConnected(editor.input.uri);
}
/**
@@ -87,12 +87,12 @@ export abstract class QueryTaskbarAction extends Action {
*/
protected connectEditor(editor: QueryEditor, runQueryOnCompletion?: RunQueryOnConnectionMode, selection?: ISelectionData): void {
let params: INewConnectionParams = {
input: editor.currentQueryInput,
input: editor.input,
connectionType: ConnectionType.editor,
runQueryOnCompletion: runQueryOnCompletion ? runQueryOnCompletion : RunQueryOnConnectionMode.none,
querySelection: selection
};
this._connectionManagementService.showConnectionDialog(params);
this.connectionManagementService.showConnectionDialog(params);
}
}
@@ -106,7 +106,7 @@ export class RunQueryAction extends QueryTaskbarAction {
constructor(
editor: QueryEditor,
@IQueryModelService protected _queryModelService: IQueryModelService,
@IQueryModelService protected readonly queryModelService: IQueryModelService,
@IConnectionManagementService connectionManagementService: IConnectionManagementService
) {
super(connectionManagementService, editor, RunQueryAction.ID, RunQueryAction.EnabledClass);
@@ -151,11 +151,11 @@ export class RunQueryAction extends QueryTaskbarAction {
// otherwise, either run the statement or the script depending on parameter
let selection: ISelectionData = editor.getSelection(false);
if (runCurrentStatement && selection && this.isCursorPosition(selection)) {
editor.currentQueryInput.runQueryStatement(selection);
editor.input.runQueryStatement(selection);
} else {
// get the selection again this time with trimming
selection = editor.getSelection();
editor.currentQueryInput.runQuery(selection);
editor.input.runQuery(selection);
}
}
}
@@ -176,7 +176,7 @@ export class CancelQueryAction extends QueryTaskbarAction {
constructor(
editor: QueryEditor,
@IQueryModelService private _queryModelService: IQueryModelService,
@IQueryModelService private readonly queryModelService: IQueryModelService,
@IConnectionManagementService connectionManagementService: IConnectionManagementService
) {
super(connectionManagementService, editor, CancelQueryAction.ID, CancelQueryAction.EnabledClass);
@@ -186,7 +186,7 @@ export class CancelQueryAction extends QueryTaskbarAction {
public run(): Promise<void> {
if (this.isConnected(this.editor)) {
this._queryModelService.cancelQuery(this.editor.currentQueryInput.uri);
this.queryModelService.cancelQuery(this.editor.input.uri);
}
return Promise.resolve(null);
}
@@ -202,7 +202,6 @@ export class EstimatedQueryPlanAction extends QueryTaskbarAction {
constructor(
editor: QueryEditor,
@IQueryModelService private _queryModelService: IQueryModelService,
@IConnectionManagementService connectionManagementService: IConnectionManagementService
) {
super(connectionManagementService, editor, EstimatedQueryPlanAction.ID, EstimatedQueryPlanAction.EnabledClass);
@@ -229,7 +228,7 @@ export class EstimatedQueryPlanAction extends QueryTaskbarAction {
}
if (this.isConnected(editor)) {
editor.currentQueryInput.runQuery(editor.getSelection(), {
editor.input.runQuery(editor.getSelection(), {
displayEstimatedQueryPlan: true
});
}
@@ -242,7 +241,6 @@ export class ActualQueryPlanAction extends QueryTaskbarAction {
constructor(
editor: QueryEditor,
@IQueryModelService private _queryModelService: IQueryModelService,
@IConnectionManagementService connectionManagementService: IConnectionManagementService
) {
super(connectionManagementService, editor, ActualQueryPlanAction.ID, ActualQueryPlanAction.EnabledClass);
@@ -273,7 +271,7 @@ export class ActualQueryPlanAction extends QueryTaskbarAction {
if (!selection) {
selection = editor.getAllSelection();
}
editor.currentQueryInput.runQuery(selection, {
editor.input.runQuery(selection, {
displayActualQueryPlan: true
});
}
@@ -299,7 +297,7 @@ export class DisconnectDatabaseAction extends QueryTaskbarAction {
public run(): Promise<void> {
// Call disconnectEditor regardless of the connection state and let the ConnectionManagementService
// determine if we need to disconnect, cancel an in-progress conneciton, or do nothing
this._connectionManagementService.disconnectEditor(this.editor.currentQueryInput);
this.connectionManagementService.disconnectEditor(this.editor.input);
return Promise.resolve(null);
}
}
@@ -350,22 +348,14 @@ export class ToggleConnectDatabaseAction extends QueryTaskbarAction {
public static DisconnectClass = 'disconnect';
public static ID = 'toggleConnectDatabaseAction';
private _connected: boolean;
private _connectLabel: string;
private _disconnectLabel: string;
private _connectLabel = nls.localize('connectDatabaseLabel', 'Connect');
private _disconnectLabel = nls.localize('disconnectDatabaseLabel', 'Disconnect');
constructor(
editor: QueryEditor,
isConnected: boolean,
private _connected: boolean,
@IConnectionManagementService connectionManagementService: IConnectionManagementService
) {
let enabledClass: string;
super(connectionManagementService, editor, ToggleConnectDatabaseAction.ID, enabledClass);
this._connectLabel = nls.localize('connectDatabaseLabel', 'Connect');
this._disconnectLabel = nls.localize('disconnectDatabaseLabel', 'Disconnect');
this.connected = isConnected;
super(connectionManagementService, editor, ToggleConnectDatabaseAction.ID, undefined);
}
public get connected(): boolean {
@@ -393,7 +383,7 @@ export class ToggleConnectDatabaseAction extends QueryTaskbarAction {
if (this.connected) {
// Call disconnectEditor regardless of the connection state and let the ConnectionManagementService
// determine if we need to disconnect, cancel an in-progress connection, or do nothing
this._connectionManagementService.disconnectEditor(this.editor.currentQueryInput);
this.connectionManagementService.disconnectEditor(this.editor.input);
} else {
this.connectEditor(this.editor);
}
@@ -444,14 +434,14 @@ export class ListDatabasesActionItem implements IActionViewItem {
// CONSTRUCTOR /////////////////////////////////////////////////////////
constructor(
private _editor: QueryEditor,
@IConnectionManagementService private _connectionManagementService: IConnectionManagementService,
@INotificationService private _notificationService: INotificationService,
@IContextViewService contextViewProvider: IContextViewService,
@IConfigurationService private readonly _configurationService: IConfigurationService
@IConnectionManagementService private readonly connectionManagementService: IConnectionManagementService,
@INotificationService private readonly notificationService: INotificationService,
@IConfigurationService private readonly configurationService: IConfigurationService
) {
this._toDispose = [];
this._databaseListDropdown = $('.databaseListDropdown');
this._isInAccessibilityMode = this._configurationService.getValue('editor.accessibilitySupport') === 'on';
this._isInAccessibilityMode = this.configurationService.getValue('editor.accessibilitySupport') === 'on';
if (this._isInAccessibilityMode) {
this._databaseSelectBox = new SelectBox([this._selectDatabaseString], this._selectDatabaseString, contextViewProvider, undefined, { ariaLabel: this._selectDatabaseString });
@@ -467,12 +457,11 @@ export class ListDatabasesActionItem implements IActionViewItem {
actionLabel: nls.localize('listDatabases.toggleDatabaseNameDropdown', 'Select Database Toggle Dropdown')
});
this._dropdown.onValueChange(s => this.databaseSelected(s));
this._toDispose.push(this._dropdown.onFocus(() => { self.onDropdownFocus(); }));
this._toDispose.push(this._dropdown.onFocus(() => this.onDropdownFocus()));
}
// Register event handlers
let self = this;
this._toDispose.push(this._connectionManagementService.onConnectionChanged(params => { self.onConnectionChanged(params); }));
this._toDispose.push(this.connectionManagementService.onConnectionChanged(params => this.onConnectionChanged(params)));
}
// PUBLIC METHODS //////////////////////////////////////////////////////
@@ -546,22 +535,22 @@ export class ListDatabasesActionItem implements IActionViewItem {
// PRIVATE HELPERS /////////////////////////////////////////////////////
private databaseSelected(dbName: string): void {
let uri = this._editor.connectedUri;
let uri = this._editor.input.uri;
if (!uri) {
return;
}
let profile = this._connectionManagementService.getConnectionProfile(uri);
let profile = this.connectionManagementService.getConnectionProfile(uri);
if (!profile) {
return;
}
this._connectionManagementService.changeDatabase(this._editor.uri, dbName)
this.connectionManagementService.changeDatabase(this._editor.input.uri, dbName)
.then(
result => {
if (!result) {
this.resetDatabaseName();
this._notificationService.notify({
this.notificationService.notify({
severity: Severity.Error,
message: nls.localize('changeDatabase.failed', "Failed to change database")
});
@@ -569,7 +558,7 @@ export class ListDatabasesActionItem implements IActionViewItem {
},
error => {
this.resetDatabaseName();
this._notificationService.notify({
this.notificationService.notify({
severity: Severity.Error,
message: nls.localize('changeDatabase.failedWithError', "Failed to change database {0}", error)
});
@@ -577,9 +566,9 @@ export class ListDatabasesActionItem implements IActionViewItem {
}
private getCurrentDatabaseName() {
let uri = this._editor.connectedUri;
let uri = this._editor.input.uri;
if (uri) {
let profile = this._connectionManagementService.getConnectionProfile(uri);
let profile = this.connectionManagementService.getConnectionProfile(uri);
if (profile) {
return profile.databaseName;
}
@@ -600,7 +589,7 @@ export class ListDatabasesActionItem implements IActionViewItem {
return;
}
let uri = this._editor.connectedUri;
let uri = this._editor.input.uri;
if (uri !== connParams.connectionUri) {
return;
}
@@ -609,14 +598,12 @@ export class ListDatabasesActionItem implements IActionViewItem {
}
private onDropdownFocus(): void {
let self = this;
let uri = self._editor.connectedUri;
let uri = this._editor.input.uri;
if (!uri) {
return;
}
self._connectionManagementService.listDatabases(uri)
this.connectionManagementService.listDatabases(uri)
.then(result => {
if (result && result.databaseNames) {
this._dropdown.values = result.databaseNames;
@@ -630,12 +617,11 @@ export class ListDatabasesActionItem implements IActionViewItem {
if (this._isInAccessibilityMode) {
this._databaseSelectBox.enable();
let self = this;
let uri = self._editor.connectedUri;
let uri = this._editor.input.uri;
if (!uri) {
return;
}
self._connectionManagementService.listDatabases(uri)
this.connectionManagementService.listDatabases(uri)
.then(result => {
if (result && result.databaseNames) {
this._databaseSelectBox.setOptions(result.databaseNames);