Skip to content

Commit

Permalink
fix: memoize ally table to avoid reset
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Dec 4, 2020
1 parent 7fc4168 commit 79e4456
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 29 deletions.
1 change: 0 additions & 1 deletion plugins/axe-plugin/src/AllyBlock/BaseAllyBlock.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export const BaseAllyBlock: FC<BaseAllyBlockProps> = ({ children }) => {
}
return actions;
}, [incomplete.length, passes.length, violations.length]);
console.log('REDRAW');
return (
<PanelContainer actions={actions} openTab="dashboard" visibleTabs={true}>
<HighlightSelector>{children}</HighlightSelector>
Expand Down
9 changes: 2 additions & 7 deletions plugins/axe-plugin/src/AllyBlock/NodesTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export interface NodesTableProps {

const SelectionCheckbox: FC<{ target: string[] }> = ({ target }) => {
const { isSelected, selection, setSelection } = useContext(SelectionContext);

const checked = isSelected(target);
const toggleSelection = (selector: string[]) => {
const included = tagSelectedList(selection, selector, true);
Expand All @@ -31,13 +32,7 @@ const SelectionCheckbox: FC<{ target: string[] }> = ({ target }) => {
};
return (
<Label>
<Checkbox
onChange={e => {
toggleSelection(target);
e.preventDefault();
}}
checked={checked}
/>
<Checkbox onChange={() => toggleSelection(target)} checked={checked} />
</Label>
);
};
Expand Down
45 changes: 24 additions & 21 deletions plugins/axe-plugin/src/AllyBlock/ResultsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,18 @@ export interface ResultsTableProps {
}

const ResultsTable: FC<ResultsTableProps> = ({ results, hideErrorColumns }) => {
const columns: Column<Record<string, unknown>>[] = useMemo(
() => [
const renderRowSubComponent = useCallback(
({ row }) => (
<NodesTable
nodes={row.original.nodes}
hideErrorColumns={hideErrorColumns}
/>
),
[hideErrorColumns],
);
const table = useMemo(() => {
console.log('MEMO', hideErrorColumns);
const columns: Column<Record<string, unknown>>[] = [
{
// Build our expander column
id: 'expander', // Make sure it has an ID
Expand Down Expand Up @@ -138,26 +148,19 @@ const ResultsTable: FC<ResultsTableProps> = ({ results, hideErrorColumns }) => {
</Flex>
),
},
],
[],
);
const renderRowSubComponent = useCallback(
({ row }) => (
<NodesTable
nodes={row.original.nodes}
hideErrorColumns={hideErrorColumns}
];
return (
<Table
data={results || []}
columns={columns}
hiddenColumns={hideErrorColumns ? ['impact'] : undefined}
renderRowSubComponent={renderRowSubComponent}
/>
),
[hideErrorColumns],
);
return (
<Table
data={results || []}
columns={columns}
hiddenColumns={hideErrorColumns ? ['impact'] : undefined}
renderRowSubComponent={renderRowSubComponent}
/>
);
);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [results?.length, hideErrorColumns, renderRowSubComponent]);

return table;
};

export const ViolationsTable: FC = () => {
Expand Down

0 comments on commit 79e4456

Please sign in to comment.