Skip to content

Commit 109766d

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 0415ac5 commit 109766d

File tree

2 files changed

+74
-26
lines changed

2 files changed

+74
-26
lines changed

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

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ import { RawResultSet } from "../common/raw-result-types";
2727
import {
2828
findCommonResultSetNames,
2929
findResultSetNames,
30+
CompareQueryInfo,
31+
getResultSetNames,
3032
} from "./result-set-names";
3133

3234
interface ComparePair {
3335
from: CompletedLocalQueryInfo;
34-
fromSchemas: BqrsInfo;
36+
fromInfo: CompareQueryInfo;
3537
to: CompletedLocalQueryInfo;
36-
toSchemas: BqrsInfo;
38+
toInfo: CompareQueryInfo;
3739

3840
commonResultSetNames: readonly string[];
3941
}
@@ -69,16 +71,41 @@ export class CompareView extends AbstractWebview<
6971
to.completedQuery.query.resultsPaths.resultsPath,
7072
);
7173

72-
const commonResultSetNames = await findCommonResultSetNames(
73-
fromSchemas,
74-
toSchemas,
74+
const [fromSchemaNames, toSchemaNames] = await Promise.all([
75+
getResultSetNames(
76+
fromSchemas,
77+
from.completedQuery.query.metadata,
78+
from.completedQuery.query.resultsPaths.interpretedResultsPath,
79+
),
80+
getResultSetNames(
81+
toSchemas,
82+
to.completedQuery.query.metadata,
83+
to.completedQuery.query.resultsPaths.interpretedResultsPath,
84+
),
85+
]);
86+
87+
const commonResultSetNames = findCommonResultSetNames(
88+
fromSchemaNames,
89+
toSchemaNames,
7590
);
7691

7792
this.comparePair = {
7893
from,
79-
fromSchemas,
94+
fromInfo: {
95+
schemas: fromSchemas,
96+
schemaNames: fromSchemaNames,
97+
metadata: from.completedQuery.query.metadata,
98+
interpretedResultsPath:
99+
from.completedQuery.query.resultsPaths.interpretedResultsPath,
100+
},
80101
to,
81-
toSchemas,
102+
toInfo: {
103+
schemas: toSchemas,
104+
schemaNames: toSchemaNames,
105+
metadata: to.completedQuery.query.metadata,
106+
interpretedResultsPath:
107+
to.completedQuery.query.resultsPaths.interpretedResultsPath,
108+
},
82109
commonResultSetNames,
83110
};
84111

@@ -205,24 +232,24 @@ export class CompareView extends AbstractWebview<
205232
}
206233

207234
private async findResultSetsToCompare(
208-
{ from, fromSchemas, to, toSchemas, commonResultSetNames }: ComparePair,
235+
{ from, fromInfo, to, toInfo, commonResultSetNames }: ComparePair,
209236
selectedResultSetName: string | undefined,
210237
) {
211238
const { currentResultSetDisplayName, fromResultSetName, toResultSetName } =
212239
await findResultSetNames(
213-
fromSchemas,
214-
toSchemas,
240+
fromInfo,
241+
toInfo,
215242
commonResultSetNames,
216243
selectedResultSetName,
217244
);
218245

219246
const fromResultSet = await this.getResultSet(
220-
fromSchemas,
247+
fromInfo.schemas,
221248
fromResultSetName,
222249
from.completedQuery.query.resultsPaths.resultsPath,
223250
);
224251
const toResultSet = await this.getResultSet(
225-
toSchemas,
252+
toInfo.schemas,
226253
toResultSetName,
227254
to.completedQuery.query.resultsPaths.resultsPath,
228255
);

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

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,49 @@
1+
import { pathExists } from "fs-extra";
12
import { BqrsInfo } from "../common/bqrs-cli-types";
2-
import { getDefaultResultSetName } from "../common/interface-types";
3+
import {
4+
ALERTS_TABLE_NAME,
5+
getDefaultResultSetName,
6+
QueryMetadata,
7+
} from "../common/interface-types";
38

4-
export async function findCommonResultSetNames(
5-
fromSchemas: BqrsInfo,
6-
toSchemas: BqrsInfo,
9+
export async function getResultSetNames(
10+
schemas: BqrsInfo,
11+
metadata: QueryMetadata | undefined,
12+
interpretedResultsPath: string | undefined,
713
): Promise<string[]> {
8-
const fromSchemaNames = fromSchemas["result-sets"].map(
9-
(schema) => schema.name,
10-
);
11-
const toSchemaNames = toSchemas["result-sets"].map((schema) => schema.name);
14+
const schemaNames = schemas["result-sets"].map((schema) => schema.name);
15+
16+
if (metadata?.kind !== "graph" && interpretedResultsPath) {
17+
if (await pathExists(interpretedResultsPath)) {
18+
schemaNames.push(ALERTS_TABLE_NAME);
19+
}
20+
}
1221

22+
return schemaNames;
23+
}
24+
25+
export function findCommonResultSetNames(
26+
fromSchemaNames: string[],
27+
toSchemaNames: string[],
28+
): string[] {
1329
return fromSchemaNames.filter((name) => toSchemaNames.includes(name));
1430
}
1531

32+
export type CompareQueryInfo = {
33+
schemas: BqrsInfo;
34+
schemaNames: string[];
35+
metadata: QueryMetadata | undefined;
36+
interpretedResultsPath: string;
37+
};
38+
1639
export async function findResultSetNames(
17-
fromSchemas: BqrsInfo,
18-
toSchemas: BqrsInfo,
40+
from: CompareQueryInfo,
41+
to: CompareQueryInfo,
1942
commonResultSetNames: readonly string[],
2043
selectedResultSetName: string | undefined,
2144
) {
22-
const fromSchemaNames = fromSchemas["result-sets"].map(
23-
(schema) => schema.name,
24-
);
25-
const toSchemaNames = toSchemas["result-sets"].map((schema) => schema.name);
45+
const fromSchemaNames = from.schemaNames;
46+
const toSchemaNames = to.schemaNames;
2647

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

0 commit comments

Comments
 (0)