/*--------------------------------------------------------------------------------------------- * Copyright (c) Microsoft Corporation. All rights reserved. * Licensed under the Source EULA. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as azdata from 'azdata'; import { ObjectManagementDialogBase, ObjectManagementDialogOptions } from './objectManagementDialogBase'; import { IObjectManagementService } from 'mssql'; import * as localizedConstants from '../localizedConstants'; import { CreateDatabaseDocUrl } from '../constants'; import { Database, DatabaseViewInfo } from '../interfaces'; export class DatabaseDialog extends ObjectManagementDialogBase { private _nameInput: azdata.InputBoxComponent; constructor(objectManagementService: IObjectManagementService, options: ObjectManagementDialogOptions) { super(objectManagementService, options); } protected override get helpUrl(): string { return CreateDatabaseDocUrl; } protected async initializeUI(): Promise { let components = []; components.push(this.initializeGeneralSection()); components.push(this.initializeOptionsSection()); if (this.viewInfo.isAzureDB) { components.push(this.initializeConfigureSLOSection()); } this.formContainer.addItems(components); } private initializeGeneralSection(): azdata.GroupContainer { let containers: azdata.Component[] = []; this._nameInput = this.createInputBox(localizedConstants.NameText, async () => { this.objectInfo.name = this._nameInput.value; await this.runValidation(false); }); containers.push(this.createLabelInputContainer(localizedConstants.NameText, this._nameInput)); if (this.viewInfo.loginNames?.length > 0) { this.objectInfo.owner = this.viewInfo.loginNames[0]; let ownerDropbox = this.createDropdown(localizedConstants.OwnerText, async () => { this.objectInfo.owner = ownerDropbox.value as string; }, this.viewInfo.loginNames, this.viewInfo.loginNames[0]); containers.push(this.createLabelInputContainer(localizedConstants.OwnerText, ownerDropbox)); } return this.createGroup(localizedConstants.GeneralSectionHeader, containers, false); } private initializeOptionsSection(): azdata.GroupContainer { let containers: azdata.Component[] = []; if (this.viewInfo.collationNames?.length > 0) { this.objectInfo.collationName = this.viewInfo.collationNames[0]; let collationDropbox = this.createDropdown(localizedConstants.CollationText, async () => { this.objectInfo.collationName = collationDropbox.value as string; }, this.viewInfo.collationNames, this.viewInfo.collationNames[0]); containers.push(this.createLabelInputContainer(localizedConstants.CollationText, collationDropbox)); } if (this.viewInfo.recoveryModels?.length > 0) { this.objectInfo.recoveryModel = this.viewInfo.recoveryModels[0]; let recoveryDropbox = this.createDropdown(localizedConstants.RecoveryModelText, async () => { this.objectInfo.recoveryModel = recoveryDropbox.value as string; }, this.viewInfo.recoveryModels, this.viewInfo.recoveryModels[0]); containers.push(this.createLabelInputContainer(localizedConstants.RecoveryModelText, recoveryDropbox)); } if (this.viewInfo.compatibilityLevels?.length > 0) { this.objectInfo.compatibilityLevel = this.viewInfo.compatibilityLevels[0]; let compatibilityDropbox = this.createDropdown(localizedConstants.CompatibilityLevelText, async () => { this.objectInfo.compatibilityLevel = compatibilityDropbox.value as string; }, this.viewInfo.compatibilityLevels, this.viewInfo.compatibilityLevels[0]); containers.push(this.createLabelInputContainer(localizedConstants.CompatibilityLevelText, compatibilityDropbox)); } if (this.viewInfo.containmentTypes?.length > 0) { this.objectInfo.containmentType = this.viewInfo.containmentTypes[0]; let containmentDropbox = this.createDropdown(localizedConstants.ContainmentTypeText, async () => { this.objectInfo.containmentType = containmentDropbox.value as string; }, this.viewInfo.containmentTypes, this.viewInfo.containmentTypes[0]); containers.push(this.createLabelInputContainer(localizedConstants.ContainmentTypeText, containmentDropbox)); } return this.createGroup(localizedConstants.OptionsSectionHeader, containers, true, true); } private initializeConfigureSLOSection(): azdata.GroupContainer { let containers: azdata.Component[] = []; if (this.viewInfo.azureEditions?.length > 0) { let defaultEdition = this.viewInfo.azureEditions[0]; this.objectInfo.azureEdition = defaultEdition; // Service Level Objective options let sloDetails = this.viewInfo.azureServiceLevelObjectives?.find(details => details.editionDisplayName === defaultEdition); let serviceLevels = sloDetails?.details ?? []; this.objectInfo.azureServiceLevelObjective = serviceLevels[0]; let serviceLevelDropbox = this.createDropdown(localizedConstants.CurrentSLOText, async () => { this.objectInfo.azureServiceLevelObjective = serviceLevelDropbox.value as string; }, serviceLevels, serviceLevels[0]); // Maximum Database Size options let sizeDetails = this.viewInfo.azureMaxSizes?.find(details => details.editionDisplayName === defaultEdition); let maxSizes = sizeDetails?.details ?? []; this.objectInfo.azureMaxSize = maxSizes[0]; let sizeDropbox = this.createDropdown(localizedConstants.MaxSizeText, async () => { this.objectInfo.azureMaxSize = sizeDropbox.value as string; }, maxSizes, maxSizes[0]); // Azure Database Edition options let editionDropbox = this.createDropdown(localizedConstants.EditionText, async () => { let edition = editionDropbox.value as string; this.objectInfo.azureEdition = edition; // Update dropboxes for SLO and Size, since they're edition specific sloDetails = this.viewInfo.azureServiceLevelObjectives?.find(details => details.editionDisplayName === edition); serviceLevels = sloDetails?.details ?? []; serviceLevelDropbox.loading = true; await serviceLevelDropbox.updateProperties({ value: serviceLevels[0], values: serviceLevels }); serviceLevelDropbox.loading = false; sizeDetails = this.viewInfo.azureMaxSizes?.find(details => details.editionDisplayName === edition); maxSizes = sizeDetails?.details ?? []; sizeDropbox.loading = true; await sizeDropbox.updateProperties({ value: maxSizes[0], values: maxSizes }); sizeDropbox.loading = false; }, this.viewInfo.azureEditions, defaultEdition); containers.push(this.createLabelInputContainer(localizedConstants.EditionText, editionDropbox)); containers.push(this.createLabelInputContainer(localizedConstants.CurrentSLOText, serviceLevelDropbox)); containers.push(this.createLabelInputContainer(localizedConstants.MaxSizeText, sizeDropbox)); } if (this.viewInfo.azureBackupRedundancyLevels?.length > 0) { let backupDropbox = this.createDropdown(localizedConstants.BackupRedundancyText, async () => { this.objectInfo.azureBackupRedundancyLevel = backupDropbox.value as string; }, this.viewInfo.azureBackupRedundancyLevels, this.viewInfo.azureBackupRedundancyLevels[0]); containers.push(this.createLabelInputContainer(localizedConstants.BackupRedundancyText, backupDropbox)); } return this.createGroup(localizedConstants.ConfigureSLOSectionHeader, containers, true, true); } }