Get query ID for query history items (incl VariantAnalysisHistoryItem)

This commit is contained in:
shati-patel
2022-10-14 17:30:52 +01:00
parent 60e9f552db
commit 04c9f17398
3 changed files with 54 additions and 14 deletions

View File

@@ -17,3 +17,16 @@ export function getRawQueryName(item: QueryHistoryInfo): string {
assertNever(item);
}
}
export function getQueryId(item: QueryHistoryInfo): string {
switch (item.t) {
case 'local':
return item.initialInfo.id;
case 'remote':
return item.queryId;
case 'variant-analysis':
return item.variantAnalysis.id.toString();
default:
assertNever(item);
}
}

View File

@@ -31,7 +31,7 @@ import { commandRunner } from './commandRunner';
import { ONE_HOUR_IN_MS, TWO_HOURS_IN_MS } from './pure/time';
import { assertNever, getErrorMessage, getErrorStack } from './pure/helpers-pure';
import { CompletedLocalQueryInfo, LocalQueryInfo } from './query-results';
import { QueryHistoryInfo } from './query-history-info';
import { getQueryId, QueryHistoryInfo } from './query-history-info';
import { DatabaseManager } from './databases';
import { registerQueryHistoryScrubber } from './query-history-scrubber';
import { QueryStatus } from './query-status';
@@ -1068,19 +1068,13 @@ export class QueryHistoryManager extends DisposableObject {
queryText: encodeURIComponent(await this.getQueryText(finalSingleItem)),
});
if (finalSingleItem.t === 'variant-analysis') {
// TODO
} else {
const queryId = finalSingleItem.t === 'local'
? finalSingleItem.initialInfo.id
: finalSingleItem.queryId;
const queryId = getQueryId(finalSingleItem);
const uri = Uri.parse(
`codeql:${queryId}?${params.toString()}`, true
);
const doc = await workspace.openTextDocument(uri);
await window.showTextDocument(doc, { preview: false });
}
const uri = Uri.parse(
`codeql:${queryId}?${params.toString()}`, true
);
const doc = await workspace.openTextDocument(uri);
await window.showTextDocument(doc, { preview: false });
}
async handleViewSarifAlerts(

View File

@@ -1,7 +1,7 @@
import { expect } from 'chai';
import { QueryStatus } from '../../src/query-status';
import { getRawQueryName } from '../../src/query-history-info';
import { getQueryId, getRawQueryName } from '../../src/query-history-info';
import { VariantAnalysisHistoryItem } from '../../src/remote-queries/variant-analysis-history-item';
import { createMockVariantAnalysis } from '../../src/vscode-tests/factories/remote-queries/shared/variant-analysis';
import { createMockLocalQueryInfo } from '../../src/vscode-tests/factories/local-queries/local-query-history-item';
@@ -40,4 +40,37 @@ describe('Query history info', () => {
expect(queryName).to.equal(queryHistoryItem.variantAnalysis.query.name);
});
});
describe('getQueryId', () => {
it('should get the ID for local history items', () => {
const date = new Date('2022-01-01T00:00:00.000Z');
const dateStr = date.toLocaleString();
const queryHistoryItem = createMockLocalQueryInfo(dateStr);
const queryId = getQueryId(queryHistoryItem);
expect(queryId).to.equal(queryHistoryItem.initialInfo.id);
});
it('should get the ID for remote query history items', () => {
const queryHistoryItem = createMockRemoteQueryHistoryItem({});
const queryId = getQueryId(queryHistoryItem);
expect(queryId).to.equal(queryHistoryItem.queryId);
});
it('should get the ID for variant analysis history items', () => {
const queryHistoryItem: VariantAnalysisHistoryItem = {
t: 'variant-analysis',
status: QueryStatus.InProgress,
completed: false,
variantAnalysis: createMockVariantAnalysis()
};
const queryId = getQueryId(queryHistoryItem);
expect(queryId).to.equal(queryHistoryItem.variantAnalysis.id.toString());
});
});
});