Add memory inputs validation (#23685)

* memory validation

* Update extensions/mssql/src/objectManagement/localizedConstants.ts

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>

* Update extensions/mssql/src/objectManagement/localizedConstants.ts

Co-authored-by: Cory Rivera <corivera@microsoft.com>

* rename property to match sts

---------

Co-authored-by: Charles Gagnon <chgagnon@microsoft.com>
Co-authored-by: Cory Rivera <corivera@microsoft.com>
This commit is contained in:
Barbara Valdez
2023-07-07 12:36:55 -07:00
committed by GitHub
parent 8048cab162
commit a52f86bc48
4 changed files with 24 additions and 8 deletions

View File

@@ -495,8 +495,14 @@ export interface Server extends ObjectManagement.SqlObject {
serverCollation: string;
serviceTier: string;
storageSpaceUsageInMB: number;
minServerMemory: number;
maxServerMemory: number;
minServerMemory: NumericServerProperty;
maxServerMemory: NumericServerProperty;
}
export interface NumericServerProperty {
maximumValue: number;
minimumValue: number;
value: number;
}
export interface ServerViewInfo extends ObjectManagement.ObjectViewInfo<Server> {

View File

@@ -261,6 +261,7 @@ export const StorageSpaceUsageInMBText = localize('objectManagement.storageSpace
export const VersionText = localize('objectManagement.versionText', "Version");
export const minServerMemoryText = localize('objectManagement.minServerMemoryText', "Minimum Server Memory (MB)");
export const maxServerMemoryText = localize('objectManagement.maxServerMemoryText', "Maximum Server Memory (MB)");
export const serverMemoryMaxLowerThanMinInputError: string = localize('objectManagement.serverMemoryMaxLowerThanMinInputError', "Maximum server memory cannot be lower than minimum server memory")
//Database properties Dialog
export const LastDatabaseBackupText = localize('objectManagement.lastDatabaseBackup', "Last Database Backup");

View File

@@ -4,6 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import * as azdata from 'azdata';
import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase';
import { DefaultInputWidth } from '../../ui/dialogBase';
import { IObjectManagementService } from 'mssql';
import * as localizedConstants from '../localizedConstants';
import { ViewServerPropertiesDocUrl } from '../constants';
@@ -163,13 +164,13 @@ export class ServerPropertiesDialog extends ObjectManagementDialogBase<Server, S
private initializeMemorySection(): void {
const isEnabled = this.engineEdition !== azdata.DatabaseEngineEdition.SqlManagedInstance;
this.minServerMemoryInput = this.createInputBox(localizedConstants.minServerMemoryText, async (newValue) => {
this.objectInfo.minServerMemory = +newValue;
}, this.objectInfo.minServerMemory.toString(), isEnabled, 'number');
this.objectInfo.minServerMemory.value = +newValue;
}, this.objectInfo.minServerMemory.value.toString(), isEnabled, 'number', DefaultInputWidth, this.objectInfo.minServerMemory.minimumValue, this.objectInfo.minServerMemory.maximumValue);
const minMemoryContainer = this.createLabelInputContainer(localizedConstants.minServerMemoryText, this.minServerMemoryInput);
this.maxServerMemoryInput = this.createInputBox(localizedConstants.maxServerMemoryText, async (newValue) => {
this.objectInfo.maxServerMemory = +newValue;
}, this.objectInfo.maxServerMemory.toString(), isEnabled, 'number');
this.objectInfo.maxServerMemory.value = +newValue;
}, this.objectInfo.maxServerMemory.value.toString(), isEnabled, 'number', DefaultInputWidth, this.objectInfo.maxServerMemory.minimumValue, this.objectInfo.maxServerMemory.maximumValue);
const maxMemoryContainer = this.createLabelInputContainer(localizedConstants.maxServerMemoryText, this.maxServerMemoryInput);
this.memorySection = this.createGroup('', [
@@ -179,4 +180,12 @@ export class ServerPropertiesDialog extends ObjectManagementDialogBase<Server, S
this.memoryTab = this.createTab('memoryId', localizedConstants.MemoryText, this.memorySection);
}
protected override async validateInput(): Promise<string[]> {
const errors = await super.validateInput();
if (this.objectInfo.maxServerMemory.value < this.objectInfo.minServerMemory.value) {
errors.push(localizedConstants.serverMemoryMaxLowerThanMinInputError);
}
return errors;
}
}

View File

@@ -147,8 +147,8 @@ export abstract class DialogBase<DialogResult> {
return this.createInputBox(ariaLabel, textChangeHandler, value, enabled, 'password', width);
}
protected createInputBox(ariaLabel: string, textChangeHandler: (newValue: string) => Promise<void>, value: string = '', enabled: boolean = true, type: azdata.InputBoxInputType = 'text', width: number = DefaultInputWidth): azdata.InputBoxComponent {
const inputbox = this.modelView.modelBuilder.inputBox().withProps({ inputType: type, enabled: enabled, ariaLabel: ariaLabel, value: value, width: width }).component();
protected createInputBox(ariaLabel: string, textChangeHandler: (newValue: string) => Promise<void>, value: string = '', enabled: boolean = true, type: azdata.InputBoxInputType = 'text', width: number = DefaultInputWidth, min?: number, max?: number): azdata.InputBoxComponent {
const inputbox = this.modelView.modelBuilder.inputBox().withProps({ inputType: type, enabled: enabled, ariaLabel: ariaLabel, value: value, width: width, min: min, max: max }).component();
this.disposables.push(inputbox.onTextChanged(async () => {
await textChangeHandler(inputbox.value!);
this.onFormFieldChange();