Skip to content

Commit

Permalink
fix(memorize filter in state): memorize filter in state
Browse files Browse the repository at this point in the history
memorize filter in state
  • Loading branch information
Conglei Shi authored and zhaoyongjie committed Nov 26, 2021
1 parent f814882 commit a71b9f2
Showing 1 changed file with 23 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ type TableState = {
selectedCells: Set<string>;
searchKeyword: string;
filteredRows: ParentRow[];
filters: {
[key: string]: (string | number)[];
};
};

function getCellHash(cell: Cell) {
Expand All @@ -55,6 +58,7 @@ class TableVis extends React.PureComponent<InternalTableProps, TableState> {
selectedCells: new Set(),
searchKeyword: '',
filteredRows: [],
filters: props.filters,
};
}

Expand Down Expand Up @@ -92,7 +96,7 @@ class TableVis extends React.PureComponent<InternalTableProps, TableState> {
const content = Object.values(row.data)
.join('|')
.toLowerCase();
return content.indexOf(value) >= 0;
return content.indexOf(value.toLowerCase()) >= 0;
});
this.setState({
searchKeyword: value,
Expand All @@ -106,22 +110,25 @@ class TableVis extends React.PureComponent<InternalTableProps, TableState> {
TableState
> = (props: InternalTableProps, state: TableState) => {
const { filters } = props;
const { selectedCells } = state;
const newSelectedCells = new Set(Array.from(selectedCells));
Object.keys(filters).forEach(key => {
filters[key].forEach(value => {
newSelectedCells.add(
getCellHash({
key,
value,
}),
);
const { selectedCells, filters: prevFilters } = state;
if (prevFilters !== filters) {
const newSelectedCells = new Set(Array.from(selectedCells));
Object.keys(filters).forEach(key => {
filters[key].forEach(value => {
newSelectedCells.add(
getCellHash({
key,
value,
}),
);
});
});
});
return {
...state,
selectedCells: newSelectedCells,
};
return {
...state,
selectedCells: newSelectedCells,
};
}
return state;
};

render() {
Expand Down

0 comments on commit a71b9f2

Please sign in to comment.