fix find object dialog type display name issue (#23232)

This commit is contained in:
Alan Ren
2023-05-26 07:59:34 -07:00
committed by GitHub
parent 2717a9b16d
commit 1a1839ab09
4 changed files with 39 additions and 20 deletions

View File

@@ -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)
};
});
}

View File

@@ -54,7 +54,11 @@ export class DatabaseRoleDialog extends PrincipalDialogBase<ObjectManagement.Dat
}, this.objectInfo.owner, true, 'text', 210);
const browseOwnerButton = this.createButton(localizedConstants.BrowseText, localizedConstants.BrowseOwnerButtonAriaLabel, async () => {
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<ObjectManagement.Dat
const buttonContainer = this.addButtonsForTable(this.memberTable, localizedConstants.AddMemberAriaLabel, localizedConstants.RemoveMemberAriaLabel,
async () => {
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,

View File

@@ -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<FindObjectDialogResult> {
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<FindObjectDialogResult> {
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<void> {
this.dialogObject.okButton.enabled = false;
this.objectTypesTable = this.createTableList<ObjectType>(localizedConstants.ObjectTypeText,
this.objectTypesTable = this.createTableList<ObjectTypeInfo>(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<FindObjectDialogResult> {
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<FindObjectDialogResult> {
}
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);
}

View File

@@ -59,7 +59,10 @@ export class ServerRoleDialog extends PrincipalDialogBase<ObjectManagement.Serve
}, this.objectInfo.owner, !this.viewInfo.isFixedRole, 'text', 210);
const browseOwnerButton = this.createButton(localizedConstants.BrowseText, localizedConstants.BrowseOwnerButtonAriaLabel, async () => {
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<ObjectManagement.Serve
const buttonContainer = this.addButtonsForTable(this.memberTable, localizedConstants.AddMemberAriaLabel, localizedConstants.RemoveMemberAriaLabel,
async () => {
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,