mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-06 17:23:53 -05:00
DisableSchema compare dialog's Okay button if source/target isn't selected (#5557)
* Enable schema compare ok button only on filling source and target * Nit fixes
This commit is contained in:
@@ -9,6 +9,8 @@ import * as azdata from 'azdata';
|
||||
import * as vscode from 'vscode';
|
||||
import * as os from 'os';
|
||||
import { SchemaCompareResult } from '../schemaCompareResult';
|
||||
import { isNullOrUndefined } from 'util';
|
||||
import { existsSync } from 'fs';
|
||||
|
||||
const localize = nls.loadMessageBundle();
|
||||
const OkButtonText: string = localize('schemaCompareDialog.ok', 'Ok');
|
||||
@@ -76,6 +78,7 @@ export class SchemaCompareDialog {
|
||||
this.initializeDialog();
|
||||
|
||||
this.dialog.okButton.label = OkButtonText;
|
||||
this.dialog.okButton.enabled = false;
|
||||
this.dialog.okButton.onClick(async () => await this.execute());
|
||||
|
||||
this.dialog.cancelButton.label = CancelButtonText;
|
||||
@@ -147,10 +150,18 @@ export class SchemaCompareDialog {
|
||||
width: 275
|
||||
}).component();
|
||||
|
||||
this.sourceTextBox.onTextChanged((e) => {
|
||||
this.dialog.okButton.enabled = this.shouldEnableOkayButton();
|
||||
});
|
||||
|
||||
this.targetTextBox = view.modelBuilder.inputBox().withProperties({
|
||||
width: 275
|
||||
}).component();
|
||||
|
||||
this.targetTextBox.onTextChanged(() => {
|
||||
this.dialog.okButton.enabled = this.shouldEnableOkayButton();
|
||||
});
|
||||
|
||||
this.sourceServerComponent = await this.createSourceServerDropdown(view);
|
||||
await this.populateServerDropdown(false);
|
||||
|
||||
@@ -288,6 +299,7 @@ export class SchemaCompareDialog {
|
||||
this.formBuilder.removeFormItem(this.sourceServerComponent);
|
||||
this.formBuilder.removeFormItem(this.sourceDatabaseComponent);
|
||||
this.formBuilder.insertFormItem(this.sourceDacpacComponent, 2, { horizontal: true, titleFontSize: titleFontSize });
|
||||
this.dialog.okButton.enabled = this.shouldEnableOkayButton();
|
||||
});
|
||||
|
||||
// show server and db dropdowns or 'No active connections' text
|
||||
@@ -300,6 +312,7 @@ export class SchemaCompareDialog {
|
||||
this.formBuilder.insertFormItem(this.sourceNoActiveConnectionsText, 2, { horizontal: true, titleFontSize: titleFontSize });
|
||||
}
|
||||
this.formBuilder.removeFormItem(this.sourceDacpacComponent);
|
||||
this.dialog.okButton.enabled = this.shouldEnableOkayButton();
|
||||
});
|
||||
|
||||
if (this.database) {
|
||||
@@ -340,6 +353,7 @@ export class SchemaCompareDialog {
|
||||
this.formBuilder.removeFormItem(this.targetServerComponent);
|
||||
this.formBuilder.removeFormItem(this.targetDatabaseComponent);
|
||||
this.formBuilder.addFormItem(this.targetDacpacComponent, { horizontal: true, titleFontSize: titleFontSize });
|
||||
this.dialog.okButton.enabled = this.shouldEnableOkayButton();
|
||||
});
|
||||
|
||||
// show server and db dropdowns or 'No active connections' text
|
||||
@@ -352,6 +366,7 @@ export class SchemaCompareDialog {
|
||||
} else {
|
||||
this.formBuilder.addFormItem(this.targetNoActiveConnectionsText, { horizontal: true, titleFontSize: titleFontSize });
|
||||
}
|
||||
this.dialog.okButton.enabled = this.shouldEnableOkayButton();
|
||||
});
|
||||
|
||||
dacpacRadioButton.checked = true;
|
||||
@@ -367,6 +382,17 @@ export class SchemaCompareDialog {
|
||||
};
|
||||
}
|
||||
|
||||
private shouldEnableOkayButton(): boolean {
|
||||
let sourcefilled = (this.sourceIsDacpac && this.existsDacpac(this.sourceTextBox.value)) || (!this.sourceIsDacpac && !isNullOrUndefined(this.sourceDatabaseDropdown.value));
|
||||
let targetfilled = (this.targetIsDacpac && this.existsDacpac(this.targetTextBox.value)) || (!this.targetIsDacpac && !isNullOrUndefined(this.targetDatabaseDropdown.value));
|
||||
|
||||
return sourcefilled && targetfilled;
|
||||
}
|
||||
|
||||
private existsDacpac(filename: string): boolean {
|
||||
return !isNullOrUndefined(filename) && existsSync(filename) && (filename.toLocaleLowerCase().endsWith('.dacpac'));
|
||||
}
|
||||
|
||||
protected async createSourceServerDropdown(view: azdata.ModelView): Promise<azdata.FormComponent> {
|
||||
this.sourceServerDropdown = view.modelBuilder.dropDown().component();
|
||||
this.sourceServerDropdown.onValueChanged(async () => {
|
||||
@@ -454,6 +480,9 @@ export class SchemaCompareDialog {
|
||||
|
||||
protected async createSourceDatabaseDropdown(view: azdata.ModelView): Promise<azdata.FormComponent> {
|
||||
this.sourceDatabaseDropdown = view.modelBuilder.dropDown().component();
|
||||
this.sourceDatabaseDropdown.onValueChanged(() => {
|
||||
this.dialog.okButton.enabled = this.shouldEnableOkayButton();
|
||||
});
|
||||
|
||||
return {
|
||||
component: this.sourceDatabaseDropdown,
|
||||
@@ -463,6 +492,9 @@ export class SchemaCompareDialog {
|
||||
|
||||
protected async createTargetDatabaseDropdown(view: azdata.ModelView): Promise<azdata.FormComponent> {
|
||||
this.targetDatabaseDropdown = view.modelBuilder.dropDown().component();
|
||||
this.targetDatabaseDropdown.onValueChanged(() => {
|
||||
this.dialog.okButton.enabled = this.shouldEnableOkayButton();
|
||||
});
|
||||
|
||||
return {
|
||||
component: this.targetDatabaseDropdown,
|
||||
|
||||
Reference in New Issue
Block a user