Skip to content

Commit 23d815f

Browse files
Use useMemo for callback passed to AlertTableDropdownIndicatorCell.onClick in AlertTableResultRow
1 parent 8945abc commit 23d815f

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { listUnordered } from "./octicons";
55
import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
66
import { selectableZebraStripe } from "./result-table-utils";
77
import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCell";
8+
import { useMemo } from "react";
89

910
interface Props {
1011
result: Sarif.Result;
@@ -29,15 +30,16 @@ export function AlertTableResultRow(props: Props) {
2930
locationCells,
3031
} = props;
3132

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];
33+
const handleDropdownClick = useMemo(() => {
34+
const resultKey: Keys.Result = { resultIndex };
35+
const indices =
36+
Keys.getAllPaths(result).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+
return toggler(indices);
42+
}, [result, resultIndex, toggler]);
4143

4244
const resultRowIsSelected =
4345
selectedItem?.resultIndex === resultIndex &&
@@ -51,7 +53,7 @@ export function AlertTableResultRow(props: Props) {
5153
>
5254
<AlertTableDropdownIndicatorCell
5355
expanded={currentResultExpanded}
54-
onClick={toggler(indices)}
56+
onClick={handleDropdownClick}
5557
/>
5658
<td className="vscode-codeql__icon-cell">{listUnordered}</td>
5759
<td colSpan={2}>{msg}</td>

0 commit comments

Comments
 (0)