Skip to content

Commit d29c24d

Browse files
Convert handleRemoveHistoryItem to use createMultiSelectionCommand
1 parent 0b0a033 commit d29c24d

3 files changed

Lines changed: 21 additions & 47 deletions

File tree

extensions/ql-vscode/src/query-history/query-history-manager.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ import { QueryHistoryDirs } from "./query-history-dirs";
5959
import { QueryHistoryCommands } from "../common/commands";
6060
import { App } from "../common/app";
6161
import { tryOpenExternalFile } from "../vscode-utils/external-files";
62-
import { createSingleSelectionCommand } from "../common/selection-commands";
62+
import {
63+
createMultiSelectionCommand,
64+
createSingleSelectionCommand,
65+
} from "../common/selection-commands";
6366

6467
/**
6568
* query-history-manager.ts
@@ -241,9 +244,9 @@ export class QueryHistoryManager extends DisposableObject {
241244
"query",
242245
),
243246
"codeQLQueryHistory.removeHistoryItemContextMenu":
244-
this.handleRemoveHistoryItem.bind(this),
247+
createMultiSelectionCommand(this.handleRemoveHistoryItem.bind(this)),
245248
"codeQLQueryHistory.removeHistoryItemContextInline":
246-
this.handleRemoveHistoryItem.bind(this),
249+
createMultiSelectionCommand(this.handleRemoveHistoryItem.bind(this)),
247250
"codeQLQueryHistory.renameItem": this.handleRenameItem.bind(this),
248251
"codeQLQueryHistory.compareWith": this.handleCompareWith.bind(this),
249252
"codeQLQueryHistory.showEvalLog": this.handleShowEvalLog.bind(this),
@@ -448,13 +451,9 @@ export class QueryHistoryManager extends DisposableObject {
448451
);
449452
}
450453

451-
async handleRemoveHistoryItem(
452-
singleItem: QueryHistoryInfo,
453-
multiSelect: QueryHistoryInfo[] | undefined,
454-
) {
455-
multiSelect ||= [singleItem];
454+
async handleRemoveHistoryItem(items: QueryHistoryInfo[]) {
456455
await Promise.all(
457-
multiSelect.map(async (item) => {
456+
items.map(async (item) => {
458457
if (item.t === "local") {
459458
// Removing in progress local queries is not supported. They must be cancelled first.
460459
if (item.status !== QueryStatus.InProgress) {

extensions/ql-vscode/test/vscode-tests/no-workspace/query-history/query-history-manager.test.ts

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,7 @@ describe("QueryHistoryManager", () => {
278278
);
279279

280280
// remove an item
281-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
282-
toDelete,
283-
]);
281+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
284282
});
285283

286284
it("should remove the item", () => {
@@ -320,9 +318,7 @@ describe("QueryHistoryManager", () => {
320318
await queryHistoryManager.treeView.reveal(toDelete, {
321319
select: true,
322320
});
323-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
324-
toDelete,
325-
]);
321+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
326322
});
327323

328324
it("should remove the item", () => {
@@ -401,9 +397,7 @@ describe("QueryHistoryManager", () => {
401397

402398
it("should remove the item", async () => {
403399
// remove an item
404-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
405-
toDelete,
406-
]);
400+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
407401

408402
expect(
409403
variantAnalysisManagerStub.removeVariantAnalysis,
@@ -415,9 +409,7 @@ describe("QueryHistoryManager", () => {
415409

416410
it("should not change the selection", async () => {
417411
// remove an item
418-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
419-
toDelete,
420-
]);
412+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
421413

422414
expect(queryHistoryManager.treeDataProvider.getCurrent()).toEqual(
423415
selected,
@@ -429,9 +421,7 @@ describe("QueryHistoryManager", () => {
429421

430422
it("should show a modal asking 'Are you sure?'", async () => {
431423
// remove an item
432-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
433-
toDelete,
434-
]);
424+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
435425

436426
expect(showBinaryChoiceDialogSpy).toHaveBeenCalledWith(
437427
"You are about to delete this query: a-query-name (javascript). Are you sure?",
@@ -440,9 +430,7 @@ describe("QueryHistoryManager", () => {
440430

441431
it("should show a toast notification with a link to GitHub Actions", async () => {
442432
// remove an item
443-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
444-
toDelete,
445-
]);
433+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
446434

447435
expect(showInformationMessageWithActionSpy).toHaveBeenCalled();
448436
});
@@ -454,9 +442,7 @@ describe("QueryHistoryManager", () => {
454442

455443
it("should not delete the item", async () => {
456444
// remove an item
457-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
458-
toDelete,
459-
]);
445+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
460446

461447
expect(queryHistoryManager.treeDataProvider.allHistory).toContain(
462448
toDelete,
@@ -465,9 +451,7 @@ describe("QueryHistoryManager", () => {
465451

466452
it("should not show a toast notification", async () => {
467453
// remove an item
468-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
469-
toDelete,
470-
]);
454+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
471455

472456
expect(
473457
showInformationMessageWithActionSpy,
@@ -493,9 +477,7 @@ describe("QueryHistoryManager", () => {
493477
await queryHistoryManager.treeView.reveal(toDelete, {
494478
select: true,
495479
});
496-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
497-
toDelete,
498-
]);
480+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
499481
});
500482

501483
it("should remove the item", () => {
@@ -555,9 +537,7 @@ describe("QueryHistoryManager", () => {
555537
);
556538

557539
// remove an item
558-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
559-
toDelete,
560-
]);
540+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
561541
});
562542

563543
it("should remove the item", () => {
@@ -600,9 +580,7 @@ describe("QueryHistoryManager", () => {
600580
await queryHistoryManager.treeView.reveal(toDelete, {
601581
select: true,
602582
});
603-
await queryHistoryManager.handleRemoveHistoryItem(toDelete, [
604-
toDelete,
605-
]);
583+
await queryHistoryManager.handleRemoveHistoryItem([toDelete]);
606584
});
607585

608586
it("should remove the item", () => {

extensions/ql-vscode/test/vscode-tests/no-workspace/query-history/variant-analysis-history.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
132132
await qhm.readQueryHistory();
133133

134134
// Remove the first variant analysis
135-
await qhm.handleRemoveHistoryItem(
136-
qhm.treeDataProvider.allHistory[0],
137-
undefined,
138-
);
135+
await qhm.handleRemoveHistoryItem([qhm.treeDataProvider.allHistory[0]]);
139136

140137
// Add it back to the history
141138
qhm.addQuery(rawQueryHistory[0]);
@@ -152,7 +149,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
152149

153150
// Remove both queries
154151
// Just for fun, let's do it in reverse order
155-
await qhm.handleRemoveHistoryItem(undefined!, [
152+
await qhm.handleRemoveHistoryItem([
156153
qhm.treeDataProvider.allHistory[1],
157154
qhm.treeDataProvider.allHistory[0],
158155
]);

0 commit comments

Comments
 (0)