Disabling revert button when no changes to SQLCMD vars at publish time (#22552)

* disabling revert SQLCMD var value button when no changes to values; changing string

* Updating docstring

* Updating behavior to account for SQLCMD vars defined in publish profiles
This commit is contained in:
Benjin Dubishar
2023-04-03 10:09:06 -07:00
committed by GitHub
parent 55820e94f9
commit 267a830775
2 changed files with 60 additions and 23 deletions

View File

@@ -142,7 +142,7 @@ export const profileReadError = (err: any) => localize('profileReadError', "Erro
export const sqlCmdVariables = localize('sqlCmdTableLabel', "SQLCMD Variables"); export const sqlCmdVariables = localize('sqlCmdTableLabel', "SQLCMD Variables");
export const sqlCmdVariableColumn = localize('sqlCmdVariableColumn', "Name"); export const sqlCmdVariableColumn = localize('sqlCmdVariableColumn', "Name");
export const sqlCmdValueColumn = localize('sqlCmdValueColumn', "Value"); export const sqlCmdValueColumn = localize('sqlCmdValueColumn', "Value");
export const loadSqlCmdVarsButtonTitle = localize('reloadValuesFromProjectButtonTitle', "Reload values from project"); export const revertSqlCmdVarsButtonTitle = localize('revertSqlCmdVarsButtonTitle', "Revert values to project defaults");
export const profile = localize('profile', "Profile"); export const profile = localize('profile', "Profile");
export const selectConnection = localize('selectConnection', "Select connection"); export const selectConnection = localize('selectConnection', "Select connection");
export const server = localize('server', "Server"); export const server = localize('server', "Server");

View File

@@ -41,7 +41,7 @@ export class PublishDatabaseDialog {
private dataSourcesRadioButton: azdataType.RadioButtonComponent | undefined; private dataSourcesRadioButton: azdataType.RadioButtonComponent | undefined;
private sqlCmdVariablesTable: azdataType.DeclarativeTableComponent | undefined; private sqlCmdVariablesTable: azdataType.DeclarativeTableComponent | undefined;
private sqlCmdVariablesFormComponentGroup: azdataType.FormComponentGroup | undefined; private sqlCmdVariablesFormComponentGroup: azdataType.FormComponentGroup | undefined;
private loadSqlCmdVarsButton: azdataType.ButtonComponent | undefined; private revertSqlCmdVarsButton: azdataType.ButtonComponent | undefined;
private loadProfileTextBox: azdataType.InputBoxComponent | undefined; private loadProfileTextBox: azdataType.InputBoxComponent | undefined;
private formBuilder: azdataType.FormBuilder | undefined; private formBuilder: azdataType.FormBuilder | undefined;
private connectionRow: azdataType.FlexContainer | undefined; private connectionRow: azdataType.FlexContainer | undefined;
@@ -124,13 +124,13 @@ export class PublishDatabaseDialog {
this.dataSourcesFormComponent = this.createDataSourcesFormComponent(view); this.dataSourcesFormComponent = this.createDataSourcesFormComponent(view);
this.sqlCmdVariablesTable = this.createSqlCmdTable(view); this.sqlCmdVariablesTable = this.createSqlCmdTable(view);
this.loadSqlCmdVarsButton = this.createLoadSqlCmdVarsButton(view); this.revertSqlCmdVarsButton = this.createRevertSqlCmdVarsButton(view);
this.sqlCmdVariablesFormComponentGroup = { this.sqlCmdVariablesFormComponentGroup = {
components: [ components: [
{ {
title: '', title: '',
component: this.loadSqlCmdVarsButton component: this.revertSqlCmdVarsButton
}, },
{ {
title: '', title: '',
@@ -430,7 +430,7 @@ export class PublishDatabaseDialog {
private onPublishTypeChange(existingServer: boolean, view: azdataType.ModelView) { private onPublishTypeChange(existingServer: boolean, view: azdataType.ModelView) {
this.existingServerSelected = existingServer; this.existingServerSelected = existingServer;
this.createDatabaseRow(view); this.createDatabaseRow(view);
this.tryEnableGenerateScriptAndOkButtons(); this.tryEnableGenerateScriptAndPublishButtons();
if (existingServer) { if (existingServer) {
if (this.connectionRow) { if (this.connectionRow) {
this.formBuilder!.insertFormItem({ this.formBuilder!.insertFormItem({
@@ -470,7 +470,7 @@ export class PublishDatabaseDialog {
}).component(); }).component();
this.targetConnectionTextBox.onTextChanged(() => { this.targetConnectionTextBox.onTextChanged(() => {
this.tryEnableGenerateScriptAndOkButtons(); this.tryEnableGenerateScriptAndPublishButtons();
}); });
return this.targetConnectionTextBox; return this.targetConnectionTextBox;
@@ -509,7 +509,7 @@ export class PublishDatabaseDialog {
this.dataSourcesDropDown.onValueChanged(() => { this.dataSourcesDropDown.onValueChanged(() => {
this.setDatabaseToSelectedDataSourceDatabase(); this.setDatabaseToSelectedDataSourceDatabase();
this.tryEnableGenerateScriptAndOkButtons(); this.tryEnableGenerateScriptAndPublishButtons();
}); });
return { return {
@@ -574,7 +574,7 @@ export class PublishDatabaseDialog {
}).withValidation(component => utils.validateSqlServerPortNumber(component.value)).component(); }).withValidation(component => utils.validateSqlServerPortNumber(component.value)).component();
this.serverPortTextBox.onTextChanged(() => { this.serverPortTextBox.onTextChanged(() => {
this.tryEnableGenerateScriptAndOkButtons(); this.tryEnableGenerateScriptAndPublishButtons();
}); });
const serverPortRow = this.createFormRow(view, constants.serverPortNumber(name), this.serverPortTextBox); const serverPortRow = this.createFormRow(view, constants.serverPortNumber(name), this.serverPortTextBox);
this.serverAdminPasswordTextBox = view.modelBuilder.inputBox().withProps({ this.serverAdminPasswordTextBox = view.modelBuilder.inputBox().withProps({
@@ -600,13 +600,13 @@ export class PublishDatabaseDialog {
required: true required: true
}).withValidation(component => component.value === this.serverAdminPasswordTextBox?.value).component(); }).withValidation(component => component.value === this.serverAdminPasswordTextBox?.value).component();
this.serverAdminPasswordTextBox.onTextChanged(() => { this.serverAdminPasswordTextBox.onTextChanged(() => {
this.tryEnableGenerateScriptAndOkButtons(); this.tryEnableGenerateScriptAndPublishButtons();
if (this.serverConfigAdminPasswordTextBox) { if (this.serverConfigAdminPasswordTextBox) {
this.serverConfigAdminPasswordTextBox.value = ''; this.serverConfigAdminPasswordTextBox.value = '';
} }
}); });
this.serverConfigAdminPasswordTextBox.onTextChanged(() => { this.serverConfigAdminPasswordTextBox.onTextChanged(() => {
this.tryEnableGenerateScriptAndOkButtons(); this.tryEnableGenerateScriptAndPublishButtons();
}); });
const serverConfirmPasswordRow = this.createFormRow(view, constants.confirmServerPassword(name), this.serverConfigAdminPasswordTextBox); const serverConfirmPasswordRow = this.createFormRow(view, constants.confirmServerPassword(name), this.serverConfigAdminPasswordTextBox);
@@ -636,7 +636,7 @@ export class PublishDatabaseDialog {
}).component(); }).component();
this.imageTagDropDown.onValueChanged(() => { this.imageTagDropDown.onValueChanged(() => {
this.tryEnableGenerateScriptAndOkButtons(); this.tryEnableGenerateScriptAndPublishButtons();
}); });
const agreementInfo = baseImages[0].agreementInfo; const agreementInfo = baseImages[0].agreementInfo;
@@ -648,7 +648,7 @@ export class PublishDatabaseDialog {
required: true required: true
}).component(); }).component();
this.eulaCheckBox.onChanged(() => { this.eulaCheckBox.onChanged(() => {
this.tryEnableGenerateScriptAndOkButtons(); this.tryEnableGenerateScriptAndPublishButtons();
}); });
const eulaRow = view.modelBuilder.flexContainer().withLayout({ flexFlow: 'row', alignItems: 'center' }).component(); const eulaRow = view.modelBuilder.flexContainer().withLayout({ flexFlow: 'row', alignItems: 'center' }).component();
@@ -719,7 +719,7 @@ export class PublishDatabaseDialog {
}).component(); }).component();
this.targetDatabaseDropDown.onValueChanged(() => { this.targetDatabaseDropDown.onValueChanged(() => {
this.tryEnableGenerateScriptAndOkButtons(); this.tryEnableGenerateScriptAndPublishButtons();
}); });
} }
@@ -773,37 +773,52 @@ export class PublishDatabaseDialog {
(<Record<string, string>>this.sqlCmdVars)[<string>row[0].value] = <string>row[1].value; (<Record<string, string>>this.sqlCmdVars)[<string>row[0].value] = <string>row[1].value;
}); });
this.tryEnableGenerateScriptAndOkButtons(); this.updateRevertSqlCmdVarsButtonState();
this.tryEnableGenerateScriptAndPublishButtons();
}); });
return table; return table;
} }
private createLoadSqlCmdVarsButton(view: azdataType.ModelView): azdataType.ButtonComponent { private createRevertSqlCmdVarsButton(view: azdataType.ModelView): azdataType.ButtonComponent {
let loadSqlCmdVarsButton: azdataType.ButtonComponent = view.modelBuilder.button().withProps({ let loadSqlCmdVarsButton: azdataType.ButtonComponent = view.modelBuilder.button().withProps({
label: constants.loadSqlCmdVarsButtonTitle, label: constants.revertSqlCmdVarsButtonTitle,
title: constants.loadSqlCmdVarsButtonTitle, title: constants.revertSqlCmdVarsButtonTitle,
ariaLabel: constants.loadSqlCmdVarsButtonTitle, ariaLabel: constants.revertSqlCmdVarsButtonTitle,
width: '210px', width: '210px',
iconPath: IconPathHelper.refresh, iconPath: IconPathHelper.refresh,
height: '18px', height: '18px',
CSSStyles: { 'font-size': '13px' } CSSStyles: { 'font-size': '13px' },
enabled: false // start disabled because no SQLCMD variable values have been edited yet
}).component(); }).component();
loadSqlCmdVarsButton.onDidClick(async () => { loadSqlCmdVarsButton.onDidClick(async () => {
this.sqlCmdVars = { ...this.project.sqlCmdVariables }; for (const varName in this.sqlCmdVars) {
this.sqlCmdVars[varName] = this.getDefaultSqlCmdValue(varName);
}
const data = this.convertSqlCmdVarsToTableFormat(this.sqlCmdVars!); const data = this.convertSqlCmdVarsToTableFormat(this.sqlCmdVars!);
await (<azdataType.DeclarativeTableComponent>this.sqlCmdVariablesTable)!.updateProperties({ await (<azdataType.DeclarativeTableComponent>this.sqlCmdVariablesTable)!.updateProperties({
dataValues: data dataValues: data
}); });
this.tryEnableGenerateScriptAndOkButtons(); this.updateRevertSqlCmdVarsButtonState();
this.tryEnableGenerateScriptAndPublishButtons();
}); });
return loadSqlCmdVarsButton; return loadSqlCmdVarsButton;
} }
/**
* Gets the default value of a SQLCMD variable for a project
* @param varName
* @returns value defined in the sqlproj file, or blank string if not defined
*/
private getDefaultSqlCmdValue(varName: string): string {
return Object.keys(this.project.sqlCmdVariables).includes(varName) ? this.project.sqlCmdVariables[varName] : '';
}
private createSelectConnectionButton(view: azdataType.ModelView): azdataType.Component { private createSelectConnectionButton(view: azdataType.ModelView): azdataType.Component {
this.selectConnectionButton = view.modelBuilder.button().withProps({ this.selectConnectionButton = view.modelBuilder.button().withProps({
ariaLabel: constants.selectConnection, ariaLabel: constants.selectConnection,
@@ -889,6 +904,7 @@ export class PublishDatabaseDialog {
(<Record<string, string>>this.sqlCmdVars)[key] = result.sqlCmdVariables[key]; (<Record<string, string>>this.sqlCmdVars)[key] = result.sqlCmdVariables[key];
} }
this.updateRevertSqlCmdVarsButtonState();
this.deploymentOptions = result.options; this.deploymentOptions = result.options;
const data = this.convertSqlCmdVarsToTableFormat(this.getSqlCmdVariablesForPublish()); const data = this.convertSqlCmdVarsToTableFormat(this.getSqlCmdVariablesForPublish());
@@ -916,8 +932,29 @@ export class PublishDatabaseDialog {
return data; return data;
} }
// only enable Generate Script and Ok buttons if all fields are filled /**
private tryEnableGenerateScriptAndOkButtons(): void { * Enables or disables "Revert SQLCMD variable values" button depending on whether there are changes
* */
private updateRevertSqlCmdVarsButtonState(): void {
// no SQLCMD vars -> no button to update state for
if (!this.revertSqlCmdVarsButton) {
return;
}
let revertButtonEnabled = false;
for (const varName in this.sqlCmdVars) {
if (this.sqlCmdVars![varName] !== this.getDefaultSqlCmdValue(varName)) {
revertButtonEnabled = true;
break;
}
}
this.revertSqlCmdVarsButton.enabled = revertButtonEnabled;
}
// only enable "Generate Script" and "Publish" buttons if all fields are filled
private tryEnableGenerateScriptAndPublishButtons(): void {
let publishEnabled: boolean = false; let publishEnabled: boolean = false;
let generateScriptEnabled: boolean = false; let generateScriptEnabled: boolean = false;