Merge pull request #1528 from github/koesie10/fix-export-all-selection
Fix "Export All" not always exporting the correct query
This commit is contained in:
@@ -915,8 +915,8 @@ async function activateWithInstalledDistribution(
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
ctx.subscriptions.push(
|
ctx.subscriptions.push(
|
||||||
commandRunner('codeQL.exportVariantAnalysisResults', async () => {
|
commandRunner('codeQL.exportVariantAnalysisResults', async (queryId?: string) => {
|
||||||
await exportRemoteQueryResults(qhm, rqm, ctx);
|
await exportRemoteQueryResults(qhm, rqm, ctx, queryId);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
@@ -422,6 +422,7 @@ export interface RemoteQueryDownloadAllAnalysesResultsMessage {
|
|||||||
|
|
||||||
export interface RemoteQueryExportResultsMessage {
|
export interface RemoteQueryExportResultsMessage {
|
||||||
t: 'remoteQueryExportResults';
|
t: 'remoteQueryExportResults';
|
||||||
|
queryId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CopyRepoListMessage {
|
export interface CopyRepoListMessage {
|
||||||
|
|||||||
@@ -680,6 +680,10 @@ export class QueryHistoryManager extends DisposableObject {
|
|||||||
return this.treeDataProvider.getCurrent();
|
return this.treeDataProvider.getCurrent();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getRemoteQueryById(queryId: string): RemoteQueryHistoryItem | undefined {
|
||||||
|
return this.treeDataProvider.allHistory.find(i => i.t === 'remote' && i.queryId === queryId) as RemoteQueryHistoryItem;
|
||||||
|
}
|
||||||
|
|
||||||
async removeDeletedQueries() {
|
async removeDeletedQueries() {
|
||||||
await Promise.all(this.treeDataProvider.allHistory.map(async (item) => {
|
await Promise.all(this.treeDataProvider.allHistory.map(async (item) => {
|
||||||
if (item.t == 'local' && item.completedQuery && !(await fs.pathExists(item.completedQuery?.query.querySaveDir))) {
|
if (item.t == 'local' && item.completedQuery && !(await fs.pathExists(item.completedQuery?.query.querySaveDir))) {
|
||||||
|
|||||||
@@ -15,26 +15,41 @@ import { RemoteQueriesManager } from './remote-queries-manager';
|
|||||||
import { generateMarkdown } from './remote-queries-markdown-generation';
|
import { generateMarkdown } from './remote-queries-markdown-generation';
|
||||||
import { RemoteQuery } from './remote-query';
|
import { RemoteQuery } from './remote-query';
|
||||||
import { AnalysisResults, sumAnalysesResults } from './shared/analysis-result';
|
import { AnalysisResults, sumAnalysesResults } from './shared/analysis-result';
|
||||||
|
import { RemoteQueryHistoryItem } from './remote-query-history-item';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exports the results of the currently-selected remote query.
|
* Exports the results of the given or currently-selected remote query.
|
||||||
* The user is prompted to select the export format.
|
* The user is prompted to select the export format.
|
||||||
*/
|
*/
|
||||||
export async function exportRemoteQueryResults(
|
export async function exportRemoteQueryResults(
|
||||||
queryHistoryManager: QueryHistoryManager,
|
queryHistoryManager: QueryHistoryManager,
|
||||||
remoteQueriesManager: RemoteQueriesManager,
|
remoteQueriesManager: RemoteQueriesManager,
|
||||||
ctx: ExtensionContext,
|
ctx: ExtensionContext,
|
||||||
|
queryId?: string,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const queryHistoryItem = queryHistoryManager.getCurrentQueryHistoryItem();
|
let queryHistoryItem: RemoteQueryHistoryItem;
|
||||||
if (!queryHistoryItem || queryHistoryItem.t !== 'remote') {
|
if (queryId) {
|
||||||
|
const query = queryHistoryManager.getRemoteQueryById(queryId);
|
||||||
|
if (!query) {
|
||||||
|
void logger.log(`Could not find query with id ${queryId}`);
|
||||||
|
throw new Error('There was an error when trying to retrieve variant analysis information');
|
||||||
|
}
|
||||||
|
queryHistoryItem = query;
|
||||||
|
} else {
|
||||||
|
const query = queryHistoryManager.getCurrentQueryHistoryItem();
|
||||||
|
if (!query || query.t !== 'remote') {
|
||||||
throw new Error('No variant analysis results currently open. To open results, click an item in the query history view.');
|
throw new Error('No variant analysis results currently open. To open results, click an item in the query history view.');
|
||||||
} else if (!queryHistoryItem.completed) {
|
}
|
||||||
|
queryHistoryItem = query;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!queryHistoryItem.completed) {
|
||||||
throw new Error('Variant analysis results are not yet available.');
|
throw new Error('Variant analysis results are not yet available.');
|
||||||
}
|
}
|
||||||
const queryId = queryHistoryItem.queryId;
|
|
||||||
void logger.log(`Exporting variant analysis results for query: ${queryId}`);
|
void logger.log(`Exporting variant analysis results for query: ${queryHistoryItem.queryId}`);
|
||||||
const query = queryHistoryItem.remoteQuery;
|
const query = queryHistoryItem.remoteQuery;
|
||||||
const analysesResults = remoteQueriesManager.getAnalysesResults(queryId);
|
const analysesResults = remoteQueriesManager.getAnalysesResults(queryHistoryItem.queryId);
|
||||||
|
|
||||||
const gistOption = {
|
const gistOption = {
|
||||||
label: '$(ports-open-browser-icon) Create Gist (GitHub)',
|
label: '$(ports-open-browser-icon) Create Gist (GitHub)',
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ export class RemoteQueriesView extends AbstractWebview<ToRemoteQueriesMessage, F
|
|||||||
await this.downloadAllAnalysesResults(msg);
|
await this.downloadAllAnalysesResults(msg);
|
||||||
break;
|
break;
|
||||||
case 'remoteQueryExportResults':
|
case 'remoteQueryExportResults':
|
||||||
await commands.executeCommand('codeQL.exportVariantAnalysisResults');
|
await commands.executeCommand('codeQL.exportVariantAnalysisResults', msg.queryId);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assertNever(msg);
|
assertNever(msg);
|
||||||
|
|||||||
@@ -270,9 +270,10 @@ const AnalysesResultsTitle = ({ totalAnalysesResults, totalResults }: { totalAna
|
|||||||
return <SectionTitle>{totalAnalysesResults}/{totalResults} results</SectionTitle>;
|
return <SectionTitle>{totalAnalysesResults}/{totalResults} results</SectionTitle>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const exportResults = () => {
|
const exportResults = (queryResult: RemoteQueryResult) => {
|
||||||
vscode.postMessage({
|
vscode.postMessage({
|
||||||
t: 'remoteQueryExportResults',
|
t: 'remoteQueryExportResults',
|
||||||
|
queryId: queryResult.queryId,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -362,7 +363,7 @@ const AnalysesResults = ({
|
|||||||
totalResults={totalResults} />
|
totalResults={totalResults} />
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<VSCodeButton onClick={exportResults}>Export all</VSCodeButton>
|
<VSCodeButton onClick={() => exportResults(queryResult)}>Export all</VSCodeButton>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<AnalysesResultsDescription
|
<AnalysesResultsDescription
|
||||||
|
|||||||
Reference in New Issue
Block a user