Merge pull request #3111 from github/koesie10/compare-raw

Add interpreted results type to compare view
This commit is contained in:
Koen Vlaswinkel
2023-12-07 10:35:41 +01:00
committed by GitHub
4 changed files with 36 additions and 21 deletions

View File

@@ -355,26 +355,35 @@ export interface SetComparisonsMessage {
};
readonly commonResultSetNames: string[];
readonly currentResultSetName: string;
readonly result: RawQueryCompareResult | undefined;
readonly result: QueryCompareResult | undefined;
readonly message: string | undefined;
readonly databaseUri: string;
}
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

@@ -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

@@ -34,6 +34,7 @@ CompareTable.args = {
commonResultSetNames: ["edges", "nodes", "subpaths", "#select"],
currentResultSetName: "edges",
result: {
kind: "raw",
columns: [
{ name: "a", kind: "Entity" },
{ name: "b", kind: "Entity" },

View File

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