Skip to content

Commit 8945abc

Browse files
Pull out AlertTableResultRow to a separate component
1 parent a576dac commit 8945abc

2 files changed

Lines changed: 73 additions & 22 deletions

File tree

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

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from "react";
22
import * as Sarif from "sarif";
33
import * as Keys from "./result-keys";
4-
import { info, listUnordered } from "./octicons";
4+
import { info } from "./octicons";
55
import {
66
className,
77
ResultTableProps,
@@ -21,10 +21,10 @@ import { sendTelemetry } from "../common/telemetry";
2121
import { AlertTableHeader } from "./AlertTableHeader";
2222
import { SarifMessageWithLocations } from "./locations/SarifMessageWithLocations";
2323
import { SarifLocation } from "./locations/SarifLocation";
24-
import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCell";
2524
import { AlertTableNoResults } from "./AlertTableNoResults";
2625
import { AlertTableTruncatedMessage } from "./AlertTableTruncatedMessage";
2726
import { AlertTablePathRow } from "./AlertTablePathRow";
27+
import { AlertTableResultRow } from "./AlertTableResultRow";
2828

2929
type AlertTableProps = ResultTableProps & {
3030
resultSet: InterpretedResultSet<SarifInterpretationData>;
@@ -153,27 +153,17 @@ export class AlertTable extends React.Component<
153153
} else {
154154
const paths: Sarif.ThreadFlow[] = Keys.getAllPaths(result);
155155

156-
const indices =
157-
paths.length === 1
158-
? [resultKey, { ...resultKey, pathIndex: 0 }]
159-
: /* if there's exactly one path, auto-expand
160-
* the path when expanding the result */
161-
[resultKey];
162-
163156
const resultRow = (
164-
<tr
165-
ref={this.scroller.ref(resultRowIsSelected)}
166-
{...selectableZebraStripe(resultRowIsSelected, resultIndex)}
167-
key={resultIndex}
168-
>
169-
<AlertTableDropdownIndicatorCell
170-
expanded={currentResultExpanded}
171-
onClick={toggler(indices)}
172-
/>
173-
<td className="vscode-codeql__icon-cell">{listUnordered}</td>
174-
<td colSpan={2}>{msg}</td>
175-
{locationCells}
176-
</tr>
157+
<AlertTableResultRow
158+
result={result}
159+
resultIndex={resultIndex}
160+
currentResultExpanded={currentResultExpanded}
161+
selectedItem={selectedItem}
162+
toggler={toggler}
163+
scroller={this.scroller}
164+
msg={msg}
165+
locationCells={locationCells}
166+
/>
177167
);
178168

179169
const pathRows =
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import * as React from "react";
2+
import * as Sarif from "sarif";
3+
import * as Keys from "./result-keys";
4+
import { listUnordered } from "./octicons";
5+
import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
6+
import { selectableZebraStripe } from "./result-table-utils";
7+
import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCell";
8+
9+
interface Props {
10+
result: Sarif.Result;
11+
resultIndex: number;
12+
currentResultExpanded: boolean;
13+
selectedItem: undefined | Keys.ResultKey;
14+
toggler: (keys: Keys.ResultKey[]) => (e: React.MouseEvent) => void;
15+
scroller: ScrollIntoViewHelper;
16+
msg: JSX.Element;
17+
locationCells: JSX.Element;
18+
}
19+
20+
export function AlertTableResultRow(props: Props) {
21+
const {
22+
result,
23+
resultIndex,
24+
currentResultExpanded,
25+
selectedItem,
26+
toggler,
27+
scroller,
28+
msg,
29+
locationCells,
30+
} = props;
31+
32+
const resultKey: Keys.Result = { resultIndex };
33+
34+
const paths: Sarif.ThreadFlow[] = Keys.getAllPaths(result);
35+
const indices =
36+
paths.length === 1
37+
? [resultKey, { ...resultKey, pathIndex: 0 }]
38+
: /* if there's exactly one path, auto-expand
39+
* the path when expanding the result */
40+
[resultKey];
41+
42+
const resultRowIsSelected =
43+
selectedItem?.resultIndex === resultIndex &&
44+
selectedItem.pathIndex === undefined;
45+
46+
return (
47+
<tr
48+
ref={scroller.ref(resultRowIsSelected)}
49+
{...selectableZebraStripe(resultRowIsSelected, resultIndex)}
50+
key={resultIndex}
51+
>
52+
<AlertTableDropdownIndicatorCell
53+
expanded={currentResultExpanded}
54+
onClick={toggler(indices)}
55+
/>
56+
<td className="vscode-codeql__icon-cell">{listUnordered}</td>
57+
<td colSpan={2}>{msg}</td>
58+
{locationCells}
59+
</tr>
60+
);
61+
}

0 commit comments

Comments
 (0)