Merge pull request #2422 from github/aeisenberg/compare-view-quick-eval

Allow compare view to work with quick-eval
This commit is contained in:
Andrew Eisenberg
2023-05-16 08:41:12 -07:00
committed by GitHub
3 changed files with 28 additions and 7 deletions

View File

@@ -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,
];

View File

@@ -59,9 +59,7 @@ export function Compare(_: Record<string, never>): JSX.Element {
return (
<>
<div className="vscode-codeql__compare-header">
<div className="vscode-codeql__compare-header-item">
Table to compare:
</div>
<div className="vscode-codeql__compare-header-item">Comparing:</div>
<CompareSelector
availableResultSets={comparison.commonResultSetNames}
currentResultSetName={comparison.currentResultSetName}

View File

@@ -7,7 +7,8 @@ interface Props {
}
export default function CompareSelector(props: Props) {
return (
return props.availableResultSets.length ? (
// Handle case where there are shared result sets
<select
value={props.currentResultSetName}
onChange={(e) => props.updateResultSet(e.target.value)}
@@ -18,5 +19,8 @@ export default function CompareSelector(props: Props) {
</option>
))}
</select>
) : (
// Handle case where there are no shared result sets
<div>{props.currentResultSetName}</div>
);
}