-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathAlertTablePathRow.tsx
More file actions
83 lines (78 loc) · 2.45 KB
/
AlertTablePathRow.tsx
File metadata and controls
83 lines (78 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import type { Run, ThreadFlow } from "sarif";
import type {
PathNode,
Result as ResultKeysResult,
ResultKey,
} from "./result-keys";
import { equalsNotUndefined } from "./result-keys";
import { selectableZebraStripe } from "./result-table-utils";
import { AlertTablePathNodeRow } from "./AlertTablePathNodeRow";
import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCell";
import { useCallback, useMemo } from "react";
import { VerticalRule } from "../common/VerticalRule";
import type { UserSettings } from "../../common/interface-types";
import { pluralize } from "../../common/word";
export interface Props {
path: ThreadFlow;
pathIndex: number;
resultIndex: number;
currentPathExpanded: boolean;
selectedItem: undefined | ResultKey;
selectedItemRef: React.RefObject<HTMLTableRowElement | null>;
databaseUri: string;
sourceLocationPrefix: string;
run?: Run;
userSettings: UserSettings;
updateSelectionCallback: (
resultKey: PathNode | ResultKeysResult | undefined,
) => void;
toggleExpanded: (e: React.MouseEvent, keys: ResultKey[]) => void;
}
export function AlertTablePathRow(props: Props) {
const {
path,
pathIndex,
resultIndex,
currentPathExpanded,
selectedItem,
selectedItemRef,
toggleExpanded,
} = props;
const pathKey = useMemo(
() => ({ resultIndex, pathIndex }),
[pathIndex, resultIndex],
);
const handleDropdownClick = useCallback(
(e: React.MouseEvent) => toggleExpanded(e, [pathKey]),
[pathKey, toggleExpanded],
);
const isPathSpecificallySelected = equalsNotUndefined(pathKey, selectedItem);
return (
<>
<tr
ref={isPathSpecificallySelected ? selectedItemRef : undefined}
{...selectableZebraStripe(isPathSpecificallySelected, resultIndex)}
>
<td className="vscode-codeql__icon-cell">
<VerticalRule />
</td>
<AlertTableDropdownIndicatorCell
expanded={currentPathExpanded}
onClick={handleDropdownClick}
/>
<td className="vscode-codeql__text-center" colSpan={4}>
{`Path (${pluralize(path.locations.length, "step", "steps")})`}
</td>
</tr>
{currentPathExpanded &&
path.locations.map((step, pathNodeIndex) => (
<AlertTablePathNodeRow
key={`${resultIndex}-${pathIndex}-${pathNodeIndex}`}
{...props}
step={step}
pathNodeIndex={pathNodeIndex}
/>
))}
</>
);
}