mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 10:58:30 -05:00
support scripting in object management dialogs (#22429)
* user management - scripting * remove confirmation * update sts * update string
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"downloadUrl": "https://github.com/Microsoft/sqltoolsservice/releases/download/{#version#}/microsoft.sqltools.servicelayer-{#fileName#}",
|
||||
"version": "4.7.0.8",
|
||||
"version": "4.7.0.10",
|
||||
"downloadFileNames": {
|
||||
"Windows_86": "win-x86-net7.0.zip",
|
||||
"Windows_64": "win-x64-net7.0.zip",
|
||||
|
||||
@@ -1538,6 +1538,15 @@ export namespace CreateLoginRequest {
|
||||
export const type = new RequestType<CreateLoginRequestParams, void, void, void>('objectManagement/createLogin');
|
||||
}
|
||||
|
||||
export interface ScriptLoginRequestParams {
|
||||
contextId: string;
|
||||
login: mssql.ObjectManagement.Login;
|
||||
}
|
||||
|
||||
export namespace ScriptLoginRequest {
|
||||
export const type = new RequestType<ScriptLoginRequestParams, string, void, void>('objectManagement/scriptLogin');
|
||||
}
|
||||
|
||||
export interface UpdateLoginRequestParams {
|
||||
contextId: string;
|
||||
login: mssql.ObjectManagement.Login;
|
||||
@@ -1576,6 +1585,15 @@ export namespace CreateUserRequest {
|
||||
export const type = new RequestType<CreateUserRequestParams, void, void, void>('objectManagement/createUser');
|
||||
}
|
||||
|
||||
export interface ScriptUserRequestParams {
|
||||
contextId: string;
|
||||
user: mssql.ObjectManagement.User;
|
||||
}
|
||||
|
||||
export namespace ScriptUserRequest {
|
||||
export const type = new RequestType<ScriptUserRequestParams, string, void, void>('objectManagement/scriptUser');
|
||||
}
|
||||
|
||||
export interface UpdateUserRequestParams {
|
||||
contextId: string;
|
||||
user: mssql.ObjectManagement.User;
|
||||
|
||||
12
extensions/mssql/src/mssql.d.ts
vendored
12
extensions/mssql/src/mssql.d.ts
vendored
@@ -1185,6 +1185,12 @@ declare module 'mssql' {
|
||||
* @param login The login information.
|
||||
*/
|
||||
updateLogin(contextId: string, login: ObjectManagement.Login): Thenable<void>;
|
||||
/**
|
||||
* Script a login.
|
||||
* @param contextId The login view's context id.
|
||||
* @param login The login information.
|
||||
*/
|
||||
scriptLogin(contextId: string, login: ObjectManagement.Login): Thenable<string>;
|
||||
/**
|
||||
* Dispose the login view.
|
||||
* @param contextId The id of the view.
|
||||
@@ -1211,6 +1217,12 @@ declare module 'mssql' {
|
||||
* @param user The user information.
|
||||
*/
|
||||
updateUser(contextId: string, user: ObjectManagement.User): Thenable<void>;
|
||||
/**
|
||||
* Script a user.
|
||||
* @param contextId Id of the view.
|
||||
* @param user The user information.
|
||||
*/
|
||||
scriptUser(contextId: string, user: ObjectManagement.User): Thenable<string>;
|
||||
/**
|
||||
* Dispose the user view.
|
||||
* @param contextId The id of the view.
|
||||
|
||||
@@ -23,6 +23,9 @@ export const OkText: string = localize('objectManagement.OkText', "OK");
|
||||
export const LoadingDialogText: string = localize('objectManagement.loadingDialog', "Loading dialog...");
|
||||
export const FailedToRetrieveConnectionInfoErrorMessage: string = localize('objectManagement.noConnectionUriError', "Failed to retrieve the connection information, please reconnect and try again.")
|
||||
export const RenameObjectDialogTitle: string = localize('objectManagement.renameObjectDialogTitle', "Enter new name");
|
||||
export const ScriptText: string = localize('objectManagement.scriptText', "Script");
|
||||
export const ScriptGeneratedText: string = localize('objectManagement.scriptGenerated', "Script has been generated successfully. You can close the dialog to view it in the newly opened editor.")
|
||||
|
||||
|
||||
export function RefreshObjectExplorerError(error: string): string {
|
||||
return localize({
|
||||
@@ -108,6 +111,10 @@ export function RenameObjectError(objectType: string, originalName: string, newN
|
||||
}, "An error occurred while renaming {0} '{1}' to '{2}'. {3}", objectType, originalName, newName, error);
|
||||
}
|
||||
|
||||
export function ScriptError(error: string): string {
|
||||
return localize('objectManagement.scriptError', "An error occurred while generating script. {0}", error);
|
||||
}
|
||||
|
||||
export const NameText = localize('objectManagement.nameLabel', "Name");
|
||||
export const SelectedText = localize('objectManagement.selectedLabel', "Selected");
|
||||
export const GeneralSectionHeader = localize('objectManagement.generalSectionHeader', "General");
|
||||
|
||||
@@ -63,6 +63,16 @@ export class ObjectManagementService implements IObjectManagementService {
|
||||
}
|
||||
);
|
||||
}
|
||||
scriptLogin(contextId: string, login: ObjectManagement.Login): Thenable<string> {
|
||||
const params: contracts.ScriptLoginRequestParams = { contextId, login };
|
||||
return this.client.sendRequest(contracts.ScriptLoginRequest.type, params).then(
|
||||
r => { return r; },
|
||||
e => {
|
||||
this.client.logFailedRequest(contracts.ScriptLoginRequest.type, e);
|
||||
return Promise.reject(e);
|
||||
}
|
||||
);
|
||||
}
|
||||
disposeLoginView(contextId: string): Thenable<void> {
|
||||
const params: contracts.DisposeLoginViewRequestParams = { contextId };
|
||||
return this.client.sendRequest(contracts.DisposeLoginViewRequest.type, params).then(
|
||||
@@ -105,6 +115,16 @@ export class ObjectManagementService implements IObjectManagementService {
|
||||
}
|
||||
);
|
||||
}
|
||||
scriptUser(contextId: string, user: ObjectManagement.User): Thenable<string> {
|
||||
const params: contracts.ScriptUserRequestParams = { contextId, user };
|
||||
return this.client.sendRequest(contracts.ScriptUserRequest.type, params).then(
|
||||
r => { return r; },
|
||||
e => {
|
||||
this.client.logFailedRequest(contracts.ScriptUserRequest.type, e);
|
||||
return Promise.reject(e);
|
||||
}
|
||||
);
|
||||
}
|
||||
disposeUserView(contextId: string): Thenable<void> {
|
||||
const params: contracts.DisposeUserViewRequestParams = { contextId };
|
||||
return this.client.sendRequest(contracts.DisposeUserViewRequest.type, params).then(
|
||||
@@ -215,6 +235,13 @@ export class TestObjectManagementService implements IObjectManagementService {
|
||||
}, 3000);
|
||||
});
|
||||
}
|
||||
async scriptLogin(contextId: string, login: ObjectManagement.Login): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('test script');
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
async disposeLoginView(contextId: string): Promise<void> {
|
||||
}
|
||||
async initializeUserView(connectionUri: string, database: string, contextId: string, isNewObject: boolean, name: string): Promise<ObjectManagement.UserViewInfo> {
|
||||
@@ -280,6 +307,13 @@ export class TestObjectManagementService implements IObjectManagementService {
|
||||
async updateUser(contextId: string, login: ObjectManagement.User): Promise<void> {
|
||||
return this.delayAndResolve();
|
||||
}
|
||||
async scriptUser(contextId: string, login: ObjectManagement.User): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
reject('generate script for user not supported');
|
||||
}, 1000);
|
||||
});
|
||||
}
|
||||
async disposeUserView(contextId: string): Promise<void> {
|
||||
}
|
||||
async rename(connectionUri: string, objectUrn: string, newName: string): Promise<void> {
|
||||
|
||||
@@ -114,6 +114,10 @@ export class LoginDialog extends ObjectManagementDialogBase<ObjectManagement.Log
|
||||
this.formContainer.addItems(sections);
|
||||
}
|
||||
|
||||
protected async generateScript(): Promise<string> {
|
||||
return this.objectManagementService.scriptLogin(this.contextId, this.objectInfo);
|
||||
}
|
||||
|
||||
private initializeGeneralSection(): void {
|
||||
this.nameInput = this.modelView.modelBuilder.inputBox().withProps({
|
||||
ariaLabel: localizedConstants.NameText,
|
||||
|
||||
@@ -16,10 +16,11 @@ import { NodeType, TelemetryActions, TelemetryViews } from '../constants';
|
||||
import {
|
||||
CreateObjectOperationDisplayName, HelpText, LoadingDialogText,
|
||||
NameText,
|
||||
NewObjectDialogTitle, ObjectPropertiesDialogTitle, OkText, SelectedText, UpdateObjectOperationDisplayName
|
||||
NewObjectDialogTitle, ObjectPropertiesDialogTitle, OkText, ScriptError, ScriptGeneratedText, ScriptText, SelectedText, UpdateObjectOperationDisplayName
|
||||
} from '../localizedConstants';
|
||||
import { deepClone, getNodeTypeDisplayName, refreshNode } from '../utils';
|
||||
import { TelemetryReporter } from '../../telemetry';
|
||||
import { providerId } from '../../constants';
|
||||
|
||||
export const DefaultLabelWidth = 150;
|
||||
export const DefaultInputWidth = 300;
|
||||
@@ -47,6 +48,7 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
private _loadingComponent: azdata.LoadingComponent;
|
||||
private _formContainer: azdata.DivContainer;
|
||||
private _helpButton: azdata.window.Button;
|
||||
private _scriptButton: azdata.window.Button;
|
||||
|
||||
constructor(private readonly objectType: NodeType,
|
||||
docUrl: string,
|
||||
@@ -65,9 +67,10 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
this.disposables.push(this._helpButton.onClick(async () => {
|
||||
await vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(docUrl));
|
||||
}));
|
||||
this.dialogObject.customButtons = [this._helpButton];
|
||||
this.dialogObject.okButton.hidden = true;
|
||||
this._helpButton.hidden = true;
|
||||
this._scriptButton = azdata.window.createButton(ScriptText, 'left');
|
||||
this.disposables.push(this._scriptButton.onClick(async () => { await this.onScriptButtonClick(); }));
|
||||
this.dialogObject.customButtons = [this._helpButton, this._scriptButton];
|
||||
this.updateLoadingStatus(true);
|
||||
this.contextId = generateUuid();
|
||||
this.dialogObject.registerCloseValidator(async (): Promise<boolean> => {
|
||||
const confirmed = await this.onConfirmation();
|
||||
@@ -83,6 +86,7 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
protected abstract onComplete(): Promise<void>;
|
||||
protected async onDispose(): Promise<void> { }
|
||||
protected abstract validateInput(): Promise<string[]>;
|
||||
protected abstract generateScript(): Promise<string>;
|
||||
|
||||
/**
|
||||
* Dispose the information related to this view in the backend service.
|
||||
@@ -90,7 +94,7 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
protected abstract disposeView(): Promise<void>;
|
||||
|
||||
protected onObjectValueChange(): void {
|
||||
this.dialogObject.okButton.enabled = JSON.stringify(this.objectInfo) !== JSON.stringify(this._originalObjectInfo);
|
||||
this.dialogObject.okButton.enabled = this.isDirty;
|
||||
}
|
||||
|
||||
protected async onConfirmation(): Promise<boolean> {
|
||||
@@ -175,9 +179,7 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
}
|
||||
}
|
||||
});
|
||||
this.dialogObject.okButton.hidden = false;
|
||||
this._helpButton.hidden = false;
|
||||
this._loadingComponent.loading = false;
|
||||
this.updateLoadingStatus(false);
|
||||
} catch (err) {
|
||||
const actionName = this.isNewObject ? TelemetryActions.OpenNewObjectDialog : TelemetryActions.OpenPropertiesDialog;
|
||||
TelemetryReporter.createErrorEvent2(TelemetryViews.ObjectManagement, actionName, err).withAdditionalProperties({
|
||||
@@ -316,4 +318,40 @@ export abstract class ObjectManagementDialogBase<ObjectInfoType extends ObjectMa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private updateLoadingStatus(isLoading: boolean): void {
|
||||
this._scriptButton.enabled = !isLoading;
|
||||
this._helpButton.enabled = !isLoading;
|
||||
this.dialogObject.okButton.enabled = isLoading ? false : this.isDirty;
|
||||
if (this._loadingComponent) {
|
||||
this._loadingComponent.loading = isLoading;
|
||||
}
|
||||
}
|
||||
|
||||
private async onScriptButtonClick(): Promise<void> {
|
||||
this.updateLoadingStatus(true);
|
||||
try {
|
||||
const isValid = await this.runValidation();
|
||||
if (!isValid) {
|
||||
return;
|
||||
}
|
||||
const script = await this.generateScript();
|
||||
await azdata.queryeditor.openQueryDocument({ content: script }, providerId);
|
||||
this.dialogObject.message = {
|
||||
text: ScriptGeneratedText,
|
||||
level: azdata.window.MessageLevel.Information
|
||||
};
|
||||
} catch (err) {
|
||||
this.dialogObject.message = {
|
||||
text: ScriptError(getErrorMessage(err)),
|
||||
level: azdata.window.MessageLevel.Error
|
||||
};
|
||||
} finally {
|
||||
this.updateLoadingStatus(false);
|
||||
}
|
||||
}
|
||||
|
||||
private get isDirty(): boolean {
|
||||
return JSON.stringify(this.objectInfo) !== JSON.stringify(this._originalObjectInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,6 +88,10 @@ export class UserDialog extends ObjectManagementDialogBase<ObjectManagement.User
|
||||
}, 100);
|
||||
}
|
||||
|
||||
protected async generateScript(): Promise<string> {
|
||||
return this.objectManagementService.scriptUser(this.contextId, this.objectInfo);
|
||||
}
|
||||
|
||||
private initializeGeneralSection(): void {
|
||||
this.nameInput = this.modelView.modelBuilder.inputBox().withProps({
|
||||
ariaLabel: localizedConstants.NameText,
|
||||
|
||||
Reference in New Issue
Block a user