Skip to content

Commit 9b9a0cb

Browse files
authored
Split download actions in remote queries view (#1083)
1 parent 1dde5af commit 9b9a0cb

3 files changed

Lines changed: 34 additions & 12 deletions

File tree

extensions/ql-vscode/src/pure/interface-types.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,8 @@ export type FromRemoteQueriesMessage =
377377
| RemoteQueryErrorMessage
378378
| OpenFileMsg
379379
| OpenVirtualFileMsg
380-
| RemoteQueryDownloadLinkClickedMessage;
380+
| RemoteQueryDownloadAnalysisResultsMessage
381+
| RemoteQueryDownloadAllAnalysesResultsMessage;
381382

382383
export type ToRemoteQueriesMessage =
383384
| SetRemoteQueryResultMessage;
@@ -396,7 +397,13 @@ export interface RemoteQueryErrorMessage {
396397
error: string;
397398
}
398399

399-
export interface RemoteQueryDownloadLinkClickedMessage {
400-
t: 'remoteQueryDownloadLinkClicked';
400+
export interface RemoteQueryDownloadAnalysisResultsMessage {
401+
t: 'remoteQueryDownloadAnalysisResults';
402+
nwo: string
403+
downloadLink: DownloadLink;
404+
}
405+
406+
export interface RemoteQueryDownloadAllAnalysesResultsMessage {
407+
t: 'remoteQueryDownloadAllAnalysesResults';
401408
downloadLink: DownloadLink;
402409
}

extensions/ql-vscode/src/remote-queries/remote-queries-interface.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { tmpDir } from '../run-queries';
1414
import {
1515
ToRemoteQueriesMessage,
1616
FromRemoteQueriesMessage,
17-
RemoteQueryDownloadLinkClickedMessage,
1817
} from '../pure/interface-types';
1918
import { Logger } from '../logging';
2019
import { getHtmlForWebview } from '../interface-utils';
@@ -28,6 +27,7 @@ import { Credentials } from '../authentication';
2827
import { showAndLogWarningMessage, showInformationMessageWithAction } from '../helpers';
2928
import { URLSearchParams } from 'url';
3029
import { SHOW_QUERY_TEXT_MSG } from '../query-history';
30+
import { DownloadLink } from './download-link';
3131

3232
export class RemoteQueriesInterfaceManager {
3333
private panel: WebviewPanel | undefined;
@@ -189,18 +189,21 @@ export class RemoteQueriesInterfaceManager {
189189
case 'openVirtualFile':
190190
await this.openVirtualFile(msg.queryText);
191191
break;
192-
case 'remoteQueryDownloadLinkClicked':
193-
await this.handleDownloadLinkClicked(msg);
192+
case 'remoteQueryDownloadAnalysisResults':
193+
await this.handleDownloadLinkClicked(msg.downloadLink);
194+
break;
195+
case 'remoteQueryDownloadAllAnalysesResults':
196+
await this.handleDownloadLinkClicked(msg.downloadLink);
194197
break;
195198
default:
196199
assertNever(msg);
197200
}
198201
}
199202

200-
private async handleDownloadLinkClicked(msg: RemoteQueryDownloadLinkClickedMessage): Promise<void> {
203+
private async handleDownloadLinkClicked(downloadLink: DownloadLink): Promise<void> {
201204
const credentials = await Credentials.initialize(this.ctx);
202205

203-
const filePath = await downloadArtifactFromLink(credentials, msg.downloadLink);
206+
const filePath = await downloadArtifactFromLink(credentials, downloadLink);
204207
const isDir = (await fs.stat(filePath)).isDirectory();
205208
const message = `Result file saved at ${filePath}`;
206209
if (isDir) {

extensions/ql-vscode/src/remote-queries/view/RemoteQueries.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,17 @@ const emptyQueryResult: RemoteQueryResult = {
3333
analysisSummaries: []
3434
};
3535

36-
const download = (link: DownloadLink) => {
36+
const downloadAnalysisResults = (nwo: string, link: DownloadLink) => {
3737
vscode.postMessage({
38-
t: 'remoteQueryDownloadLinkClicked',
38+
t: 'remoteQueryDownloadAnalysisResults',
39+
nwo,
40+
downloadLink: link
41+
});
42+
};
43+
44+
const downloadAllAnalysesResults = (link: DownloadLink) => {
45+
vscode.postMessage({
46+
t: 'remoteQueryDownloadAllAnalysesResults',
3947
downloadLink: link
4048
});
4149
};
@@ -76,7 +84,9 @@ const QueryInfo = (queryResult: RemoteQueryResult) => (
7684
const SummaryTitleWithResults = (queryResult: RemoteQueryResult) => (
7785
<div className="vscode-codeql__query-summary-container">
7886
<SectionTitle text={`Repositories with results (${queryResult.affectedRepositoryCount}):`} />
79-
<DownloadButton text="Download all" onClick={() => download(queryResult.downloadLink)} />
87+
<DownloadButton
88+
text="Download all"
89+
onClick={() => downloadAllAnalysesResults(queryResult.downloadLink)} />
8090
</div>
8191
);
8292

@@ -92,7 +102,9 @@ const SummaryItem = (props: AnalysisSummary) => (
92102
<span className="vscode-codeql__analysis-item">{props.nwo}</span>
93103
<span className="vscode-codeql__analysis-item"><Badge text={props.resultCount.toString()} /></span>
94104
<span className="vscode-codeql__analysis-item">
95-
<DownloadButton text={props.fileSize} onClick={() => download(props.downloadLink)} />
105+
<DownloadButton
106+
text={props.fileSize}
107+
onClick={() => downloadAnalysisResults(props.nwo, props.downloadLink)} />
96108
</span>
97109
</span>
98110
);

0 commit comments

Comments
 (0)