Skip to content

Commit 96688e3

Browse files
committed
Fix listing of tables when in alerts view
1 parent 88c2761 commit 96688e3

File tree

3 files changed

+25
-22
lines changed

3 files changed

+25
-22
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface ShowInterpretedPageMsg {
121121
metadata?: QueryMetadata;
122122
pageNumber: number;
123123
numPages: number;
124+
resultSetNames: string[];
124125
}
125126

126127
/** Advance to the next or previous path no in the path viewer */

extensions/ql-vscode/src/interface.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
jumpToLocation,
5353
} from './interface-utils';
5454
import { getDefaultResultSetName } from './interface-types';
55+
import { ResultSetSchema } from './bqrs-cli-types';
5556

5657
/**
5758
* interface.ts
@@ -330,19 +331,13 @@ export class InterfaceManager extends DisposableObject {
330331

331332
const getParsedResultSets = async (): Promise<ParsedResultSets> => {
332333
if (EXPERIMENTAL_BQRS_SETTING.getValue()) {
333-
const schemas = await this.cliServer.bqrsInfo(
334-
results.query.resultsPaths.resultsPath,
335-
RAW_RESULTS_PAGE_SIZE
336-
);
337-
338-
const resultSetNames = schemas['result-sets'].map(
339-
(resultSet) => resultSet.name
340-
);
334+
const resultSetSchemas = await this.getResultSetSchemas(results);
335+
const resultSetNames = resultSetSchemas.map(schema => schema.name);
341336

342337
// This may not wind up being the page we actually show, if there are interpreted results,
343338
// but speculatively send it anyway.
344339
const selectedTable = getDefaultResultSetName(resultSetNames);
345-
const schema = schemas['result-sets'].find(
340+
const schema = resultSetSchemas.find(
346341
(resultSet) => resultSet.name == selectedTable
347342
)!;
348343
if (schema === undefined) {
@@ -401,16 +396,29 @@ export class InterfaceManager extends DisposableObject {
401396
if (this._interpretation.sarif.runs[0].results === undefined) {
402397
throw new Error(`Trying to show interpreted results but results were undefined`);
403398
}
399+
400+
const resultSetSchemas = await this.getResultSetSchemas(this._displayedQuery);
401+
const resultSetNames = resultSetSchemas.map(schema => schema.name);
402+
404403
await this.postMessage({
405404
t: 'showInterpretedPage',
406405
interpretation: this.getPageOfInterpretedResults(pageNumber),
407406
database: this._displayedQuery.database,
408407
metadata: this._displayedQuery.query.metadata,
409408
pageNumber,
409+
resultSetNames,
410410
numPages: Math.ceil(this._interpretation.sarif.runs[0].results.length / INTERPRETED_RESULTS_PAGE_SIZE),
411411
});
412412
}
413413

414+
private async getResultSetSchemas(results: CompletedQuery): Promise<ResultSetSchema[]> {
415+
const schemas = await this.cliServer.bqrsInfo(
416+
results.query.resultsPaths.resultsPath,
417+
RAW_RESULTS_PAGE_SIZE
418+
);
419+
return schemas['result-sets'];
420+
}
421+
414422
/**
415423
* Show a page of raw results from the chosen table.
416424
*/
@@ -429,16 +437,10 @@ export class InterfaceManager extends DisposableObject {
429437
(sortedResultsMap[k] = this.convertPathPropertiesToWebviewUris(v))
430438
);
431439

432-
const schemas = await this.cliServer.bqrsInfo(
433-
results.query.resultsPaths.resultsPath,
434-
RAW_RESULTS_PAGE_SIZE
435-
);
436-
437-
const resultSetNames = schemas['result-sets'].map(
438-
(resultSet) => resultSet.name
439-
);
440+
const resultSetSchemas = await this.getResultSetSchemas(results);
441+
const resultSetNames = resultSetSchemas.map(schema => schema.name);
440442

441-
const schema = schemas['result-sets'].find(
443+
const schema = resultSetSchemas.find(
442444
(resultSet) => resultSet.name == selectedTable
443445
)!;
444446
if (schema === undefined)

extensions/ql-vscode/src/view/results.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,11 @@ class App extends React.Component<{}, ResultsViewState> {
198198
break;
199199
case 'showInterpretedPage':
200200
const resultsInfo: ResultsInfo = {
201-
resultsPath: '...', // XXX
201+
resultsPath: '', // FIXME: Not used for interpreted, refactor so this is not needed
202202
parsedResultSets: {
203203
t: 'ExtensionParsed',
204204
numPages: msg.numPages,
205-
resultSetNames: ['alerts'], // XXX get the other result set names from the extension
205+
resultSetNames: msg.resultSetNames,
206206
pageNumber: msg.pageNumber,
207207
resultSet: {
208208
t: 'SarifResultSet',
@@ -212,8 +212,8 @@ class App extends React.Component<{}, ResultsViewState> {
212212
},
213213
selectedTable: ALERTS_TABLE_NAME,
214214
},
215-
origResultsPaths: undefined as any,
216-
sortedResultsMap: new Map(), // XXX ?
215+
origResultsPaths: undefined as any, // FIXME: Not used for interpreted, refactor so this is not needed
216+
sortedResultsMap: new Map(), // FIXME: Not used for interpreted, refactor so this is not needed
217217
database: msg.database,
218218
interpretation: msg.interpretation,
219219
shouldKeepOldResultsWhileRendering: true,

0 commit comments

Comments
 (0)