Skip to content

Commit 2949fc3

Browse files
committed
Replace 'expanded' with a Set<number>
1 parent ab933fc commit 2949fc3

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

extensions/ql-vscode/src/view/results/alert-table.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import { isWholeFileLoc, isLineColumnLoc } from '../../pure/bqrs-utils';
1717

1818
export type PathTableProps = ResultTableProps & { resultSet: InterpretedResultSet<SarifInterpretationData> };
1919
export interface PathTableState {
20-
expanded: { [k: string]: boolean };
20+
expanded: Set<number>;
2121
selectedItem: undefined | Keys.PathNode | Keys.Result;
2222
}
2323

2424
export class PathTable extends React.Component<PathTableProps, PathTableState> {
2525
constructor(props: PathTableProps) {
2626
super(props);
27-
this.state = { expanded: {}, selectedItem: undefined };
27+
this.state = { expanded: new Set<number>(), selectedItem: undefined };
2828
this.handleNavigationEvent = this.handleNavigationEvent.bind(this);
2929
}
3030

@@ -35,16 +35,15 @@ export class PathTable extends React.Component<PathTableProps, PathTableState> {
3535
*/
3636
toggle(e: React.MouseEvent, indices: number[]) {
3737
this.setState(previousState => {
38-
if (previousState.expanded[indices[0]]) {
39-
return { expanded: { ...previousState.expanded, [indices[0]]: false } };
40-
}
41-
else {
42-
const expanded = { ...previousState.expanded };
38+
const expanded = new Set(previousState.expanded);
39+
if (previousState.expanded.has(indices[0])) {
40+
expanded.delete(indices[0]);
41+
} else {
4342
for (const index of indices) {
44-
expanded[index] = true;
43+
expanded.add(index);
4544
}
46-
return { expanded };
4745
}
46+
return { expanded };
4847
});
4948
e.stopPropagation();
5049
e.preventDefault();
@@ -202,7 +201,7 @@ export class PathTable extends React.Component<PathTableProps, PathTableState> {
202201
[<span key="0">{text}</span>] :
203202
renderRelatedLocations(text, result.relatedLocations, resultKey);
204203

205-
const currentResultExpanded = this.state.expanded[expansionIndex];
204+
const currentResultExpanded = this.state.expanded.has(expansionIndex);
206205
const indicator = currentResultExpanded ? octicons.chevronDown : octicons.chevronRight;
207206
const location = result.locations !== undefined && result.locations.length > 0 &&
208207
renderSarifLocation(result.locations[0], resultKey);
@@ -246,7 +245,7 @@ export class PathTable extends React.Component<PathTableProps, PathTableState> {
246245

247246
paths.forEach((path, pathIndex) => {
248247
const pathKey = { resultIndex, pathIndex };
249-
const currentPathExpanded = this.state.expanded[expansionIndex];
248+
const currentPathExpanded = this.state.expanded.has(expansionIndex);
250249
if (currentResultExpanded) {
251250
const indicator = currentPathExpanded ? octicons.chevronDown : octicons.chevronRight;
252251
rows.push(

0 commit comments

Comments
 (0)