Merge remote-tracking branch 'origin/main' into koesie10/compare-messages

This commit is contained in:
Koen Vlaswinkel
2023-12-07 10:39:28 +01:00
5 changed files with 39 additions and 22 deletions

View File

@@ -365,25 +365,34 @@ export interface SetComparisonQueryInfoMessage {
export interface SetComparisonsMessage {
readonly t: "setComparisons";
readonly currentResultSetName: string;
readonly result: RawQueryCompareResult | undefined;
readonly result: QueryCompareResult | undefined;
readonly message: string | undefined;
}
type QueryCompareResult = RawQueryCompareResult | InterpretedQueryCompareResult;
/**
* from is the set of rows that have changes in the "from" query.
* to is the set of rows that have changes in the "to" query.
* They are in the same order, so element 1 in "from" corresponds to
* element 1 in "to".
*
* If an array element is null, that means that the element was removed
* (or added) in the comparison.
*/
export type RawQueryCompareResult = {
kind: "raw";
columns: readonly BqrsColumn[];
from: ResultRow[];
to: ResultRow[];
};
/**
* from is the set of results that have changes in the "from" query.
* to is the set of results that have changes in the "to" query.
*/
type InterpretedQueryCompareResult = {
kind: "interpreted";
sourceLocationPrefix: string;
from: sarif.Result[];
to: sarif.Result[];
};
/**
* Extract the name of the default result. Prefer returning
* 'alerts', or '#select'. Otherwise return the first in the list.

View File

@@ -1,4 +1,5 @@
import { BQRSInfo } from "../common/bqrs-cli-types";
import { getDefaultResultSetName } from "../common/interface-types";
export async function findCommonResultSetNames(
fromSchemas: BQRSInfo,
@@ -40,7 +41,8 @@ export async function findResultSetNames(
);
}
const currentResultSetName = selectedResultSetName || commonResultSetNames[0];
const currentResultSetName =
selectedResultSetName ?? getDefaultResultSetName(commonResultSetNames);
const fromResultSetName = currentResultSetName || defaultFromResultSetName!;
const toResultSetName = currentResultSetName || defaultToResultSetName!;

View File

@@ -35,7 +35,8 @@ export default function resultsDiff(
throw new Error("CodeQL Compare: Target query has no results.");
}
const results = {
const results: RawQueryCompareResult = {
kind: "raw",
columns: fromResults.columns,
from: arrayDiff(fromResults.tuples, toResults.tuples),
to: arrayDiff(toResults.tuples, fromResults.tuples),

View File

@@ -38,6 +38,7 @@ CompareTable.args = {
t: "setComparisons",
currentResultSetName: "edges",
result: {
kind: "raw",
columns: [
{ name: "a", kind: "Entity" },
{ name: "b", kind: "Entity" },

View File

@@ -67,22 +67,26 @@ export default function CompareTable({ queryInfo, comparison }: Props) {
<tbody>
<tr>
<td>
<RawCompareResultTable
columns={result.columns}
schemaName={comparison.currentResultSetName}
rows={result.from}
databaseUri={queryInfo.databaseUri}
className={className}
/>
{result.kind === "raw" && (
<RawCompareResultTable
columns={result.columns}
schemaName={comparison.currentResultSetName}
rows={result.from}
databaseUri={queryInfo.databaseUri}
className={className}
/>
)}
</td>
<td>
<RawCompareResultTable
columns={result.columns}
schemaName={comparison.currentResultSetName}
rows={result.to}
databaseUri={queryInfo.databaseUri}
className={className}
/>
{result.kind === "raw" && (
<RawCompareResultTable
columns={result.columns}
schemaName={comparison.currentResultSetName}
rows={result.to}
databaseUri={queryInfo.databaseUri}
className={className}
/>
)}
</td>
</tr>
</tbody>