Skip to content

Commit af1af07

Browse files
Convert updateSelectionCallback to not use double-nested methods
1 parent d65ce3e commit af1af07

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@ export class AlertTable extends React.Component<
7575
const updateSelectionCallback = (
7676
resultKey: Keys.PathNode | Keys.Result | undefined,
7777
) => {
78-
return () => {
79-
this.setState((previousState) => ({
80-
...previousState,
81-
selectedItem: resultKey,
82-
}));
83-
sendTelemetry("local-results-alert-table-path-selected");
84-
};
78+
this.setState((previousState) => ({
79+
...previousState,
80+
selectedItem: resultKey,
81+
}));
82+
sendTelemetry("local-results-alert-table-path-selected");
8583
};
8684

8785
if (!resultSet.interpretation.data.runs?.[0]?.results?.length) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as Keys from "./result-keys";
44
import { SarifLocation } from "./locations/SarifLocation";
55
import { selectableZebraStripe } from "./result-table-utils";
66
import { ScrollIntoViewHelper } from "./scroll-into-view-helper";
7-
import { useMemo } from "react";
7+
import { useCallback, useMemo } from "react";
88

99
interface Props {
1010
step: Sarif.ThreadFlowLocation;
@@ -16,7 +16,7 @@ interface Props {
1616
sourceLocationPrefix: string;
1717
updateSelectionCallback: (
1818
resultKey: Keys.PathNode | Keys.Result | undefined,
19-
) => () => void;
19+
) => void;
2020
scroller: ScrollIntoViewHelper;
2121
}
2222

@@ -41,7 +41,7 @@ export function AlertTablePathNodeRow(props: Props) {
4141
}),
4242
[pathIndex, pathNodeIndex, resultIndex],
4343
);
44-
const handleSarifLocationClicked = useMemo(
44+
const handleSarifLocationClicked = useCallback(
4545
() => updateSelectionCallback(pathNodeKey),
4646
[pathNodeKey, updateSelectionCallback],
4747
);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ interface Props {
1717
sourceLocationPrefix: string;
1818
updateSelectionCallback: (
1919
resultKey: Keys.PathNode | Keys.Result | undefined,
20-
) => () => void;
20+
) => void;
2121
toggleExpanded: (e: React.MouseEvent, keys: Keys.ResultKey[]) => void;
2222
scroller: ScrollIntoViewHelper;
2323
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface Props {
1919
sourceLocationPrefix: string;
2020
updateSelectionCallback: (
2121
resultKey: Keys.PathNode | Keys.Result | undefined,
22-
) => () => void;
22+
) => void;
2323
toggleExpanded: (e: React.MouseEvent, keys: Keys.ResultKey[]) => void;
2424
scroller: ScrollIntoViewHelper;
2525
}
@@ -42,7 +42,7 @@ export function AlertTableResultRow(props: Props) {
4242
[resultIndex],
4343
);
4444

45-
const handleSarifLocationClicked = useMemo(
45+
const handleSarifLocationClicked = useCallback(
4646
() => updateSelectionCallback(resultKey),
4747
[resultKey, updateSelectionCallback],
4848
);

0 commit comments

Comments
 (0)