Skip to content

Commit 21b1c99

Browse files
Move rendering of AlertTablePathRow to inside of AlertTableResultRow
1 parent 9ecf971 commit 21b1c99

2 files changed

Lines changed: 67 additions & 73 deletions

File tree

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

Lines changed: 14 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { sendTelemetry } from "../common/telemetry";
1919
import { AlertTableHeader } from "./AlertTableHeader";
2020
import { AlertTableNoResults } from "./AlertTableNoResults";
2121
import { AlertTableTruncatedMessage } from "./AlertTableTruncatedMessage";
22-
import { AlertTablePathRow } from "./AlertTablePathRow";
2322
import { AlertTableResultRow } from "./AlertTableResultRow";
2423

2524
type AlertTableProps = ResultTableProps & {
@@ -97,47 +96,20 @@ export class AlertTable extends React.Component<
9796

9897
const rows: JSX.Element[] =
9998
resultSet.interpretation.data.runs[0].results.map(
100-
(result, resultIndex) => {
101-
const resultKey: Keys.Result = { resultIndex };
102-
const currentResultExpanded = this.state.expanded.has(
103-
Keys.keyToString(resultKey),
104-
);
105-
106-
return (
107-
<>
108-
<AlertTableResultRow
109-
result={result}
110-
resultIndex={resultIndex}
111-
currentResultExpanded={currentResultExpanded}
112-
selectedItem={this.state.selectedItem}
113-
databaseUri={databaseUri}
114-
sourceLocationPrefix={sourceLocationPrefix}
115-
updateSelectionCallback={updateSelectionCallback}
116-
toggler={toggler}
117-
scroller={this.scroller}
118-
/>
119-
{currentResultExpanded &&
120-
result.codeFlows &&
121-
Keys.getAllPaths(result).map((path, pathIndex) => (
122-
<AlertTablePathRow
123-
key={`${resultIndex}-${pathIndex}`}
124-
path={path}
125-
pathIndex={pathIndex}
126-
resultIndex={resultIndex}
127-
currentPathExpanded={this.state.expanded.has(
128-
Keys.keyToString({ resultIndex, pathIndex }),
129-
)}
130-
selectedItem={this.state.selectedItem}
131-
databaseUri={databaseUri}
132-
sourceLocationPrefix={sourceLocationPrefix}
133-
updateSelectionCallback={updateSelectionCallback}
134-
toggler={toggler}
135-
scroller={this.scroller}
136-
/>
137-
))}
138-
</>
139-
);
140-
},
99+
(result, resultIndex) => (
100+
<AlertTableResultRow
101+
key={resultIndex}
102+
result={result}
103+
resultIndex={resultIndex}
104+
expanded={this.state.expanded}
105+
selectedItem={this.state.selectedItem}
106+
databaseUri={databaseUri}
107+
sourceLocationPrefix={sourceLocationPrefix}
108+
updateSelectionCallback={updateSelectionCallback}
109+
toggler={toggler}
110+
scroller={this.scroller}
111+
/>
112+
),
141113
);
142114

143115
return (

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

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { AlertTableDropdownIndicatorCell } from "./AlertTableDropdownIndicatorCe
88
import { useMemo } from "react";
99
import { SarifLocation } from "./locations/SarifLocation";
1010
import { SarifMessageWithLocations } from "./locations/SarifMessageWithLocations";
11+
import { AlertTablePathRow } from "./AlertTablePathRow";
1112

1213
interface Props {
1314
result: Sarif.Result;
1415
resultIndex: number;
15-
currentResultExpanded: boolean;
16+
expanded: Set<string>;
1617
selectedItem: undefined | Keys.ResultKey;
1718
databaseUri: string;
1819
sourceLocationPrefix: string;
@@ -27,7 +28,7 @@ export function AlertTableResultRow(props: Props) {
2728
const {
2829
result,
2930
resultIndex,
30-
currentResultExpanded,
31+
expanded,
3132
selectedItem,
3233
databaseUri,
3334
sourceLocationPrefix,
@@ -73,37 +74,58 @@ export function AlertTableResultRow(props: Props) {
7374
/>
7475
);
7576

77+
const currentResultExpanded = expanded.has(Keys.keyToString(resultKey));
7678
return (
77-
<tr
78-
ref={scroller.ref(resultRowIsSelected)}
79-
{...selectableZebraStripe(resultRowIsSelected, resultIndex)}
80-
key={resultIndex}
81-
>
82-
{result.codeFlows === undefined ? (
83-
<>
84-
<td className="vscode-codeql__icon-cell">{info}</td>
85-
<td colSpan={3}>{msg}</td>
86-
</>
87-
) : (
88-
<>
89-
<AlertTableDropdownIndicatorCell
90-
expanded={currentResultExpanded}
91-
onClick={handleDropdownClick}
92-
/>
93-
<td className="vscode-codeql__icon-cell">{listUnordered}</td>
94-
<td colSpan={2}>{msg}</td>
95-
</>
96-
)}
97-
<td className="vscode-codeql__location-cell">
98-
{result.locations && result.locations.length > 0 && (
99-
<SarifLocation
100-
loc={result.locations[0]}
101-
sourceLocationPrefix={sourceLocationPrefix}
79+
<>
80+
<tr
81+
ref={scroller.ref(resultRowIsSelected)}
82+
{...selectableZebraStripe(resultRowIsSelected, resultIndex)}
83+
>
84+
{result.codeFlows === undefined ? (
85+
<>
86+
<td className="vscode-codeql__icon-cell">{info}</td>
87+
<td colSpan={3}>{msg}</td>
88+
</>
89+
) : (
90+
<>
91+
<AlertTableDropdownIndicatorCell
92+
expanded={currentResultExpanded}
93+
onClick={handleDropdownClick}
94+
/>
95+
<td className="vscode-codeql__icon-cell">{listUnordered}</td>
96+
<td colSpan={2}>{msg}</td>
97+
</>
98+
)}
99+
<td className="vscode-codeql__location-cell">
100+
{result.locations && result.locations.length > 0 && (
101+
<SarifLocation
102+
loc={result.locations[0]}
103+
sourceLocationPrefix={sourceLocationPrefix}
104+
databaseUri={databaseUri}
105+
onClick={handleSarifLocationClicked}
106+
/>
107+
)}
108+
</td>
109+
</tr>
110+
{currentResultExpanded &&
111+
result.codeFlows &&
112+
Keys.getAllPaths(result).map((path, pathIndex) => (
113+
<AlertTablePathRow
114+
key={`${resultIndex}-${pathIndex}`}
115+
path={path}
116+
pathIndex={pathIndex}
117+
resultIndex={resultIndex}
118+
currentPathExpanded={expanded.has(
119+
Keys.keyToString({ resultIndex, pathIndex }),
120+
)}
121+
selectedItem={selectedItem}
102122
databaseUri={databaseUri}
103-
onClick={handleSarifLocationClicked}
123+
sourceLocationPrefix={sourceLocationPrefix}
124+
updateSelectionCallback={updateSelectionCallback}
125+
toggler={toggler}
126+
scroller={scroller}
104127
/>
105-
)}
106-
</td>
107-
</tr>
128+
))}
129+
</>
108130
);
109131
}

0 commit comments

Comments
 (0)