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.
This commit is contained in:
@@ -27,13 +27,15 @@ import { RawResultSet } from "../common/raw-result-types";
|
|||||||
import {
|
import {
|
||||||
findCommonResultSetNames,
|
findCommonResultSetNames,
|
||||||
findResultSetNames,
|
findResultSetNames,
|
||||||
|
CompareQueryInfo,
|
||||||
|
getResultSetNames,
|
||||||
} from "./result-set-names";
|
} from "./result-set-names";
|
||||||
|
|
||||||
interface ComparePair {
|
interface ComparePair {
|
||||||
from: CompletedLocalQueryInfo;
|
from: CompletedLocalQueryInfo;
|
||||||
fromSchemas: BqrsInfo;
|
fromInfo: CompareQueryInfo;
|
||||||
to: CompletedLocalQueryInfo;
|
to: CompletedLocalQueryInfo;
|
||||||
toSchemas: BqrsInfo;
|
toInfo: CompareQueryInfo;
|
||||||
|
|
||||||
commonResultSetNames: readonly string[];
|
commonResultSetNames: readonly string[];
|
||||||
}
|
}
|
||||||
@@ -69,16 +71,41 @@ export class CompareView extends AbstractWebview<
|
|||||||
to.completedQuery.query.resultsPaths.resultsPath,
|
to.completedQuery.query.resultsPaths.resultsPath,
|
||||||
);
|
);
|
||||||
|
|
||||||
const commonResultSetNames = await findCommonResultSetNames(
|
const [fromSchemaNames, toSchemaNames] = await Promise.all([
|
||||||
fromSchemas,
|
getResultSetNames(
|
||||||
toSchemas,
|
fromSchemas,
|
||||||
|
from.completedQuery.query.metadata,
|
||||||
|
from.completedQuery.query.resultsPaths.interpretedResultsPath,
|
||||||
|
),
|
||||||
|
getResultSetNames(
|
||||||
|
toSchemas,
|
||||||
|
to.completedQuery.query.metadata,
|
||||||
|
to.completedQuery.query.resultsPaths.interpretedResultsPath,
|
||||||
|
),
|
||||||
|
]);
|
||||||
|
|
||||||
|
const commonResultSetNames = findCommonResultSetNames(
|
||||||
|
fromSchemaNames,
|
||||||
|
toSchemaNames,
|
||||||
);
|
);
|
||||||
|
|
||||||
this.comparePair = {
|
this.comparePair = {
|
||||||
from,
|
from,
|
||||||
fromSchemas,
|
fromInfo: {
|
||||||
|
schemas: fromSchemas,
|
||||||
|
schemaNames: fromSchemaNames,
|
||||||
|
metadata: from.completedQuery.query.metadata,
|
||||||
|
interpretedResultsPath:
|
||||||
|
from.completedQuery.query.resultsPaths.interpretedResultsPath,
|
||||||
|
},
|
||||||
to,
|
to,
|
||||||
toSchemas,
|
toInfo: {
|
||||||
|
schemas: toSchemas,
|
||||||
|
schemaNames: toSchemaNames,
|
||||||
|
metadata: to.completedQuery.query.metadata,
|
||||||
|
interpretedResultsPath:
|
||||||
|
to.completedQuery.query.resultsPaths.interpretedResultsPath,
|
||||||
|
},
|
||||||
commonResultSetNames,
|
commonResultSetNames,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -205,24 +232,24 @@ export class CompareView extends AbstractWebview<
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async findResultSetsToCompare(
|
private async findResultSetsToCompare(
|
||||||
{ from, fromSchemas, to, toSchemas, commonResultSetNames }: ComparePair,
|
{ from, fromInfo, to, toInfo, commonResultSetNames }: ComparePair,
|
||||||
selectedResultSetName: string | undefined,
|
selectedResultSetName: string | undefined,
|
||||||
) {
|
) {
|
||||||
const { currentResultSetDisplayName, fromResultSetName, toResultSetName } =
|
const { currentResultSetDisplayName, fromResultSetName, toResultSetName } =
|
||||||
await findResultSetNames(
|
await findResultSetNames(
|
||||||
fromSchemas,
|
fromInfo,
|
||||||
toSchemas,
|
toInfo,
|
||||||
commonResultSetNames,
|
commonResultSetNames,
|
||||||
selectedResultSetName,
|
selectedResultSetName,
|
||||||
);
|
);
|
||||||
|
|
||||||
const fromResultSet = await this.getResultSet(
|
const fromResultSet = await this.getResultSet(
|
||||||
fromSchemas,
|
fromInfo.schemas,
|
||||||
fromResultSetName,
|
fromResultSetName,
|
||||||
from.completedQuery.query.resultsPaths.resultsPath,
|
from.completedQuery.query.resultsPaths.resultsPath,
|
||||||
);
|
);
|
||||||
const toResultSet = await this.getResultSet(
|
const toResultSet = await this.getResultSet(
|
||||||
toSchemas,
|
toInfo.schemas,
|
||||||
toResultSetName,
|
toResultSetName,
|
||||||
to.completedQuery.query.resultsPaths.resultsPath,
|
to.completedQuery.query.resultsPaths.resultsPath,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,28 +1,49 @@
|
|||||||
|
import { pathExists } from "fs-extra";
|
||||||
import { BqrsInfo } from "../common/bqrs-cli-types";
|
import { BqrsInfo } from "../common/bqrs-cli-types";
|
||||||
import { getDefaultResultSetName } from "../common/interface-types";
|
import {
|
||||||
|
ALERTS_TABLE_NAME,
|
||||||
|
getDefaultResultSetName,
|
||||||
|
QueryMetadata,
|
||||||
|
} from "../common/interface-types";
|
||||||
|
|
||||||
export async function findCommonResultSetNames(
|
export async function getResultSetNames(
|
||||||
fromSchemas: BqrsInfo,
|
schemas: BqrsInfo,
|
||||||
toSchemas: BqrsInfo,
|
metadata: QueryMetadata | undefined,
|
||||||
|
interpretedResultsPath: string | undefined,
|
||||||
): Promise<string[]> {
|
): Promise<string[]> {
|
||||||
const fromSchemaNames = fromSchemas["result-sets"].map(
|
const schemaNames = schemas["result-sets"].map((schema) => schema.name);
|
||||||
(schema) => schema.name,
|
|
||||||
);
|
|
||||||
const toSchemaNames = toSchemas["result-sets"].map((schema) => schema.name);
|
|
||||||
|
|
||||||
|
if (metadata?.kind !== "graph" && interpretedResultsPath) {
|
||||||
|
if (await pathExists(interpretedResultsPath)) {
|
||||||
|
schemaNames.push(ALERTS_TABLE_NAME);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return schemaNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function findCommonResultSetNames(
|
||||||
|
fromSchemaNames: string[],
|
||||||
|
toSchemaNames: string[],
|
||||||
|
): string[] {
|
||||||
return fromSchemaNames.filter((name) => toSchemaNames.includes(name));
|
return fromSchemaNames.filter((name) => toSchemaNames.includes(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type CompareQueryInfo = {
|
||||||
|
schemas: BqrsInfo;
|
||||||
|
schemaNames: string[];
|
||||||
|
metadata: QueryMetadata | undefined;
|
||||||
|
interpretedResultsPath: string;
|
||||||
|
};
|
||||||
|
|
||||||
export async function findResultSetNames(
|
export async function findResultSetNames(
|
||||||
fromSchemas: BqrsInfo,
|
from: CompareQueryInfo,
|
||||||
toSchemas: BqrsInfo,
|
to: CompareQueryInfo,
|
||||||
commonResultSetNames: readonly string[],
|
commonResultSetNames: readonly string[],
|
||||||
selectedResultSetName: string | undefined,
|
selectedResultSetName: string | undefined,
|
||||||
) {
|
) {
|
||||||
const fromSchemaNames = fromSchemas["result-sets"].map(
|
const fromSchemaNames = from.schemaNames;
|
||||||
(schema) => schema.name,
|
const toSchemaNames = to.schemaNames;
|
||||||
);
|
|
||||||
const toSchemaNames = toSchemas["result-sets"].map((schema) => schema.name);
|
|
||||||
|
|
||||||
// Fall back on the default result set names if there are no common ones.
|
// Fall back on the default result set names if there are no common ones.
|
||||||
const defaultFromResultSetName = fromSchemaNames.find((name) =>
|
const defaultFromResultSetName = fromSchemaNames.find((name) =>
|
||||||
|
|||||||
Reference in New Issue
Block a user