From fa1f355b93ef858ae82410ba243444b04df6e3a0 Mon Sep 17 00:00:00 2001 From: Elena Tanasoiu Date: Mon, 9 Jan 2023 18:02:46 +0000 Subject: [PATCH] Show dialog with "Are you sure?" for in-progress queries When you attempt to delete a query that's still in progress from your query history, you get a prompt asking if you're sure. If you pick "Yes", the item is removed and you see a toast notification with a link towards the GitHub Action. --- extensions/ql-vscode/src/query-history.ts | 33 ++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/extensions/ql-vscode/src/query-history.ts b/extensions/ql-vscode/src/query-history.ts index 4e1731ad3..b8b0a4375 100644 --- a/extensions/ql-vscode/src/query-history.ts +++ b/extensions/ql-vscode/src/query-history.ts @@ -23,6 +23,7 @@ import { showAndLogInformationMessage, showAndLogWarningMessage, showBinaryChoiceDialog, + showInformationMessageWithAction, } from "./helpers"; import { extLogger } from "./common"; import { URLSearchParams } from "url"; @@ -946,12 +947,20 @@ export class QueryHistoryManager extends DisposableObject { ): Promise { // We can remove a Variant Analysis locally, but not remotely. // The user must cancel the query on GitHub Actions explicitly. + if (item.status === QueryStatus.InProgress) { + const response = await showBinaryChoiceDialog( + `You are about to delete this query: ${this.labelProvider.getLabel( + item, + )}. Are you sure?`, + ); + if (!response) return; + } + this.treeDataProvider.remove(item); void extLogger.log(`Deleted ${this.labelProvider.getLabel(item)}.`); + if (item.status === QueryStatus.InProgress) { - void extLogger.log( - "The variant analysis is still running on GitHub Actions. To cancel there, you must go to the workflow run in your browser.", - ); + await this.showToastWithWorkflowRunLink(item); } await this.variantAnalysisManager.removeVariantAnalysis( @@ -959,6 +968,24 @@ export class QueryHistoryManager extends DisposableObject { ); } + private async showToastWithWorkflowRunLink( + item: VariantAnalysisHistoryItem, + ): Promise { + void extLogger.log( + "The variant analysis is still running on GitHub Actions. To cancel there, you must go to the workflow run in your browser.", + ); + + const workflowRunUrl = getActionsWorkflowRunUrl(item); + const message = `Remote query has been removed from history. However, the variant analysis is still running on GitHub Actions. To cancel it, you must go to the [workflow run](${workflowRunUrl}) in your browser.`; + + void showInformationMessageWithAction(message, "Go to workflow run").then( + async (shouldOpenWorkflowRun) => { + if (!shouldOpenWorkflowRun) return; + await env.openExternal(Uri.parse(workflowRunUrl)); + }, + ); + } + async handleSortByName() { if (this.treeDataProvider.sortOrder === SortOrder.NameAsc) { this.treeDataProvider.sortOrder = SortOrder.NameDesc;