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 14, 2023
1 parent 9572cdc commit ab79304
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 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 @@ -958,7 +958,8 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
}).component();
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 @@ -984,6 +985,19 @@ export class DatabaseDialog extends ObjectManagementDialogBase<Database, Databas
return this.createGroup(localizedConstants.MemoryOptimizedFileGroupsSectionText, [this.memoryOptimizedFilegroupsTable, memoryOptimizedFileGroupButtonContainer], 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 checked checkbox value
Expand Down
9 changes: 6 additions & 3 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 | azdata.DeclarativeTableComponent): boolean { return true; }

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

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

public async open(): Promise<void> {
Expand Down Expand Up @@ -341,13 +344,13 @@ export abstract class DialogBase<DialogResult> {
let buttonComponents: azdata.ButtonComponent[] = [];
const updateButtons = (isRemoveEnabled: boolean = undefined) => {
this.onFormFieldChange();
addButtonComponent.enabled = this.addButtonEnabled(table);
removeButtonComponent.enabled = !!isRemoveEnabled;
}

addButtonComponent = this.createButton(uiLoc.AddText, addbutton.buttonAriaLabel, async () => {
await addbutton.buttonHandler(addButtonComponent);
updateButtons();
});
}, addbutton.enabled ?? true);
buttonComponents.push(addButtonComponent);

removeButtonComponent = this.createButton(uiLoc.RemoveText, removeButton.buttonAriaLabel, async () => {
Expand Down

0 comments on commit ab79304

Please sign in to comment.