Convert handleRemoveHistoryItem to use createMultiSelectionCommand
This commit is contained in:
@@ -59,7 +59,10 @@ import { QueryHistoryDirs } from "./query-history-dirs";
|
||||
import { QueryHistoryCommands } from "../common/commands";
|
||||
import { App } from "../common/app";
|
||||
import { tryOpenExternalFile } from "../vscode-utils/external-files";
|
||||
import { createSingleSelectionCommand } from "../common/selection-commands";
|
||||
import {
|
||||
createMultiSelectionCommand,
|
||||
createSingleSelectionCommand,
|
||||
} from "../common/selection-commands";
|
||||
|
||||
/**
|
||||
* query-history-manager.ts
|
||||
@@ -241,9 +244,9 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
"query",
|
||||
),
|
||||
"codeQLQueryHistory.removeHistoryItemContextMenu":
|
||||
this.handleRemoveHistoryItem.bind(this),
|
||||
createMultiSelectionCommand(this.handleRemoveHistoryItem.bind(this)),
|
||||
"codeQLQueryHistory.removeHistoryItemContextInline":
|
||||
this.handleRemoveHistoryItem.bind(this),
|
||||
createMultiSelectionCommand(this.handleRemoveHistoryItem.bind(this)),
|
||||
"codeQLQueryHistory.renameItem": this.handleRenameItem.bind(this),
|
||||
"codeQLQueryHistory.compareWith": this.handleCompareWith.bind(this),
|
||||
"codeQLQueryHistory.showEvalLog": this.handleShowEvalLog.bind(this),
|
||||
@@ -448,13 +451,9 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
);
|
||||
}
|
||||
|
||||
async handleRemoveHistoryItem(
|
||||
singleItem: QueryHistoryInfo,
|
||||
multiSelect: QueryHistoryInfo[] | undefined,
|
||||
) {
|
||||
multiSelect ||= [singleItem];
|
||||
async handleRemoveHistoryItem(items: QueryHistoryInfo[]) {
|
||||
await Promise.all(
|
||||
multiSelect.map(async (item) => {
|
||||
items.map(async (item) => {
|
||||
if (item.t === "local") {
|
||||
// Removing in progress local queries is not supported. They must be cancelled first.
|
||||
if (item.status !== QueryStatus.InProgress) {
|
||||
|
||||
@@ -278,9 +278,7 @@ describe("QueryHistoryManager", () => {
|
||||
);
|
||||
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
});
|
||||
|
||||
it("should remove the item", () => {
|
||||
@@ -320,9 +318,7 @@ describe("QueryHistoryManager", () => {
|
||||
await queryHistoryManager.treeView.reveal(toDelete, {
|
||||
select: true,
|
||||
});
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
});
|
||||
|
||||
it("should remove the item", () => {
|
||||
@@ -401,9 +397,7 @@ describe("QueryHistoryManager", () => {
|
||||
|
||||
it("should remove the item", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
|
||||
expect(
|
||||
variantAnalysisManagerStub.removeVariantAnalysis,
|
||||
@@ -415,9 +409,7 @@ describe("QueryHistoryManager", () => {
|
||||
|
||||
it("should not change the selection", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
|
||||
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
|
||||
selected,
|
||||
@@ -429,9 +421,7 @@ describe("QueryHistoryManager", () => {
|
||||
|
||||
it("should show a modal asking 'Are you sure?'", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
|
||||
expect(showBinaryChoiceDialogSpy).toHaveBeenCalledWith(
|
||||
"You are about to delete this query: a-query-name (javascript). Are you sure?",
|
||||
@@ -440,9 +430,7 @@ describe("QueryHistoryManager", () => {
|
||||
|
||||
it("should show a toast notification with a link to GitHub Actions", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
|
||||
expect(showInformationMessageWithActionSpy).toHaveBeenCalled();
|
||||
});
|
||||
@@ -454,9 +442,7 @@ describe("QueryHistoryManager", () => {
|
||||
|
||||
it("should not delete the item", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
|
||||
expect(queryHistoryManager.treeDataProvider.allHistory).toContain(
|
||||
toDelete,
|
||||
@@ -465,9 +451,7 @@ describe("QueryHistoryManager", () => {
|
||||
|
||||
it("should not show a toast notification", async () => {
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
|
||||
expect(
|
||||
showInformationMessageWithActionSpy,
|
||||
@@ -493,9 +477,7 @@ describe("QueryHistoryManager", () => {
|
||||
await queryHistoryManager.treeView.reveal(toDelete, {
|
||||
select: true,
|
||||
});
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
});
|
||||
|
||||
it("should remove the item", () => {
|
||||
@@ -555,9 +537,7 @@ describe("QueryHistoryManager", () => {
|
||||
);
|
||||
|
||||
// remove an item
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
});
|
||||
|
||||
it("should remove the item", () => {
|
||||
@@ -600,9 +580,7 @@ describe("QueryHistoryManager", () => {
|
||||
await queryHistoryManager.treeView.reveal(toDelete, {
|
||||
select: true,
|
||||
});
|
||||
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
|
||||
toDelete,
|
||||
]);
|
||||
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
|
||||
});
|
||||
|
||||
it("should remove the item", () => {
|
||||
|
||||
@@ -132,10 +132,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
|
||||
await qhm.readQueryHistory();
|
||||
|
||||
// Remove the first variant analysis
|
||||
await qhm.handleRemoveHistoryItem(
|
||||
qhm.treeDataProvider.allHistory[0],
|
||||
undefined,
|
||||
);
|
||||
await qhm.handleRemoveHistoryItem([qhm.treeDataProvider.allHistory[0]]);
|
||||
|
||||
// Add it back to the history
|
||||
qhm.addQuery(rawQueryHistory[0]);
|
||||
@@ -152,7 +149,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
|
||||
|
||||
// Remove both queries
|
||||
// Just for fun, let's do it in reverse order
|
||||
await qhm.handleRemoveHistoryItem(undefined!, [
|
||||
await qhm.handleRemoveHistoryItem([
|
||||
qhm.treeDataProvider.allHistory[1],
|
||||
qhm.treeDataProvider.allHistory[0],
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user