Skip to content

Commit 21352da

Browse files
committed
Add alerts table to compare view if available
This adds the `alerts` result set to the compare view if an interpreted result is available. This assumes that the user has opened the query in the results view before opening the compare view. It will not interpret the results if the interpreted results are not available.
1 parent 2dab45c commit 21352da

2 files changed

Lines changed: 43 additions & 15 deletions

File tree

extensions/ql-vscode/src/compare/compare-view.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ import {
2222
import { telemetryListener } from "../common/vscode/telemetry";
2323
import { redactableError } from "../common/errors";
2424
import { App } from "../common/app";
25-
import { findResultSetNames } from "./result-set-names";
25+
import { findResultSetNames, CompareQueryInfo } from "./result-set-names";
2626

2727
interface ComparePair {
2828
from: CompletedLocalQueryInfo;
29-
fromSchemas: BQRSInfo;
29+
fromInfo: CompareQueryInfo;
3030
to: CompletedLocalQueryInfo;
31-
toSchemas: BQRSInfo;
31+
toInfo: CompareQueryInfo;
3232
}
3333

3434
export class CompareView extends AbstractWebview<
@@ -64,9 +64,19 @@ export class CompareView extends AbstractWebview<
6464

6565
this.comparePair = {
6666
from,
67-
fromSchemas,
67+
fromInfo: {
68+
schemas: fromSchemas,
69+
metadata: from.completedQuery.query.metadata,
70+
interpretedResultsPath:
71+
from.completedQuery.query.resultsPaths.interpretedResultsPath,
72+
},
6873
to,
69-
toSchemas,
74+
toInfo: {
75+
schemas: toSchemas,
76+
metadata: to.completedQuery.query.metadata,
77+
interpretedResultsPath:
78+
to.completedQuery.query.resultsPaths.interpretedResultsPath,
79+
},
7080
};
7181

7282
await this.showResultsInternal(selectedResultSetName);
@@ -190,23 +200,23 @@ export class CompareView extends AbstractWebview<
190200
}
191201

192202
private async findResultSetsToCompare(
193-
{ from, fromSchemas, to, toSchemas }: ComparePair,
203+
{ from, fromInfo, to, toInfo }: ComparePair,
194204
selectedResultSetName: string | undefined,
195205
) {
196206
const {
197207
commonResultSetNames,
198208
currentResultSetDisplayName,
199209
fromResultSetName,
200210
toResultSetName,
201-
} = await findResultSetNames(fromSchemas, toSchemas, selectedResultSetName);
211+
} = await findResultSetNames(fromInfo, toInfo, selectedResultSetName);
202212

203213
const fromResultSet = await this.getResultSet(
204-
fromSchemas,
214+
fromInfo.schemas,
205215
fromResultSetName,
206216
from.completedQuery.query.resultsPaths.resultsPath,
207217
);
208218
const toResultSet = await this.getResultSet(
209-
toSchemas,
219+
toInfo.schemas,
210220
toResultSetName,
211221
to.completedQuery.query.resultsPaths.resultsPath,
212222
);

extensions/ql-vscode/src/compare/result-set-names.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,32 @@
11
import { BQRSInfo } from "../common/bqrs-cli-types";
2+
import { ALERTS_TABLE_NAME, QueryMetadata } from "../common/interface-types";
3+
import { pathExists } from "fs-extra";
4+
5+
export type CompareQueryInfo = {
6+
schemas: BQRSInfo;
7+
metadata: QueryMetadata | undefined;
8+
interpretedResultsPath: string | undefined;
9+
};
10+
11+
async function getResultSetNames(info: CompareQueryInfo): Promise<string[]> {
12+
const schemaNames = info.schemas["result-sets"].map((schema) => schema.name);
13+
14+
if (info.metadata?.kind !== "graph" && info.interpretedResultsPath) {
15+
if (await pathExists(info.interpretedResultsPath)) {
16+
schemaNames.push(ALERTS_TABLE_NAME);
17+
}
18+
}
19+
20+
return schemaNames;
21+
}
222

323
export async function findResultSetNames(
4-
fromSchemas: BQRSInfo,
5-
toSchemas: BQRSInfo,
24+
from: CompareQueryInfo,
25+
to: CompareQueryInfo,
626
selectedResultSetName: string | undefined,
727
) {
8-
const fromSchemaNames = fromSchemas["result-sets"].map(
9-
(schema) => schema.name,
10-
);
11-
const toSchemaNames = toSchemas["result-sets"].map((schema) => schema.name);
28+
const fromSchemaNames = await getResultSetNames(from);
29+
const toSchemaNames = await getResultSetNames(to);
1230
const commonResultSetNames = fromSchemaNames.filter((name) =>
1331
toSchemaNames.includes(name),
1432
);

0 commit comments

Comments
 (0)