mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Disable schema compare generate script and apply buttons when no changes included (#5923)
* disable generate script and apply buttons when no changes are included * addressing comments
This commit is contained in:
@@ -16,7 +16,9 @@ const diffEditorTitle = localize('schemaCompare.ObjectDefinitionsTitle', 'Object
|
|||||||
const applyConfirmation = localize('schemaCompare.ApplyConfirmation', 'Are you sure you want to update the target?');
|
const applyConfirmation = localize('schemaCompare.ApplyConfirmation', 'Are you sure you want to update the target?');
|
||||||
const reCompareToRefeshMessage = localize('schemaCompare.RecompareToRefresh', 'Press Compare to refresh the comparison.');
|
const reCompareToRefeshMessage = localize('schemaCompare.RecompareToRefresh', 'Press Compare to refresh the comparison.');
|
||||||
const generateScriptEnabledMessage = localize('schemaCompare.generateScriptEnabledButton', 'Generate script to deploy changes to target');
|
const generateScriptEnabledMessage = localize('schemaCompare.generateScriptEnabledButton', 'Generate script to deploy changes to target');
|
||||||
|
const generateScriptNoChangesMessage = localize('schemaCompare.generateScriptNoChanges', 'No changes to script');
|
||||||
const applyEnabledMessage = localize('schemaCompare.applyButtonEnabledTitle', 'Apply changes to target');
|
const applyEnabledMessage = localize('schemaCompare.applyButtonEnabledTitle', 'Apply changes to target');
|
||||||
|
const applyNoChangesMessage = localize('schemaCompare.applyNoChanges', 'No changes to apply');
|
||||||
|
|
||||||
export class SchemaCompareResult {
|
export class SchemaCompareResult {
|
||||||
private differencesTable: azdata.TableComponent;
|
private differencesTable: azdata.TableComponent;
|
||||||
@@ -41,8 +43,8 @@ export class SchemaCompareResult {
|
|||||||
private deploymentOptions: azdata.DeploymentOptions;
|
private deploymentOptions: azdata.DeploymentOptions;
|
||||||
private schemaCompareOptionDialog: SchemaCompareOptionsDialog;
|
private schemaCompareOptionDialog: SchemaCompareOptionsDialog;
|
||||||
private tablelistenersToDispose: vscode.Disposable[] = [];
|
private tablelistenersToDispose: vscode.Disposable[] = [];
|
||||||
private originalSourceExcludes = {};
|
private originalSourceExcludes = new Map<string, azdata.DiffEntry>();
|
||||||
private originalTargetExcludes = {};
|
private originalTargetExcludes = new Map<string, azdata.DiffEntry>();
|
||||||
private sourceTargetSwitched = false;
|
private sourceTargetSwitched = false;
|
||||||
|
|
||||||
constructor(private sourceName: string, private targetName: string, private sourceEndpointInfo: azdata.SchemaCompareEndpointInfo, private targetEndpointInfo: azdata.SchemaCompareEndpointInfo) {
|
constructor(private sourceName: string, private targetName: string, private sourceEndpointInfo: azdata.SchemaCompareEndpointInfo, private targetEndpointInfo: azdata.SchemaCompareEndpointInfo) {
|
||||||
@@ -254,16 +256,6 @@ export class SchemaCompareResult {
|
|||||||
this.compareButton.enabled = true;
|
this.compareButton.enabled = true;
|
||||||
this.optionsButton.enabled = true;
|
this.optionsButton.enabled = true;
|
||||||
|
|
||||||
// explicitly exclude things that were excluded in previous compare
|
|
||||||
const thingsToExclude = this.sourceTargetSwitched ? this.originalTargetExcludes : this.originalSourceExcludes;
|
|
||||||
if (thingsToExclude) {
|
|
||||||
for (let item in thingsToExclude) {
|
|
||||||
if (<azdata.DiffEntry>thingsToExclude[item]) {
|
|
||||||
service.schemaCompareIncludeExcludeNode(this.comparisonResult.operationId, thingsToExclude[item], false, azdata.TaskExecutionMode.execute);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.comparisonResult.differences.length > 0) {
|
if (this.comparisonResult.differences.length > 0) {
|
||||||
this.flexModel.addItem(this.splitView, { CSSStyles: { 'overflow': 'hidden' } });
|
this.flexModel.addItem(this.splitView, { CSSStyles: { 'overflow': 'hidden' } });
|
||||||
|
|
||||||
@@ -279,6 +271,19 @@ export class SchemaCompareResult {
|
|||||||
this.flexModel.addItem(this.noDifferencesLabel, { CSSStyles: { 'margin': 'auto' } });
|
this.flexModel.addItem(this.noDifferencesLabel, { CSSStyles: { 'margin': 'auto' } });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// explicitly exclude things that were excluded in previous compare
|
||||||
|
const thingsToExclude = this.sourceTargetSwitched ? this.originalTargetExcludes : this.originalSourceExcludes;
|
||||||
|
if (thingsToExclude) {
|
||||||
|
thingsToExclude.forEach(item => {
|
||||||
|
service.schemaCompareIncludeExcludeNode(this.comparisonResult.operationId, item, false, azdata.TaskExecutionMode.execute);
|
||||||
|
});
|
||||||
|
|
||||||
|
// disable apply and generate script buttons if no changes are included
|
||||||
|
if (thingsToExclude.size === this.comparisonResult.differences.length) {
|
||||||
|
this.setButtonStatesForNoChanges(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let sourceText = '';
|
let sourceText = '';
|
||||||
let targetText = '';
|
let targetText = '';
|
||||||
this.tablelistenersToDispose.push(this.differencesTable.onRowSelected(() => {
|
this.tablelistenersToDispose.push(this.differencesTable.onRowSelected(() => {
|
||||||
@@ -311,15 +316,27 @@ export class SchemaCompareResult {
|
|||||||
let key = diff.sourceValue ? diff.sourceValue : diff.targetValue;
|
let key = diff.sourceValue ? diff.sourceValue : diff.targetValue;
|
||||||
if (key) {
|
if (key) {
|
||||||
if (!this.sourceTargetSwitched) {
|
if (!this.sourceTargetSwitched) {
|
||||||
delete this.originalSourceExcludes[key];
|
this.originalSourceExcludes.delete(key);
|
||||||
if (!rowState.checked) {
|
if (!rowState.checked) {
|
||||||
this.originalSourceExcludes[key] = diff;
|
this.originalSourceExcludes.set(key, diff);
|
||||||
|
if (this.originalSourceExcludes.size === this.comparisonResult.differences.length) {
|
||||||
|
this.setButtonStatesForNoChanges(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
delete this.originalTargetExcludes[key];
|
this.setButtonStatesForNoChanges(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.originalTargetExcludes.delete(key);
|
||||||
if (!rowState.checked) {
|
if (!rowState.checked) {
|
||||||
this.originalTargetExcludes[key] = diff;
|
this.originalTargetExcludes.set(key, diff);
|
||||||
|
if (this.originalTargetExcludes.size === this.comparisonResult.differences.length) {
|
||||||
|
this.setButtonStatesForNoChanges(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.setButtonStatesForNoChanges(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -329,11 +346,11 @@ export class SchemaCompareResult {
|
|||||||
private shouldDiffBeIncluded(diff: azdata.DiffEntry): boolean {
|
private shouldDiffBeIncluded(diff: azdata.DiffEntry): boolean {
|
||||||
let key = diff.sourceValue ? diff.sourceValue : diff.targetValue;
|
let key = diff.sourceValue ? diff.sourceValue : diff.targetValue;
|
||||||
if (key) {
|
if (key) {
|
||||||
if (this.sourceTargetSwitched === true && this.originalTargetExcludes[key]) {
|
if (this.sourceTargetSwitched === true && this.originalTargetExcludes.has(key)) {
|
||||||
this.originalTargetExcludes[key] = diff;
|
this.originalTargetExcludes[key] = diff;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (this.sourceTargetSwitched === false && this.originalSourceExcludes[key]) {
|
if (this.sourceTargetSwitched === false && this.originalSourceExcludes.has(key)) {
|
||||||
this.originalSourceExcludes[key] = diff;
|
this.originalSourceExcludes[key] = diff;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -588,6 +605,16 @@ export class SchemaCompareResult {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private setButtonStatesForNoChanges(enableButtons: boolean): void {
|
||||||
|
// generate script and apply can only be enabled if the target is a database
|
||||||
|
if (this.targetEndpointInfo.endpointType === azdata.SchemaCompareEndpointType.Database) {
|
||||||
|
this.applyButton.enabled = enableButtons;
|
||||||
|
this.generateScriptButton.enabled = enableButtons;
|
||||||
|
this.applyButton.title = enableButtons ? applyEnabledMessage : applyNoChangesMessage;
|
||||||
|
this.generateScriptButton.title = enableButtons ? generateScriptEnabledMessage : generateScriptNoChangesMessage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static async getService(providerName: string): Promise<azdata.SchemaCompareServicesProvider> {
|
private static async getService(providerName: string): Promise<azdata.SchemaCompareServicesProvider> {
|
||||||
let service = azdata.dataprotocol.getProvider<azdata.SchemaCompareServicesProvider>(providerName, azdata.DataProviderType.SchemaCompareServicesProvider);
|
let service = azdata.dataprotocol.getProvider<azdata.SchemaCompareServicesProvider>(providerName, azdata.DataProviderType.SchemaCompareServicesProvider);
|
||||||
return service;
|
return service;
|
||||||
|
|||||||
Reference in New Issue
Block a user