From 1a7f0673ea8a6ea1b2e136a3719441a5bc0c59e1 Mon Sep 17 00:00:00 2001 From: Karl Burtram Date: Thu, 2 Aug 2018 13:58:05 -0400 Subject: [PATCH] Prevent the insights dialog from showing duplicate buttons (#2122) --- src/sql/base/browser/ui/modal/modal.ts | 15 +++++++++++++++ .../parts/insights/browser/insightsDialogView.ts | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/sql/base/browser/ui/modal/modal.ts b/src/sql/base/browser/ui/modal/modal.ts index f05c7bf2d1..ce296b5bc2 100644 --- a/src/sql/base/browser/ui/modal/modal.ts +++ b/src/sql/base/browser/ui/modal/modal.ts @@ -357,6 +357,21 @@ export abstract class Modal extends Disposable implements IThemable { return button; } + /** + * Returns a footer button matching the provided label + * @param label Label to show on the button + * @param onSelect The callback to call when the button is selected + */ + protected findFooterButton(label: string): Button { + return this._footerButtons.find(e => { + try { + return e && e.element.innerText === label; + } catch { + return false; + } + }); + } + /** * Show an error in the error message element * @param err Text to show in the error message diff --git a/src/sql/parts/insights/browser/insightsDialogView.ts b/src/sql/parts/insights/browser/insightsDialogView.ts index ccb776140a..ec1e09a28b 100644 --- a/src/sql/parts/insights/browser/insightsDialogView.ts +++ b/src/sql/parts/insights/browser/insightsDialogView.ts @@ -295,8 +295,9 @@ export class InsightsDialogView extends Modal { for (let action of this._insight.actions.types) { let task = tasks.includes(action); let commandAction = MenuRegistry.getCommand(action); - if (task) { - let button = this.addFooterButton(types.isString(commandAction.title) ? commandAction.title : commandAction.title.value, () => { + let commandLabel = types.isString(commandAction.title) ? commandAction.title : commandAction.title.value; + if (task && !this.findFooterButton(commandLabel)) { + let button = this.addFooterButton(commandLabel, () => { let element = this._topTable.getSelectedRows(); let resource: ListResource; if (element && element.length > 0) {