Merge pull request #1944 from github/elena/fix-removal
Display modal when removing an item from query history
This commit is contained in:
Коммит
a1f5e5b277
|
@ -23,6 +23,7 @@ import {
|
|||
showAndLogInformationMessage,
|
||||
showAndLogWarningMessage,
|
||||
showBinaryChoiceDialog,
|
||||
showInformationMessageWithAction,
|
||||
} from "./helpers";
|
||||
import { extLogger } from "./common";
|
||||
import { URLSearchParams } from "url";
|
||||
|
@ -951,12 +952,20 @@ export class QueryHistoryManager extends DisposableObject {
|
|||
): Promise<void> {
|
||||
// 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(
|
||||
|
@ -964,6 +973,20 @@ export class QueryHistoryManager extends DisposableObject {
|
|||
);
|
||||
}
|
||||
|
||||
private async showToastWithWorkflowRunLink(
|
||||
item: VariantAnalysisHistoryItem,
|
||||
): Promise<void> {
|
||||
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;
|
||||
|
|
|
@ -45,6 +45,7 @@ import * as ghActionsApiClient from "../../../src/remote-queries/gh-api/gh-actio
|
|||
import { Credentials } from "../../../src/authentication";
|
||||
import { QuickPickItem, TextEditor } from "vscode";
|
||||
import { WebviewReveal } from "../../../src/interface-utils";
|
||||
import * as helpers from "../../../src/helpers";
|
||||
|
||||
describe("query-history", () => {
|
||||
const mockExtensionLocation = join(tmpDir.name, "mock-extension-location");
|
||||
|
@ -589,98 +590,283 @@ describe("query-history", () => {
|
|||
});
|
||||
|
||||
describe("when the item is a variant analysis", () => {
|
||||
describe("when the item being removed is not selected", () => {
|
||||
let toDelete: VariantAnalysisHistoryItem;
|
||||
let selected: VariantAnalysisHistoryItem;
|
||||
let showBinaryChoiceDialogSpy: jest.SpiedFunction<
|
||||
typeof helpers.showBinaryChoiceDialog
|
||||
>;
|
||||
let showInformationMessageWithActionSpy: jest.SpiedFunction<
|
||||
typeof helpers.showInformationMessageWithAction
|
||||
>;
|
||||
|
||||
beforeEach(async () => {
|
||||
// deleting the first item when a different item is selected
|
||||
// will not change the selection
|
||||
toDelete = variantAnalysisHistory[1];
|
||||
selected = variantAnalysisHistory[3];
|
||||
beforeEach(() => {
|
||||
// Choose 'Yes' when asked "Are you sure?"
|
||||
showBinaryChoiceDialogSpy = jest
|
||||
.spyOn(helpers, "showBinaryChoiceDialog")
|
||||
.mockResolvedValue(true);
|
||||
|
||||
queryHistoryManager = await createMockQueryHistory(allHistory);
|
||||
// initialize the selection
|
||||
await queryHistoryManager.treeView.reveal(
|
||||
variantAnalysisHistory[0],
|
||||
{
|
||||
showInformationMessageWithActionSpy = jest.spyOn(
|
||||
helpers,
|
||||
"showInformationMessageWithAction",
|
||||
);
|
||||
});
|
||||
|
||||
describe("when in progress", () => {
|
||||
describe("when the item being removed is not selected", () => {
|
||||
let toDelete: VariantAnalysisHistoryItem;
|
||||
let selected: VariantAnalysisHistoryItem;
|
||||
|
||||
beforeEach(async () => {
|
||||
// deleting the first item when a different item is selected
|
||||
// will not change the selection
|
||||
toDelete = variantAnalysisHistory[1];
|
||||
selected = variantAnalysisHistory[3];
|
||||
|
||||
queryHistoryManager = await createMockQueryHistory(allHistory);
|
||||
// initialize the selection
|
||||
await queryHistoryManager.treeView.reveal(
|
||||
variantAnalysisHistory[0],
|
||||
{
|
||||
select: true,
|
||||
},
|
||||
);
|
||||
|
||||
// select the item we want
|
||||
await queryHistoryManager.treeView.reveal(selected, {
|
||||
select: true,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
// select the item we want
|
||||
await queryHistoryManager.treeView.reveal(selected, {
|
||||
select: true,
|
||||
// should be selected
|
||||
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
|
||||
selected,
|
||||
);
|
||||
});
|
||||
|
||||
// should be selected
|
||||
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
|
||||
selected,
|
||||
);
|
||||
it("should remove the item", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
expect(
|
||||
variantAnalysisManagerStub.removeVariantAnalysis,
|
||||
).toHaveBeenCalledWith(toDelete.variantAnalysis);
|
||||
expect(
|
||||
queryHistoryManager.treeDataProvider.allHistory,
|
||||
).not.toContain(toDelete);
|
||||
});
|
||||
|
||||
it("should not change the selection", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
|
||||
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
|
||||
selected,
|
||||
);
|
||||
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
|
||||
selected.variantAnalysis.id,
|
||||
);
|
||||
});
|
||||
|
||||
it("should show a modal asking 'Are you sure?'", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
|
||||
expect(showBinaryChoiceDialogSpy).toHaveBeenCalledWith(
|
||||
"You are about to delete this query: query-name. Are you sure?",
|
||||
);
|
||||
});
|
||||
|
||||
it("should show a toast notification with a link to GitHub Actions", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
|
||||
expect(showInformationMessageWithActionSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
describe("when you choose 'No' in the 'Are you sure?' modal", () => {
|
||||
beforeEach(async () => {
|
||||
showBinaryChoiceDialogSpy.mockResolvedValue(false);
|
||||
});
|
||||
|
||||
it("should not delete the item", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
|
||||
expect(
|
||||
queryHistoryManager.treeDataProvider.allHistory,
|
||||
).toContain(toDelete);
|
||||
});
|
||||
|
||||
it("should not show a toast notification", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
|
||||
expect(
|
||||
showInformationMessageWithActionSpy,
|
||||
).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("should remove the item", () => {
|
||||
expect(
|
||||
variantAnalysisManagerStub.removeVariantAnalysis,
|
||||
).toHaveBeenCalledWith(toDelete.variantAnalysis);
|
||||
expect(
|
||||
queryHistoryManager.treeDataProvider.allHistory,
|
||||
).not.toContain(toDelete);
|
||||
});
|
||||
describe("when the item being removed is selected", () => {
|
||||
let toDelete: VariantAnalysisHistoryItem;
|
||||
let newSelected: VariantAnalysisHistoryItem;
|
||||
|
||||
it("should not change the selection", () => {
|
||||
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
|
||||
selected,
|
||||
);
|
||||
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
|
||||
selected.variantAnalysis.id,
|
||||
);
|
||||
beforeEach(async () => {
|
||||
// deleting the selected item automatically selects next item
|
||||
toDelete = variantAnalysisHistory[1];
|
||||
newSelected = variantAnalysisHistory[2];
|
||||
|
||||
queryHistoryManager = await createMockQueryHistory(
|
||||
variantAnalysisHistory,
|
||||
);
|
||||
|
||||
// select the item we want
|
||||
await queryHistoryManager.treeView.reveal(toDelete, {
|
||||
select: true,
|
||||
});
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
});
|
||||
|
||||
it("should remove the item", () => {
|
||||
expect(
|
||||
variantAnalysisManagerStub.removeVariantAnalysis,
|
||||
).toHaveBeenCalledWith(toDelete.variantAnalysis);
|
||||
expect(
|
||||
queryHistoryManager.treeDataProvider.allHistory,
|
||||
).not.toContain(toDelete);
|
||||
});
|
||||
|
||||
it.skip("should change the selection", () => {
|
||||
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
|
||||
newSelected,
|
||||
);
|
||||
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
|
||||
newSelected.variantAnalysis.id,
|
||||
);
|
||||
});
|
||||
|
||||
it("should show a modal asking 'Are you sure?'", () => {
|
||||
expect(showBinaryChoiceDialogSpy).toHaveBeenCalledWith(
|
||||
"You are about to delete this query: query-name. Are you sure?",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when the item being removed is selected", () => {
|
||||
let toDelete: VariantAnalysisHistoryItem;
|
||||
let newSelected: VariantAnalysisHistoryItem;
|
||||
describe("when not in progress", () => {
|
||||
describe("when the item being removed is not selected", () => {
|
||||
let toDelete: VariantAnalysisHistoryItem;
|
||||
let selected: VariantAnalysisHistoryItem;
|
||||
|
||||
beforeEach(async () => {
|
||||
// deleting the selected item automatically selects next item
|
||||
toDelete = variantAnalysisHistory[1];
|
||||
newSelected = variantAnalysisHistory[2];
|
||||
beforeEach(async () => {
|
||||
// deleting the first item when a different item is selected
|
||||
// will not change the selection
|
||||
toDelete = variantAnalysisHistory[2];
|
||||
selected = variantAnalysisHistory[3];
|
||||
|
||||
queryHistoryManager = await createMockQueryHistory(
|
||||
variantAnalysisHistory,
|
||||
);
|
||||
queryHistoryManager = await createMockQueryHistory(allHistory);
|
||||
// initialize the selection
|
||||
await queryHistoryManager.treeView.reveal(
|
||||
variantAnalysisHistory[0],
|
||||
{
|
||||
select: true,
|
||||
},
|
||||
);
|
||||
|
||||
// select the item we want
|
||||
await queryHistoryManager.treeView.reveal(toDelete, {
|
||||
select: true,
|
||||
// select the item we want
|
||||
await queryHistoryManager.treeView.reveal(selected, {
|
||||
select: true,
|
||||
});
|
||||
|
||||
// should be selected
|
||||
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
|
||||
selected,
|
||||
);
|
||||
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
});
|
||||
|
||||
it("should remove the item", () => {
|
||||
expect(
|
||||
variantAnalysisManagerStub.removeVariantAnalysis,
|
||||
).toHaveBeenCalledWith(toDelete.variantAnalysis);
|
||||
expect(
|
||||
queryHistoryManager.treeDataProvider.allHistory,
|
||||
).not.toContain(toDelete);
|
||||
});
|
||||
|
||||
it("should not change the selection", () => {
|
||||
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
|
||||
selected,
|
||||
);
|
||||
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
|
||||
selected.variantAnalysis.id,
|
||||
);
|
||||
});
|
||||
|
||||
it("should not show a modal asking 'Are you sure?'", () => {
|
||||
expect(showBinaryChoiceDialogSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
});
|
||||
|
||||
it("should remove the item", () => {
|
||||
expect(
|
||||
variantAnalysisManagerStub.removeVariantAnalysis,
|
||||
).toHaveBeenCalledWith(toDelete.variantAnalysis);
|
||||
expect(
|
||||
queryHistoryManager.treeDataProvider.allHistory,
|
||||
).not.toContain(toDelete);
|
||||
});
|
||||
describe("when the item being removed is selected", () => {
|
||||
let toDelete: VariantAnalysisHistoryItem;
|
||||
let newSelected: VariantAnalysisHistoryItem;
|
||||
|
||||
it.skip("should change the selection", () => {
|
||||
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
|
||||
newSelected,
|
||||
);
|
||||
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
|
||||
newSelected.variantAnalysis.id,
|
||||
);
|
||||
beforeEach(async () => {
|
||||
// deleting the selected item automatically selects next item
|
||||
toDelete = variantAnalysisHistory[0];
|
||||
newSelected = variantAnalysisHistory[2];
|
||||
|
||||
queryHistoryManager = await createMockQueryHistory(
|
||||
variantAnalysisHistory,
|
||||
);
|
||||
|
||||
// select the item we want
|
||||
await queryHistoryManager.treeView.reveal(toDelete, {
|
||||
select: true,
|
||||
});
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
});
|
||||
|
||||
it("should remove the item", () => {
|
||||
expect(
|
||||
variantAnalysisManagerStub.removeVariantAnalysis,
|
||||
).toHaveBeenCalledWith(toDelete.variantAnalysis);
|
||||
expect(
|
||||
queryHistoryManager.treeDataProvider.allHistory,
|
||||
).not.toContain(toDelete);
|
||||
});
|
||||
|
||||
it.skip("should change the selection", () => {
|
||||
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
|
||||
newSelected,
|
||||
);
|
||||
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledWith(
|
||||
newSelected.variantAnalysis.id,
|
||||
);
|
||||
});
|
||||
|
||||
it("should not show a modal asking 'Are you sure?'", () => {
|
||||
expect(showBinaryChoiceDialogSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче