From 4c33c06d55fcb47a2d22e67058572829dfc8b90f Mon Sep 17 00:00:00 2001 From: Andrew Eisenberg Date: Mon, 15 May 2023 15:51:48 -0700 Subject: [PATCH] Allow compare view to work with quick-eval The compare view typically works by matching the results sets of queries. It only allows the results sets of queries with identical names to be compared. Manually run queries use `#select` as the default result set. However, quick eval queries use a different, generated, name. Therefore, these two kinds of queries cannot be compared. This commit changes the heuristics so that if there are no identical;y named results sets, the first result set of each query that is prefixed with `#` is used (this is the default result set). It also makes a slightly nicer error message if there are no comparable results sets. --- .../ql-vscode/src/compare/compare-view.ts | 25 ++++++++++++++++--- .../ql-vscode/src/view/compare/Compare.tsx | 4 +-- .../src/view/compare/CompareSelector.tsx | 6 ++++- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/extensions/ql-vscode/src/compare/compare-view.ts b/extensions/ql-vscode/src/compare/compare-view.ts index df684d19e..c9c033f34 100644 --- a/extensions/ql-vscode/src/compare/compare-view.ts +++ b/extensions/ql-vscode/src/compare/compare-view.ts @@ -175,21 +175,40 @@ export class CompareView extends AbstractWebview< const commonResultSetNames = fromSchemaNames.filter((name) => toSchemaNames.includes(name), ); + + // Fall back on the default result set names if there are no common ones. + const defaultFromResultSetName = fromSchemaNames.find((name) => + name.startsWith("#"), + ); + const defaultToResultSetName = toSchemaNames.find((name) => + name.startsWith("#"), + ); + + if ( + commonResultSetNames.length === 0 && + !(defaultFromResultSetName || defaultToResultSetName) + ) { + throw new Error( + "No common result sets found between the two queries. Please check that the queries are compatible.", + ); + } + const currentResultSetName = selectedResultSetName || commonResultSetNames[0]; const fromResultSet = await this.getResultSet( fromSchemas, - currentResultSetName, + currentResultSetName || defaultFromResultSetName!, from.completedQuery.query.resultsPaths.resultsPath, ); const toResultSet = await this.getResultSet( toSchemas, - currentResultSetName, + currentResultSetName || defaultToResultSetName!, to.completedQuery.query.resultsPaths.resultsPath, ); return [ commonResultSetNames, - currentResultSetName, + currentResultSetName || + `${defaultFromResultSetName} <-> ${defaultToResultSetName}`, fromResultSet, toResultSet, ]; diff --git a/extensions/ql-vscode/src/view/compare/Compare.tsx b/extensions/ql-vscode/src/view/compare/Compare.tsx index 00aef5449..a98626e42 100644 --- a/extensions/ql-vscode/src/view/compare/Compare.tsx +++ b/extensions/ql-vscode/src/view/compare/Compare.tsx @@ -59,9 +59,7 @@ export function Compare(_: Record): JSX.Element { return ( <>
-
- Table to compare: -
+
Comparing:
props.updateResultSet(e.target.value)} @@ -18,5 +19,8 @@ export default function CompareSelector(props: Props) { ))} + ) : ( + // Handle case where there are no shared result sets +
{props.currentResultSetName}
); }