Skip to content

Commit 91e69c9

Browse files
Pull out AlertTablePathNodeRow to a separate component
1 parent 7e31b6e commit 91e69c9

2 files changed

Lines changed: 113 additions & 75 deletions

File tree

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

Lines changed: 15 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { SarifLocation } from "./locations/SarifLocation";
2424
import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCell";
2525
import { AlertTableNoResults } from "./AlertTableNoResults";
2626
import { AlertTableTruncatedMessage } from "./AlertTableTruncatedMessage";
27+
import { AlertTablePathNodeRow } from "./AlertTablePathNodeRow";
2728

2829
type AlertTableProps = ResultTableProps & {
2930
resultSet: InterpretedResultSet<SarifInterpretationData>;
@@ -210,81 +211,20 @@ export class AlertTable extends React.Component<
210211

211212
const pathNodeRows =
212213
currentPathExpanded &&
213-
path.locations.map((step, pathNodeIndex) => {
214-
const pathNodeKey: Keys.PathNode = {
215-
...pathKey,
216-
pathNodeIndex,
217-
};
218-
const msg =
219-
step.location !== undefined &&
220-
step.location.message !== undefined ? (
221-
<SarifLocation
222-
text={step.location.message.text}
223-
loc={step.location}
224-
sourceLocationPrefix={sourceLocationPrefix}
225-
databaseUri={databaseUri}
226-
onClick={updateSelectionCallback(pathNodeKey)}
227-
/>
228-
) : (
229-
"[no location]"
230-
);
231-
const additionalMsg =
232-
step.location !== undefined ? (
233-
<SarifLocation
234-
loc={step.location}
235-
sourceLocationPrefix={sourceLocationPrefix}
236-
databaseUri={databaseUri}
237-
onClick={updateSelectionCallback(pathNodeKey)}
238-
/>
239-
) : (
240-
""
241-
);
242-
const isSelected = Keys.equalsNotUndefined(
243-
this.state.selectedItem,
244-
pathNodeKey,
245-
);
246-
const stepIndex = pathNodeIndex + 1; // Convert to 1-based
247-
const zebraIndex = resultIndex + stepIndex;
248-
return (
249-
<tr
250-
ref={this.scroller.ref(isSelected)}
251-
className={
252-
isSelected
253-
? "vscode-codeql__selected-path-node"
254-
: undefined
255-
}
256-
key={`${resultIndex}-${pathIndex}-${pathNodeIndex}`}
257-
>
258-
<td className="vscode-codeql__icon-cell">
259-
<span className="vscode-codeql__vertical-rule"></span>
260-
</td>
261-
<td className="vscode-codeql__icon-cell">
262-
<span className="vscode-codeql__vertical-rule"></span>
263-
</td>
264-
<td
265-
{...selectableZebraStripe(
266-
isSelected,
267-
zebraIndex,
268-
"vscode-codeql__path-index-cell",
269-
)}
270-
>
271-
{stepIndex}
272-
</td>
273-
<td {...selectableZebraStripe(isSelected, zebraIndex)}>
274-
{msg}{" "}
275-
</td>
276-
<td
277-
{...selectableZebraStripe(
278-
isSelected,
279-
zebraIndex,
280-
"vscode-codeql__location-cell",
281-
)}
282-
>
283-
{additionalMsg}
284-
</td>
285-
</tr>
286-
);
287-
});
214+
path.locations.map((step, pathNodeIndex) => (
215+
<AlertTablePathNodeRow
216+
key={`${resultIndex}-${pathIndex}-${pathNodeIndex}`}
217+
step={step}
218+
pathNodeIndex={pathNodeIndex}
219+
pathIndex={pathIndex}
220+
resultIndex={resultIndex}
221+
selectedItem={selectedItem}
222+
databaseUri={databaseUri}
223+
sourceLocationPrefix={sourceLocationPrefix}
224+
updateSelectionCallback={updateSelectionCallback}
225+
scroller={this.scroller}
226+
/>
227+
));
288228

289229
return (
290230
<>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
import * as React from "react";
2+
import * as Sarif from "sarif";
3+
import * as Keys from "./result-keys";
4+
import { SarifLocation } from "./locations/SarifLocation";
5+
import { selectableZebraStripe } from "./result-table-utils";
6+
import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
7+
8+
interface Props {
9+
step: Sarif.ThreadFlowLocation;
10+
pathNodeIndex: number;
11+
pathIndex: number;
12+
resultIndex: number;
13+
selectedItem: undefined | Keys.ResultKey;
14+
databaseUri: string;
15+
sourceLocationPrefix: string;
16+
updateSelectionCallback: (
17+
resultKey: Keys.PathNode | Keys.Result | undefined,
18+
) => () => void;
19+
scroller: ScrollIntoViewHelper;
20+
}
21+
22+
export function AlertTablePathNodeRow(props: Props) {
23+
const {
24+
step,
25+
pathNodeIndex,
26+
pathIndex,
27+
resultIndex,
28+
selectedItem,
29+
databaseUri,
30+
sourceLocationPrefix,
31+
updateSelectionCallback,
32+
scroller,
33+
} = props;
34+
35+
const pathNodeKey: Keys.PathNode = {
36+
resultIndex,
37+
pathIndex,
38+
pathNodeIndex,
39+
};
40+
const msg =
41+
step.location !== undefined && step.location.message !== undefined ? (
42+
<SarifLocation
43+
text={step.location.message.text}
44+
loc={step.location}
45+
sourceLocationPrefix={sourceLocationPrefix}
46+
databaseUri={databaseUri}
47+
onClick={updateSelectionCallback(pathNodeKey)}
48+
/>
49+
) : (
50+
"[no location]"
51+
);
52+
const additionalMsg =
53+
step.location !== undefined ? (
54+
<SarifLocation
55+
loc={step.location}
56+
sourceLocationPrefix={sourceLocationPrefix}
57+
databaseUri={databaseUri}
58+
onClick={updateSelectionCallback(pathNodeKey)}
59+
/>
60+
) : (
61+
""
62+
);
63+
const isSelected = Keys.equalsNotUndefined(selectedItem, pathNodeKey);
64+
const stepIndex = pathNodeIndex + 1; // Convert to 1-based
65+
const zebraIndex = resultIndex + stepIndex;
66+
return (
67+
<tr
68+
ref={scroller.ref(isSelected)}
69+
className={isSelected ? "vscode-codeql__selected-path-node" : undefined}
70+
>
71+
<td className="vscode-codeql__icon-cell">
72+
<span className="vscode-codeql__vertical-rule"></span>
73+
</td>
74+
<td className="vscode-codeql__icon-cell">
75+
<span className="vscode-codeql__vertical-rule"></span>
76+
</td>
77+
<td
78+
{...selectableZebraStripe(
79+
isSelected,
80+
zebraIndex,
81+
"vscode-codeql__path-index-cell",
82+
)}
83+
>
84+
{stepIndex}
85+
</td>
86+
<td {...selectableZebraStripe(isSelected, zebraIndex)}>{msg} </td>
87+
<td
88+
{...selectableZebraStripe(
89+
isSelected,
90+
zebraIndex,
91+
"vscode-codeql__location-cell",
92+
)}
93+
>
94+
{additionalMsg}
95+
</td>
96+
</tr>
97+
);
98+
}

0 commit comments

Comments
 (0)