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