code refactoring (#17706)

This commit is contained in:
Alan Ren
2021-11-18 14:51:23 -08:00
committed by GitHub
parent 9bdd6aca42
commit 7cb7157821
2 changed files with 73 additions and 86 deletions

View File

@@ -1142,66 +1142,51 @@ declare module 'azdata' {
* Additional table properties. Common table properties are handled by Azure Data Studio. see {@link TableProperty} * Additional table properties. Common table properties are handled by Azure Data Studio. see {@link TableProperty}
*/ */
additionalTableProperties?: DesignerDataPropertyInfo[]; additionalTableProperties?: DesignerDataPropertyInfo[];
/**
* Whether to show columns tab. The default value is false.
*/
showColumnsTab?: boolean;
/**
* Additional table column properties. Common table columns properties are handled by Azure Data Studio. see {@link TableColumnProperty}
*/
additionalTableColumnProperties?: DesignerDataPropertyInfo[];
/**
* The properties to be displayed in the columns table. Default values are: Name, Type, Length, Precision, Scale, IsPrimaryKey, AllowNulls, DefaultValue.
*/
columnsTableProperties?: string[];
/**
* Whether user can add columns. The default value is false.
*/
canAddColumns?: boolean;
/**
* Whether user can remove columns. The default value is false.
*/
canRemoveColumns?: boolean;
/**
* Whether to show foreign keys tab. The default value is false.
*/
showForeignKeysTab?: boolean;
/**
* Additional foreign key properties. Common foreign key properties are handled by Azure Data Studio. see {@link TableForeignKeyProperty}
*/
additionalForeignKeyProperties?: DesignerDataPropertyInfo[];
/**
* The properties to be displayed in the foreign keys table. Default values are: Name, PrimaryKeyTable.
*/
foreignKeysTableProperties?: string[];
/**
* Whether user can add foreign keys. The default value is false.
*/
canAddForeignKeys?: boolean;
/**
* Whether user can remove foreign keys. The default value is false.
*/
canRemoveForeignKeys?: boolean;
/**
* Whether to show check constraints tab. The default value is false.
*/
showCheckConstraintsTab?: boolean;
/**
* Additional check constraint properties. Common check constraint properties are handled by Azure Data Studio. see {@link TableCheckConstraintProperty}
*/
additionalCheckConstraintProperties?: DesignerDataPropertyInfo[];
/**
* Whether user can add check constraints keys. The default value is false.
*/
canAddCheckConstraints?: boolean;
/**
* Whether user can remove check constraints. The default value is false.
*/
canRemoveCheckConstraints?: boolean;
/** /**
* Additional tabs. * Additional tabs.
*/ */
additionalTabs?: DesignerTab[]; additionalTabs?: DesignerTab[];
/**
* Columns table options.
* Common table columns properties are handled by Azure Data Studio. see {@link TableColumnProperty}.
* Default columns to display values are: Name, Type, Length, Precision, Scale, IsPrimaryKey, AllowNulls, DefaultValue.
*/
columnTableOptions?: TableDesignerBuiltInTableViewOptions;
/**
* Foreign keys table options.
* Common foreign key properties are handled by Azure Data Studio. see {@link TableForeignKeyProperty}.
* Default columns to display values are: Name, PrimaryKeyTable.
*/
foreignKeyTableOptions?: TableDesignerBuiltInTableViewOptions;
/**
* Check constraints table options.
* Common check constraint properties are handled by Azure Data Studio. see {@link TableCheckConstraintProperty}
* Default columns to display values are: Name, Expression.
*/
checkConstraintTableOptions?: TableDesignerBuiltInTableViewOptions;
}
export interface TableDesignerBuiltInTableViewOptions {
/**
* Whether to show the table. Default value is false.
*/
showTable?: boolean;
/**
* Properties to be displayed in the table, other properties can be accessed in the properties view.
*/
propertiesToDisplay?: string[];
/**
* Whether adding new rows is supported.
*/
canAddRows?: boolean;
/**
* Whether removing rows is supported.
*/
canRemoveRows?: boolean;
/**
* Additional properties for the entity.
*/
additionalProperties?: DesignerDataPropertyInfo[];
} }
/** /**

View File

@@ -147,16 +147,16 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
const tabs = []; const tabs = [];
if (designerInfo.view.showColumnsTab) { if (designerInfo.view.columnTableOptions?.showTable) {
tabs.push(this.getColumnsTab(designerInfo)); tabs.push(this.getColumnsTab(designerInfo.view.columnTableOptions, designerInfo.columnTypes));
} }
if (designerInfo.view.showForeignKeysTab) { if (designerInfo.view.foreignKeyTableOptions?.showTable) {
tabs.push(this.getForeignKeysTab(designerInfo)); tabs.push(this.getForeignKeysTab(designerInfo.view.foreignKeyTableOptions));
} }
if (designerInfo.view.showCheckConstraintsTab) { if (designerInfo.view.checkConstraintTableOptions?.showTable) {
tabs.push(this.getCheckConstraintsTab(designerInfo)); tabs.push(this.getCheckConstraintsTab(designerInfo.view.checkConstraintTableOptions));
} }
if (designerInfo.view.additionalTabs) { if (designerInfo.view.additionalTabs) {
@@ -209,7 +209,7 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
}; };
} }
private getColumnsTab(designerInfo: azdata.designers.TableDesignerInfo): DesignerTab { private getColumnsTab(options: azdata.designers.TableDesignerBuiltInTableViewOptions, columnTypes: string[]): DesignerTab {
const columnProperties: DesignerDataPropertyInfo[] = [ const columnProperties: DesignerDataPropertyInfo[] = [
{ {
@@ -227,7 +227,7 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
componentProperties: { componentProperties: {
title: localize('tableDesigner.columnTypeTitle', "Type"), title: localize('tableDesigner.columnTypeTitle', "Type"),
width: 100, width: 100,
values: designerInfo.columnTypes values: columnTypes
} }
}, { }, {
componentType: 'input', componentType: 'input',
@@ -278,11 +278,11 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
} }
]; ];
if (designerInfo.view.additionalTableColumnProperties) { if (options.additionalProperties) {
columnProperties.push(...designerInfo.view.additionalTableColumnProperties); columnProperties.push(...options.additionalProperties);
} }
const columnsTableProperties = designerInfo.view.columnsTableProperties?.length > 0 ? designerInfo.view.columnsTableProperties : [ const displayProperties = options.propertiesToDisplay?.length > 0 ? options.propertiesToDisplay : [
designers.TableColumnProperty.Name, designers.TableColumnProperty.Name,
designers.TableColumnProperty.Type, designers.TableColumnProperty.Type,
designers.TableColumnProperty.Length, designers.TableColumnProperty.Length,
@@ -302,18 +302,18 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
showInPropertiesView: false, showInPropertiesView: false,
componentProperties: <DesignerTableProperties>{ componentProperties: <DesignerTableProperties>{
ariaLabel: localize('tableDesigner.columnsTabTitle', "Columns"), ariaLabel: localize('tableDesigner.columnsTabTitle', "Columns"),
columns: columnsTableProperties, columns: displayProperties,
itemProperties: columnProperties, itemProperties: columnProperties,
objectTypeDisplayName: localize('tableDesigner.columnTypeName', "Column"), objectTypeDisplayName: localize('tableDesigner.columnTypeName', "Column"),
canAddRows: designerInfo.view.canAddColumns, canAddRows: options.canAddRows,
canRemoveRows: designerInfo.view.canRemoveColumns canRemoveRows: options.canRemoveRows
} }
} }
] ]
}; };
} }
private getForeignKeysTab(designerInfo: azdata.designers.TableDesignerInfo): DesignerTab { private getForeignKeysTab(options: azdata.designers.TableDesignerBuiltInTableViewOptions): DesignerTab {
const foreignKeyColumnMappingProperties: DesignerDataPropertyInfo[] = [ const foreignKeyColumnMappingProperties: DesignerDataPropertyInfo[] = [
{ {
@@ -381,19 +381,19 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
columns: [designers.ForeignKeyColumnMappingProperty.ForeignKeyColumn, designers.ForeignKeyColumnMappingProperty.PrimaryKeyColumn], columns: [designers.ForeignKeyColumnMappingProperty.ForeignKeyColumn, designers.ForeignKeyColumnMappingProperty.PrimaryKeyColumn],
itemProperties: foreignKeyColumnMappingProperties, itemProperties: foreignKeyColumnMappingProperties,
objectTypeDisplayName: '', objectTypeDisplayName: '',
canAddRows: designerInfo.view.canAddForeignKeys, canAddRows: options.canAddRows,
canRemoveRows: designerInfo.view.canRemoveColumns, canRemoveRows: options.canRemoveRows
} }
}, },
]; ];
if (designerInfo.view.additionalForeignKeyProperties) { if (options.additionalProperties) {
foreignKeyProperties.push(...designerInfo.view.additionalForeignKeyProperties); foreignKeyProperties.push(...options.additionalProperties);
} }
const foreignKeysTableProperties = designerInfo.view.foreignKeysTableProperties?.length > 0 ? designerInfo.view.foreignKeysTableProperties : [ const displayProperties = options.propertiesToDisplay?.length > 0 ? options.propertiesToDisplay : [
designers.TableForeignKeyProperty.Name, designers.TableForeignKeyProperty.Name,
designers.TableForeignKeyProperty.PrimaryKeyTable, designers.TableForeignKeyProperty.PrimaryKeyTable
]; ];
return <DesignerTab>{ return <DesignerTab>{
@@ -405,18 +405,18 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
showInPropertiesView: false, showInPropertiesView: false,
componentProperties: <DesignerTableProperties>{ componentProperties: <DesignerTableProperties>{
ariaLabel: localize('tableDesigner.foreignKeysTabTitle', "Foreign Keys"), ariaLabel: localize('tableDesigner.foreignKeysTabTitle', "Foreign Keys"),
columns: foreignKeysTableProperties, columns: displayProperties,
itemProperties: foreignKeyProperties, itemProperties: foreignKeyProperties,
objectTypeDisplayName: localize('tableDesigner.ForeignKeyTypeName', "Foreign Key"), objectTypeDisplayName: localize('tableDesigner.ForeignKeyTypeName', "Foreign Key"),
canAddRows: designerInfo.view.canAddForeignKeys, canAddRows: options.canAddRows,
canRemoveRows: designerInfo.view.canRemoveForeignKeys canRemoveRows: options.canRemoveRows
} }
} }
] ]
}; };
} }
private getCheckConstraintsTab(designerInfo: azdata.designers.TableDesignerInfo): DesignerTab { private getCheckConstraintsTab(options: azdata.designers.TableDesignerBuiltInTableViewOptions): DesignerTab {
const checkConstraintProperties: DesignerDataPropertyInfo[] = [ const checkConstraintProperties: DesignerDataPropertyInfo[] = [
{ {
componentType: 'input', componentType: 'input',
@@ -437,10 +437,12 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
} }
]; ];
if (designerInfo.view.additionalCheckConstraintProperties) { if (options.additionalProperties) {
checkConstraintProperties.push(...designerInfo.view.additionalCheckConstraintProperties); checkConstraintProperties.push(...options.additionalProperties);
} }
const displayProperties = options.propertiesToDisplay?.length > 0 ? options.propertiesToDisplay : [designers.TableCheckConstraintProperty.Name, designers.TableCheckConstraintProperty.Expression];
return <DesignerTab>{ return <DesignerTab>{
title: localize('tableDesigner.checkConstraintsTabTitle', "Check Constraints"), title: localize('tableDesigner.checkConstraintsTabTitle', "Check Constraints"),
components: [ components: [
@@ -450,11 +452,11 @@ export class TableDesignerComponentInput implements DesignerComponentInput {
showInPropertiesView: false, showInPropertiesView: false,
componentProperties: <DesignerTableProperties>{ componentProperties: <DesignerTableProperties>{
ariaLabel: localize('tableDesigner.checkConstraintsTabTitle', "Check Constraints"), ariaLabel: localize('tableDesigner.checkConstraintsTabTitle', "Check Constraints"),
columns: [designers.TableCheckConstraintProperty.Name, designers.TableCheckConstraintProperty.Expression], columns: displayProperties,
itemProperties: checkConstraintProperties, itemProperties: checkConstraintProperties,
objectTypeDisplayName: localize('tableDesigner.checkConstraintTypeName', "Check Constraint"), objectTypeDisplayName: localize('tableDesigner.checkConstraintTypeName', "Check Constraint"),
canAddRows: designerInfo.view.canAddCheckConstraints, canAddRows: options.canAddRows,
canRemoveRows: designerInfo.view.canRemoveCheckConstraints canRemoveRows: options.canRemoveRows
} }
} }
] ]