diff --git a/extensions/mssql/src/objectManagement/localizedConstants.ts b/extensions/mssql/src/objectManagement/localizedConstants.ts index 4b6354ef12..051b8c3863 100644 --- a/extensions/mssql/src/objectManagement/localizedConstants.ts +++ b/extensions/mssql/src/objectManagement/localizedConstants.ts @@ -5,6 +5,7 @@ import * as nls from 'vscode-nls'; import { ObjectManagement } from 'mssql'; +import { ObjectTypeInfo } from './ui/findObjectDialog'; const localize = nls.loadMessageBundle(); // Object Types @@ -273,3 +274,12 @@ export function getUserTypeByDisplayName(displayName: string): ObjectManagement. } throw new Error(`Unknown user type display name: ${displayName}`); } + +export function getObjectTypeInfo(typeNames: string[]): ObjectTypeInfo[] { + return typeNames.map(typeName => { + return { + name: typeName, + displayName: getNodeTypeDisplayName(typeName, true) + }; + }); +} diff --git a/extensions/mssql/src/objectManagement/ui/databaseRoleDialog.ts b/extensions/mssql/src/objectManagement/ui/databaseRoleDialog.ts index 2ba4f046a2..491d5df435 100644 --- a/extensions/mssql/src/objectManagement/ui/databaseRoleDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/databaseRoleDialog.ts @@ -54,7 +54,11 @@ export class DatabaseRoleDialog extends PrincipalDialogBase { const dialog = new FindObjectDialog(this.objectManagementService, { - objectTypes: [ObjectManagement.NodeType.ApplicationRole, ObjectManagement.NodeType.DatabaseRole, ObjectManagement.NodeType.User], + objectTypes: localizedConstants.getObjectTypeInfo([ + ObjectManagement.NodeType.ApplicationRole, + ObjectManagement.NodeType.DatabaseRole, + ObjectManagement.NodeType.User + ]), selectAllObjectTypes: true, multiSelect: false, contextId: this.contextId, @@ -78,7 +82,10 @@ export class DatabaseRoleDialog extends PrincipalDialogBase { const dialog = new FindObjectDialog(this.objectManagementService, { - objectTypes: [ObjectManagement.NodeType.DatabaseRole, ObjectManagement.NodeType.User], + objectTypes: localizedConstants.getObjectTypeInfo([ + ObjectManagement.NodeType.DatabaseRole, + ObjectManagement.NodeType.User + ]), selectAllObjectTypes: true, multiSelect: true, contextId: this.contextId, diff --git a/extensions/mssql/src/objectManagement/ui/findObjectDialog.ts b/extensions/mssql/src/objectManagement/ui/findObjectDialog.ts index 72295183f5..d2ff7287bd 100644 --- a/extensions/mssql/src/objectManagement/ui/findObjectDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/findObjectDialog.ts @@ -9,10 +9,13 @@ import { DefaultTableListItemEnabledStateGetter, DefaultMaxTableRowCount, Dialog import * as localizedConstants from '../localizedConstants'; import { getErrorMessage } from '../../utils'; -type ObjectType = string | { name: string, displayName: string }; +export interface ObjectTypeInfo { + name: string; + displayName: string; +} export interface FindObjectDialogOptions { - objectTypes: ObjectType[]; + objectTypes: ObjectTypeInfo[]; selectAllObjectTypes: boolean; multiSelect: boolean; contextId: string; @@ -37,7 +40,7 @@ export class FindObjectDialog extends DialogBase { private objectsTable: azdata.TableComponent; private objectsLoadingComponent: azdata.LoadingComponent; private result: FindObjectDialogResult; - private selectedObjectTypes: ObjectType[] = []; + private selectedObjectTypes: ObjectTypeInfo[] = []; private allObjects: mssql.ObjectManagement.SearchResultItem[] = []; constructor(private readonly objectManagementService: mssql.IObjectManagementService, private readonly options: FindObjectDialogOptions) { @@ -49,25 +52,17 @@ export class FindObjectDialog extends DialogBase { this.selectedObjectTypes = options.selectAllObjectTypes ? [...options.objectTypes] : []; } - private getObjectTypeName(objectType: ObjectType): string { - return typeof objectType === 'string' ? objectType : objectType.name; - } - - private getObjectTypeDisplayName(objectType: ObjectType): string { - return typeof objectType === 'string' ? localizedConstants.getNodeTypeDisplayName(objectType, true) : objectType.displayName; - } - protected override async initialize(): Promise { this.dialogObject.okButton.enabled = false; - this.objectTypesTable = this.createTableList(localizedConstants.ObjectTypeText, + this.objectTypesTable = this.createTableList(localizedConstants.ObjectTypeText, [localizedConstants.ObjectTypeText], this.options.objectTypes, this.selectedObjectTypes, DefaultMaxTableRowCount, DefaultTableListItemEnabledStateGetter, (item) => { - return [this.getObjectTypeDisplayName(item)]; + return [item.displayName]; }, (item1, item2) => { - return this.getObjectTypeName(item1) === this.getObjectTypeName(item2); + return item1.name === item2.name; }); this.findButton = this.createButton(localizedConstants.FindText, localizedConstants.FindText, async () => { await this.onFindObjectButtonClick(); @@ -118,7 +113,7 @@ export class FindObjectDialog extends DialogBase { this.objectsLoadingComponent.loading = true; this.findButton.enabled = false; try { - const results = await this.objectManagementService.search(this.options.contextId, this.selectedObjectTypes.map(item => this.getObjectTypeName(item))); + const results = await this.objectManagementService.search(this.options.contextId, this.selectedObjectTypes.map(item => item.name)); this.allObjects.splice(0, this.allObjects.length, ...results); let data; if (this.options.multiSelect) { @@ -147,7 +142,8 @@ export class FindObjectDialog extends DialogBase { } private getObjectRowValue(item: mssql.ObjectManagement.SearchResultItem): string[] { - const row = [item.name, this.getObjectTypeName(item.type)]; + const objectType = this.options.objectTypes.find(type => type.name === item.type); + const row = [item.name, objectType?.displayName]; if (this.options.showSchemaColumn) { row.splice(1, 0, item.schema); } diff --git a/extensions/mssql/src/objectManagement/ui/serverRoleDialog.ts b/extensions/mssql/src/objectManagement/ui/serverRoleDialog.ts index de2be177e9..64005c9c1f 100644 --- a/extensions/mssql/src/objectManagement/ui/serverRoleDialog.ts +++ b/extensions/mssql/src/objectManagement/ui/serverRoleDialog.ts @@ -59,7 +59,10 @@ export class ServerRoleDialog extends PrincipalDialogBase { const dialog = new FindObjectDialog(this.objectManagementService, { - objectTypes: [ObjectManagement.NodeType.ServerLevelLogin, ObjectManagement.NodeType.ServerLevelServerRole], + objectTypes: localizedConstants.getObjectTypeInfo([ + ObjectManagement.NodeType.ServerLevelLogin, + ObjectManagement.NodeType.ServerLevelServerRole + ]), selectAllObjectTypes: true, multiSelect: false, contextId: this.contextId, @@ -84,7 +87,10 @@ export class ServerRoleDialog extends PrincipalDialogBase { const dialog = new FindObjectDialog(this.objectManagementService, { - objectTypes: [ObjectManagement.NodeType.ServerLevelLogin, ObjectManagement.NodeType.ServerLevelServerRole], + objectTypes: localizedConstants.getObjectTypeInfo([ + ObjectManagement.NodeType.ServerLevelLogin, + ObjectManagement.NodeType.ServerLevelServerRole + ]), selectAllObjectTypes: true, multiSelect: true, contextId: this.contextId,