Skip to content

Commit

Permalink
Filegroup Memory optimized Add button should be disabled when have on…
Browse files Browse the repository at this point in the history
…e filegroup #24309
  • Loading branch information
ssreerama committed Sep 15, 2023
1 parent e6e6085 commit f6a2b5e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
16 changes: 15 additions & 1 deletion extensions/mssql/src/objectManagement/ui/databaseDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -930,7 +930,8 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
this.memoryOptimizedFilegroupNameInput = this.getFilegroupNameInput(this.memoryOptimizedFilegroupsTable, FileGroupType.MemoryOptimizedDataFileGroup);
const addButtonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.AddFilegroupText,
buttonHandler: () => this.onAddDatabaseFileGroupsButtonClicked(this.memoryOptimizedFilegroupsTable)
buttonHandler: () => this.onAddDatabaseFileGroupsButtonClicked(this.memoryOptimizedFilegroupsTable),
enabled: this.memoryoptimizedFileGroupsTableRows.length < 1
};
const removeButtonComponent: DialogButton = {
buttonAriaLabel: localizedConstants.RemoveButton,
Expand All @@ -956,6 +957,19 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
return this.createGroup(localizedConstants.MemoryOptimizedFileGroupsSectionText, [this.memoryOptimizedFilegroupsTable, memoryOptimizedContainer], true);
}

/**
* Overrides declarative table add button enabled/disabled state
* @param table table component
* @returns table add button enabled/disabled state
*/
public override addButtonEnabled(table: azdata.TableComponent | azdata.DeclarativeTableComponent): boolean {
let enabled = true;
if (table === this.memoryOptimizedFilegroupsTable) {
enabled = this.memoryoptimizedFileGroupsTableRows.length < 1;
}
return enabled;
}

/**
* Update the default value for the filegroup
* @param arg selected checkbox event
Expand Down
8 changes: 6 additions & 2 deletions extensions/mssql/src/ui/dialogBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ export function getTableHeight(rowCount: number, minRowCount: number = DefaultMi

export interface DialogButton {
buttonAriaLabel: string;
buttonHandler: (button: azdata.ButtonComponent) => Promise<void>
buttonHandler: (button: azdata.ButtonComponent) => Promise<void>,
enabled?: boolean
}

export type TableListItemEnabledStateGetter<T> = (item: T) => boolean;
Expand Down Expand Up @@ -80,6 +81,8 @@ export abstract class DialogBase<DialogResult> {

protected removeButtonEnabled(table: azdata.TableComponent): boolean { return true; }

protected addButtonEnabled(table: azdata.TableComponent): boolean { return true; }

protected validateInput(): Promise<string[]> { return Promise.resolve([]); }

public async open(): Promise<void> {
Expand Down Expand Up @@ -295,12 +298,13 @@ export abstract class DialogBase<DialogResult> {
if (editButton !== undefined) {
editButtonComponent.enabled = tableSelectedRowsLengthCheck;
}
addButtonComponent.enabled = this.addButtonEnabled(table);
removeButtonComponent.enabled = !!isRemoveEnabled && tableSelectedRowsLengthCheck;
}
addButtonComponent = this.createButton(uiLoc.AddText, addbutton.buttonAriaLabel, async () => {
await addbutton.buttonHandler(addButtonComponent);
updateButtons();
});
}, addbutton.enabled ?? true);
buttonComponents.push(addButtonComponent);

if (editButton !== undefined) {
Expand Down

0 comments on commit f6a2b5e

Please sign in to comment.