Skip to content

Commit 57724e8

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 49114cc commit 57724e8

2 files changed

Lines changed: 70 additions & 16 deletions

File tree

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

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,15 @@ import { App } from "../common/app";
2525
import {
2626
findCommonResultSetNames,
2727
findResultSetNames,
28+
CompareQueryInfo,
29+
getResultSetNames,
2830
} from "./result-set-names";
2931

3032
interface ComparePair {
3133
from: CompletedLocalQueryInfo;
32-
fromSchemas: BQRSInfo;
34+
fromInfo: CompareQueryInfo;
3335
to: CompletedLocalQueryInfo;
34-
toSchemas: BQRSInfo;
36+
toInfo: CompareQueryInfo;
3537

3638
commonResultSetNames: readonly string[];
3739
}
@@ -67,16 +69,41 @@ export class CompareView extends AbstractWebview<
6769
to.completedQuery.query.resultsPaths.resultsPath,
6870
);
6971

72+
const [fromSchemaNames, toSchemaNames] = await Promise.all([
73+
getResultSetNames(
74+
fromSchemas,
75+
from.completedQuery.query.metadata,
76+
from.completedQuery.query.resultsPaths.interpretedResultsPath,
77+
),
78+
getResultSetNames(
79+
toSchemas,
80+
to.completedQuery.query.metadata,
81+
to.completedQuery.query.resultsPaths.interpretedResultsPath,
82+
),
83+
]);
84+
7085
const commonResultSetNames = await findCommonResultSetNames(
7186
fromSchemas,
7287
toSchemas,
7388
);
7489

7590
this.comparePair = {
7691
from,
77-
fromSchemas,
92+
fromInfo: {
93+
schemas: fromSchemas,
94+
schemaNames: fromSchemaNames,
95+
metadata: from.completedQuery.query.metadata,
96+
interpretedResultsPath:
97+
from.completedQuery.query.resultsPaths.interpretedResultsPath,
98+
},
7899
to,
79-
toSchemas,
100+
toInfo: {
101+
schemas: toSchemas,
102+
schemaNames: toSchemaNames,
103+
metadata: to.completedQuery.query.metadata,
104+
interpretedResultsPath:
105+
to.completedQuery.query.resultsPaths.interpretedResultsPath,
106+
},
80107
commonResultSetNames,
81108
};
82109

@@ -203,24 +230,24 @@ export class CompareView extends AbstractWebview<
203230
}
204231

205232
private async findResultSetsToCompare(
206-
{ from, fromSchemas, to, toSchemas, commonResultSetNames }: ComparePair,
233+
{ from, fromInfo, to, toInfo, commonResultSetNames }: ComparePair,
207234
selectedResultSetName: string | undefined,
208235
) {
209236
const { currentResultSetDisplayName, fromResultSetName, toResultSetName } =
210237
await findResultSetNames(
211-
fromSchemas,
212-
toSchemas,
238+
fromInfo,
239+
toInfo,
213240
commonResultSetNames,
214241
selectedResultSetName,
215242
);
216243

217244
const fromResultSet = await this.getResultSet(
218-
fromSchemas,
245+
fromInfo.schemas,
219246
fromResultSetName,
220247
from.completedQuery.query.resultsPaths.resultsPath,
221248
);
222249
const toResultSet = await this.getResultSet(
223-
toSchemas,
250+
toInfo.schemas,
224251
toResultSetName,
225252
to.completedQuery.query.resultsPaths.resultsPath,
226253
);

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

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

426
export async function findCommonResultSetNames(
527
fromSchemas: BQRSInfo,
@@ -13,16 +35,21 @@ export async function findCommonResultSetNames(
1335
return fromSchemaNames.filter((name) => toSchemaNames.includes(name));
1436
}
1537

38+
export type CompareQueryInfo = {
39+
schemas: BQRSInfo;
40+
schemaNames: string[];
41+
metadata: QueryMetadata | undefined;
42+
interpretedResultsPath: string | undefined;
43+
};
44+
1645
export async function findResultSetNames(
17-
fromSchemas: BQRSInfo,
18-
toSchemas: BQRSInfo,
46+
from: CompareQueryInfo,
47+
to: CompareQueryInfo,
1948
commonResultSetNames: readonly string[],
2049
selectedResultSetName: string | undefined,
2150
) {
22-
const fromSchemaNames = fromSchemas["result-sets"].map(
23-
(schema) => schema.name,
24-
);
25-
const toSchemaNames = toSchemas["result-sets"].map((schema) => schema.name);
51+
const fromSchemaNames = from.schemaNames;
52+
const toSchemaNames = to.schemaNames;
2653

2754
// Fall back on the default result set names if there are no common ones.
2855
const defaultFromResultSetName = fromSchemaNames.find((name) =>

0 commit comments

Comments
 (0)