Merge pull request #1614 from github/shati-patel/query-history-get-id
Get query ID for query history items (incl `VariantAnalysisHistoryItem`)
This commit is contained in:
@@ -17,3 +17,16 @@ export function getRawQueryName(item: QueryHistoryInfo): string {
|
||||
assertNever(item);
|
||||
}
|
||||
}
|
||||
|
||||
export function getQueryHistoryItemId(item: QueryHistoryInfo): string {
|
||||
switch (item.t) {
|
||||
case 'local':
|
||||
return item.initialInfo.id;
|
||||
case 'remote':
|
||||
return item.queryId;
|
||||
case 'variant-analysis':
|
||||
return item.historyItemId;
|
||||
default:
|
||||
assertNever(item);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 { getQueryHistoryItemId, QueryHistoryInfo } from './query-history-info';
|
||||
import { DatabaseManager } from './databases';
|
||||
import { registerQueryHistoryScrubber } from './query-history-scrubber';
|
||||
import { QueryStatus } from './query-status';
|
||||
@@ -51,6 +51,7 @@ import { EvalLogData, parseViewerData } from './pure/log-summary-parser';
|
||||
import { QueryWithResults } from './run-queries-shared';
|
||||
import { QueryRunner } from './queryRunner';
|
||||
import { VariantAnalysisManager } from './remote-queries/variant-analysis-manager';
|
||||
import { nanoid } from 'nanoid';
|
||||
|
||||
/**
|
||||
* query-history.ts
|
||||
@@ -603,6 +604,7 @@ export class QueryHistoryManager extends DisposableObject {
|
||||
t: 'variant-analysis',
|
||||
status: QueryStatus.InProgress,
|
||||
completed: false,
|
||||
historyItemId: nanoid(),
|
||||
variantAnalysis,
|
||||
});
|
||||
|
||||
@@ -1068,19 +1070,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 = getQueryHistoryItemId(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(
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface VariantAnalysisHistoryItem {
|
||||
resultCount?: number;
|
||||
status: QueryStatus;
|
||||
completed: boolean;
|
||||
readonly historyItemId: string,
|
||||
variantAnalysis: VariantAnalysis;
|
||||
userSpecifiedLabel?: string;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { expect } from 'chai';
|
||||
|
||||
import { QueryStatus } from '../../src/query-status';
|
||||
import { getRawQueryName } from '../../src/query-history-info';
|
||||
import { getQueryHistoryItemId, 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';
|
||||
@@ -32,6 +32,7 @@ describe('Query history info', () => {
|
||||
t: 'variant-analysis',
|
||||
status: QueryStatus.InProgress,
|
||||
completed: false,
|
||||
historyItemId: 'abc123',
|
||||
variantAnalysis: createMockVariantAnalysis()
|
||||
};
|
||||
|
||||
@@ -40,4 +41,38 @@ describe('Query history info', () => {
|
||||
expect(queryName).to.equal(queryHistoryItem.variantAnalysis.query.name);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getQueryHistoryItemId', () => {
|
||||
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 historyItemId = getQueryHistoryItemId(queryHistoryItem);
|
||||
|
||||
expect(historyItemId).to.equal(queryHistoryItem.initialInfo.id);
|
||||
});
|
||||
|
||||
it('should get the ID for remote query history items', () => {
|
||||
const queryHistoryItem = createMockRemoteQueryHistoryItem({});
|
||||
const historyItemId = getQueryHistoryItemId(queryHistoryItem);
|
||||
|
||||
expect(historyItemId).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,
|
||||
historyItemId: 'abc123',
|
||||
variantAnalysis: createMockVariantAnalysis()
|
||||
};
|
||||
|
||||
const historyItemId = getQueryHistoryItemId(queryHistoryItem);
|
||||
|
||||
expect(historyItemId).to.equal(queryHistoryItem.historyItemId);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user