Pass around toggle instead of toggler

This commit is contained in:
Robert
2023-08-16 15:17:31 +01:00
parent e3596db8e7
commit bd5d361de1
3 changed files with 10 additions and 16 deletions

View File

@@ -84,12 +84,6 @@ export class AlertTable extends React.Component<
}; };
}; };
const toggler: (keys: Keys.ResultKey[]) => (e: React.MouseEvent) => void = (
indices,
) => {
return (e) => this.toggle(e, indices);
};
if (!resultSet.interpretation.data.runs?.[0]?.results?.length) { if (!resultSet.interpretation.data.runs?.[0]?.results?.length) {
return <AlertTableNoResults {...this.props} />; return <AlertTableNoResults {...this.props} />;
} }
@@ -109,7 +103,7 @@ export class AlertTable extends React.Component<
databaseUri={databaseUri} databaseUri={databaseUri}
sourceLocationPrefix={sourceLocationPrefix} sourceLocationPrefix={sourceLocationPrefix}
updateSelectionCallback={updateSelectionCallback} updateSelectionCallback={updateSelectionCallback}
toggler={toggler} toggleExpanded={this.toggle.bind(this)}
scroller={this.scroller} scroller={this.scroller}
/> />
), ),

View File

@@ -18,7 +18,7 @@ interface Props {
updateSelectionCallback: ( updateSelectionCallback: (
resultKey: Keys.PathNode | Keys.Result | undefined, resultKey: Keys.PathNode | Keys.Result | undefined,
) => () => void; ) => () => void;
toggler: (keys: Keys.ResultKey[]) => (e: React.MouseEvent) => void; toggleExpanded: (e: React.MouseEvent, keys: Keys.ResultKey[]) => void;
scroller: ScrollIntoViewHelper; scroller: ScrollIntoViewHelper;
} }
@@ -32,7 +32,7 @@ export function AlertTablePathRow(props: Props) {
databaseUri, databaseUri,
sourceLocationPrefix, sourceLocationPrefix,
updateSelectionCallback, updateSelectionCallback,
toggler, toggleExpanded,
scroller, scroller,
} = props; } = props;
@@ -41,8 +41,8 @@ export function AlertTablePathRow(props: Props) {
[pathIndex, resultIndex], [pathIndex, resultIndex],
); );
const handleDropdownClick = useMemo( const handleDropdownClick = useMemo(
() => toggler([pathKey]), () => (e: React.MouseEvent) => toggleExpanded(e, [pathKey]),
[pathKey, toggler], [pathKey, toggleExpanded],
); );
const isPathSpecificallySelected = Keys.equalsNotUndefined( const isPathSpecificallySelected = Keys.equalsNotUndefined(

View File

@@ -20,7 +20,7 @@ interface Props {
updateSelectionCallback: ( updateSelectionCallback: (
resultKey: Keys.PathNode | Keys.Result | undefined, resultKey: Keys.PathNode | Keys.Result | undefined,
) => () => void; ) => () => void;
toggler: (keys: Keys.ResultKey[]) => (e: React.MouseEvent) => void; toggleExpanded: (e: React.MouseEvent, keys: Keys.ResultKey[]) => void;
scroller: ScrollIntoViewHelper; scroller: ScrollIntoViewHelper;
} }
@@ -33,7 +33,7 @@ export function AlertTableResultRow(props: Props) {
databaseUri, databaseUri,
sourceLocationPrefix, sourceLocationPrefix,
updateSelectionCallback, updateSelectionCallback,
toggler, toggleExpanded,
scroller, scroller,
} = props; } = props;
@@ -53,8 +53,8 @@ export function AlertTableResultRow(props: Props) {
: /* if there's exactly one path, auto-expand : /* if there's exactly one path, auto-expand
* the path when expanding the result */ * the path when expanding the result */
[resultKey]; [resultKey];
return toggler(indices); return (e: React.MouseEvent) => toggleExpanded(e, indices);
}, [result, resultKey, toggler]); }, [result, resultKey, toggleExpanded]);
const resultRowIsSelected = const resultRowIsSelected =
selectedItem?.resultIndex === resultIndex && selectedItem?.resultIndex === resultIndex &&
@@ -122,7 +122,7 @@ export function AlertTableResultRow(props: Props) {
databaseUri={databaseUri} databaseUri={databaseUri}
sourceLocationPrefix={sourceLocationPrefix} sourceLocationPrefix={sourceLocationPrefix}
updateSelectionCallback={updateSelectionCallback} updateSelectionCallback={updateSelectionCallback}
toggler={toggler} toggleExpanded={toggleExpanded}
scroller={scroller} scroller={scroller}
/> />
))} ))}