Convert handleItemClicked to use createSingleSelectionCommand
This commit is contained in:
@@ -268,7 +268,10 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
"codeQLQueryHistory.viewSarifAlerts":
|
||||
this.handleViewSarifAlerts.bind(this),
|
||||
"codeQLQueryHistory.viewDil": this.handleViewDil.bind(this),
|
||||
"codeQLQueryHistory.itemClicked": this.handleItemClicked.bind(this),
|
||||
"codeQLQueryHistory.itemClicked": createSingleSelectionCommand(
|
||||
this.handleItemClicked.bind(this),
|
||||
"query",
|
||||
),
|
||||
"codeQLQueryHistory.openOnGithub": this.handleOpenOnGithub.bind(this),
|
||||
"codeQLQueryHistory.copyRepoList": this.handleCopyRepoList.bind(this),
|
||||
|
||||
@@ -598,33 +601,26 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
}
|
||||
}
|
||||
|
||||
async handleItemClicked(
|
||||
singleItem: QueryHistoryInfo,
|
||||
multiSelect: QueryHistoryInfo[] | undefined,
|
||||
) {
|
||||
if (!this.assertSingleQuery(multiSelect)) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.treeDataProvider.setCurrentItem(singleItem);
|
||||
async handleItemClicked(item: QueryHistoryInfo) {
|
||||
this.treeDataProvider.setCurrentItem(item);
|
||||
|
||||
const now = new Date();
|
||||
const prevItemClick = this.lastItemClick;
|
||||
this.lastItemClick = { time: now, item: singleItem };
|
||||
this.lastItemClick = { time: now, item };
|
||||
|
||||
if (
|
||||
prevItemClick !== undefined &&
|
||||
now.valueOf() - prevItemClick.time.valueOf() < DOUBLE_CLICK_TIME &&
|
||||
singleItem === prevItemClick.item
|
||||
item === prevItemClick.item
|
||||
) {
|
||||
// show original query file on double click
|
||||
await this.handleOpenQuery(singleItem);
|
||||
await this.handleOpenQuery(item);
|
||||
} else if (
|
||||
singleItem.t === "variant-analysis" ||
|
||||
singleItem.status === QueryStatus.Completed
|
||||
item.t === "variant-analysis" ||
|
||||
item.status === QueryStatus.Completed
|
||||
) {
|
||||
// show results on single click (if results view is available)
|
||||
await this.openQueryResults(singleItem);
|
||||
await this.openQueryResults(item);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,9 +155,7 @@ describe("QueryHistoryManager", () => {
|
||||
it("should show results", async () => {
|
||||
queryHistoryManager = await createMockQueryHistory(allHistory);
|
||||
const itemClicked = localQueryHistory[0];
|
||||
await queryHistoryManager.handleItemClicked(itemClicked, [
|
||||
itemClicked,
|
||||
]);
|
||||
await queryHistoryManager.handleItemClicked(itemClicked);
|
||||
|
||||
expect(
|
||||
localQueriesResultsViewStub.showResults,
|
||||
@@ -175,9 +173,7 @@ describe("QueryHistoryManager", () => {
|
||||
it("should do nothing", async () => {
|
||||
queryHistoryManager = await createMockQueryHistory(allHistory);
|
||||
const itemClicked = localQueryHistory[2];
|
||||
await queryHistoryManager.handleItemClicked(itemClicked, [
|
||||
itemClicked,
|
||||
]);
|
||||
await queryHistoryManager.handleItemClicked(itemClicked);
|
||||
|
||||
expect(
|
||||
localQueriesResultsViewStub.showResults,
|
||||
@@ -191,9 +187,7 @@ describe("QueryHistoryManager", () => {
|
||||
it("should show results", async () => {
|
||||
queryHistoryManager = await createMockQueryHistory(allHistory);
|
||||
const itemClicked = variantAnalysisHistory[0];
|
||||
await queryHistoryManager.handleItemClicked(itemClicked, [
|
||||
itemClicked,
|
||||
]);
|
||||
await queryHistoryManager.handleItemClicked(itemClicked);
|
||||
|
||||
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledTimes(
|
||||
1,
|
||||
@@ -211,9 +205,7 @@ describe("QueryHistoryManager", () => {
|
||||
it("should show results", async () => {
|
||||
queryHistoryManager = await createMockQueryHistory(allHistory);
|
||||
const itemClicked = variantAnalysisHistory[1];
|
||||
await queryHistoryManager.handleItemClicked(itemClicked, [
|
||||
itemClicked,
|
||||
]);
|
||||
await queryHistoryManager.handleItemClicked(itemClicked);
|
||||
|
||||
expect(variantAnalysisManagerStub.showView).toHaveBeenCalledTimes(
|
||||
1,
|
||||
@@ -228,25 +220,6 @@ describe("QueryHistoryManager", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("double click", () => {
|
||||
it("should do nothing", async () => {
|
||||
queryHistoryManager = await createMockQueryHistory(allHistory);
|
||||
const itemClicked = allHistory[0];
|
||||
const secondItemClicked = allHistory[1];
|
||||
|
||||
await queryHistoryManager.handleItemClicked(itemClicked, [
|
||||
itemClicked,
|
||||
secondItemClicked,
|
||||
]);
|
||||
|
||||
expect(localQueriesResultsViewStub.showResults).not.toHaveBeenCalled();
|
||||
expect(variantAnalysisManagerStub.showView).not.toBeCalled();
|
||||
expect(
|
||||
queryHistoryManager.treeDataProvider.getCurrent(),
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("handleRemoveHistoryItem", () => {
|
||||
|
||||
@@ -177,7 +177,7 @@ describe("Variant Analyses and QueryHistoryManager", () => {
|
||||
it("should handle a click", async () => {
|
||||
await qhm.readQueryHistory();
|
||||
|
||||
await qhm.handleItemClicked(qhm.treeDataProvider.allHistory[0], []);
|
||||
await qhm.handleItemClicked(qhm.treeDataProvider.allHistory[0]);
|
||||
expect(showViewStub).toBeCalledWith(rawQueryHistory[0].variantAnalysis.id);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user