Skip to content

Commit acb76a6

Browse files
Pull out AlertTablePathRow to a separate component
1 parent ba0cf9a commit acb76a6

2 files changed

Lines changed: 103 additions & 56 deletions

File tree

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

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +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";
27+
import { AlertTablePathRow } from "./AlertTablePathRow";
2828

2929
type AlertTableProps = ResultTableProps & {
3030
resultSet: InterpretedResultSet<SarifInterpretationData>;
@@ -178,61 +178,23 @@ export class AlertTable extends React.Component<
178178

179179
const pathRows =
180180
currentResultExpanded &&
181-
paths.map((path, pathIndex) => {
182-
const pathKey = { resultIndex, pathIndex };
183-
const currentPathExpanded = this.state.expanded.has(
184-
Keys.keyToString(pathKey),
185-
);
186-
const isPathSpecificallySelected = Keys.equalsNotUndefined(
187-
pathKey,
188-
selectedItem,
189-
);
190-
const pathRow = (
191-
<tr
192-
ref={this.scroller.ref(isPathSpecificallySelected)}
193-
{...selectableZebraStripe(
194-
isPathSpecificallySelected,
195-
resultIndex,
196-
)}
197-
key={`${resultIndex}-${pathIndex}`}
198-
>
199-
<td className="vscode-codeql__icon-cell">
200-
<span className="vscode-codeql__vertical-rule"></span>
201-
</td>
202-
<AlertTableDropdownIndicatorCell
203-
expanded={currentPathExpanded}
204-
onClick={toggler([pathKey])}
205-
/>
206-
<td className="vscode-codeql__text-center" colSpan={3}>
207-
Path
208-
</td>
209-
</tr>
210-
);
211-
212-
const pathNodeRows =
213-
currentPathExpanded &&
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-
));
228-
229-
return (
230-
<>
231-
{pathRow}
232-
{pathNodeRows}
233-
</>
234-
);
235-
});
181+
paths.map((path, pathIndex) => (
182+
<AlertTablePathRow
183+
key={`${resultIndex}-${pathIndex}`}
184+
path={path}
185+
pathIndex={pathIndex}
186+
resultIndex={resultIndex}
187+
currentPathExpanded={this.state.expanded.has(
188+
Keys.keyToString({ resultIndex, pathIndex }),
189+
)}
190+
selectedItem={selectedItem}
191+
databaseUri={databaseUri}
192+
sourceLocationPrefix={sourceLocationPrefix}
193+
updateSelectionCallback={updateSelectionCallback}
194+
toggler={toggler}
195+
scroller={this.scroller}
196+
/>
197+
));
236198

237199
return (
238200
<>
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
import * as React from "react";
2+
import * as Sarif from "sarif";
3+
import * as Keys from "./result-keys";
4+
import { selectableZebraStripe } from "./result-table-utils";
5+
import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
6+
import { AlertTablePathNodeRow } from "./AlertTablePathNodeRow";
7+
import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCell";
8+
9+
interface Props {
10+
path: Sarif.ThreadFlow;
11+
pathIndex: number;
12+
resultIndex: number;
13+
currentPathExpanded: boolean;
14+
selectedItem: undefined | Keys.ResultKey;
15+
databaseUri: string;
16+
sourceLocationPrefix: string;
17+
updateSelectionCallback: (
18+
resultKey: Keys.PathNode | Keys.Result | undefined,
19+
) => () => void;
20+
toggler: (keys: Keys.ResultKey[]) => (e: React.MouseEvent) => void;
21+
scroller: ScrollIntoViewHelper;
22+
}
23+
24+
export function AlertTablePathRow(props: Props) {
25+
const {
26+
path,
27+
pathIndex,
28+
resultIndex,
29+
currentPathExpanded,
30+
selectedItem,
31+
databaseUri,
32+
sourceLocationPrefix,
33+
updateSelectionCallback,
34+
toggler,
35+
scroller,
36+
} = props;
37+
38+
const pathKey = { resultIndex, pathIndex };
39+
40+
const isPathSpecificallySelected = Keys.equalsNotUndefined(
41+
pathKey,
42+
selectedItem,
43+
);
44+
const pathRow = (
45+
<tr
46+
ref={scroller.ref(isPathSpecificallySelected)}
47+
{...selectableZebraStripe(isPathSpecificallySelected, resultIndex)}
48+
>
49+
<td className="vscode-codeql__icon-cell">
50+
<span className="vscode-codeql__vertical-rule"></span>
51+
</td>
52+
<AlertTableDropdownIndicatorCell
53+
expanded={currentPathExpanded}
54+
onClick={toggler([pathKey])}
55+
/>
56+
<td className="vscode-codeql__text-center" colSpan={3}>
57+
Path
58+
</td>
59+
</tr>
60+
);
61+
62+
const pathNodeRows =
63+
currentPathExpanded &&
64+
path.locations.map((step, pathNodeIndex) => (
65+
<AlertTablePathNodeRow
66+
key={`${resultIndex}-${pathIndex}-${pathNodeIndex}`}
67+
step={step}
68+
pathNodeIndex={pathNodeIndex}
69+
pathIndex={pathIndex}
70+
resultIndex={resultIndex}
71+
selectedItem={selectedItem}
72+
databaseUri={databaseUri}
73+
sourceLocationPrefix={sourceLocationPrefix}
74+
updateSelectionCallback={updateSelectionCallback}
75+
scroller={scroller}
76+
/>
77+
));
78+
79+
return (
80+
<>
81+
{pathRow}
82+
{pathNodeRows}
83+
</>
84+
);
85+
}

0 commit comments

Comments
 (0)