Skip to content

Commit 636d0bf

Browse files
Move rendering of locationCells to inside AlertTableResuiltRow
1 parent fe4d87d commit 636d0bf

2 files changed

Lines changed: 28 additions & 19 deletions

File tree

extensions/ql-vscode/src/view/results/AlertTable.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
1818
import { sendTelemetry } from "../common/telemetry";
1919
import { AlertTableHeader } from "./AlertTableHeader";
2020
import { SarifMessageWithLocations } from "./locations/SarifMessageWithLocations";
21-
import { SarifLocation } from "./locations/SarifLocation";
2221
import { AlertTableNoResults } from "./AlertTableNoResults";
2322
import { AlertTableTruncatedMessage } from "./AlertTableTruncatedMessage";
2423
import { AlertTablePathRow } from "./AlertTablePathRow";
@@ -118,18 +117,6 @@ export class AlertTable extends React.Component<
118117
const currentResultExpanded = this.state.expanded.has(
119118
Keys.keyToString(resultKey),
120119
);
121-
const location = result.locations !== undefined &&
122-
result.locations.length > 0 && (
123-
<SarifLocation
124-
loc={result.locations[0]}
125-
sourceLocationPrefix={sourceLocationPrefix}
126-
databaseUri={databaseUri}
127-
onClick={updateSelectionCallback(resultKey)}
128-
/>
129-
);
130-
const locationCells = (
131-
<td className="vscode-codeql__location-cell">{location}</td>
132-
);
133120

134121
return (
135122
<>
@@ -138,10 +125,12 @@ export class AlertTable extends React.Component<
138125
resultIndex={resultIndex}
139126
currentResultExpanded={currentResultExpanded}
140127
selectedItem={this.state.selectedItem}
128+
databaseUri={databaseUri}
129+
sourceLocationPrefix={sourceLocationPrefix}
130+
updateSelectionCallback={updateSelectionCallback}
141131
toggler={toggler}
142132
scroller={this.scroller}
143133
msg={msg}
144-
locationCells={locationCells}
145134
/>
146135
{currentResultExpanded &&
147136
result.codeFlows &&

extensions/ql-vscode/src/view/results/AlertTableResultRow.tsx

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,21 @@ import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
66
import { selectableZebraStripe } from "./result-table-utils";
77
import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCell";
88
import { useMemo } from "react";
9+
import { SarifLocation } from "./locations/SarifLocation";
910

1011
interface Props {
1112
result: Sarif.Result;
1213
resultIndex: number;
1314
currentResultExpanded: boolean;
1415
selectedItem: undefined | Keys.ResultKey;
16+
databaseUri: string;
17+
sourceLocationPrefix: string;
18+
updateSelectionCallback: (
19+
resultKey: Keys.PathNode | Keys.Result | undefined,
20+
) => () => void;
1521
toggler: (keys: Keys.ResultKey[]) => (e: React.MouseEvent) => void;
1622
scroller: ScrollIntoViewHelper;
1723
msg: JSX.Element;
18-
locationCells: JSX.Element;
1924
}
2025

2126
export function AlertTableResultRow(props: Props) {
@@ -24,22 +29,28 @@ export function AlertTableResultRow(props: Props) {
2429
resultIndex,
2530
currentResultExpanded,
2631
selectedItem,
32+
databaseUri,
33+
sourceLocationPrefix,
34+
updateSelectionCallback,
2735
toggler,
2836
scroller,
2937
msg,
30-
locationCells,
3138
} = props;
3239

40+
const resultKey: Keys.Result = useMemo(
41+
() => ({ resultIndex }),
42+
[resultIndex],
43+
);
44+
3345
const handleDropdownClick = useMemo(() => {
34-
const resultKey: Keys.Result = { resultIndex };
3546
const indices =
3647
Keys.getAllPaths(result).length === 1
3748
? [resultKey, { ...resultKey, pathIndex: 0 }]
3849
: /* if there's exactly one path, auto-expand
3950
* the path when expanding the result */
4051
[resultKey];
4152
return toggler(indices);
42-
}, [result, resultIndex, toggler]);
53+
}, [result, resultKey, toggler]);
4354

4455
const resultRowIsSelected =
4556
selectedItem?.resultIndex === resultIndex &&
@@ -66,7 +77,16 @@ export function AlertTableResultRow(props: Props) {
6677
<td colSpan={2}>{msg}</td>
6778
</>
6879
)}
69-
{locationCells}
80+
<td className="vscode-codeql__location-cell">
81+
{result.locations && result.locations.length > 0 && (
82+
<SarifLocation
83+
loc={result.locations[0]}
84+
sourceLocationPrefix={sourceLocationPrefix}
85+
databaseUri={databaseUri}
86+
onClick={updateSelectionCallback(resultKey)}
87+
/>
88+
)}
89+
</td>
7090
</tr>
7191
);
7292
}

0 commit comments

Comments
 (0)