mirror of
https://github.com/apache/superset.git
synced 2024-09-19 20:19:37 -04:00
fix(memorize filter in state): memorize filter in state
memorize filter in state
This commit is contained in:
parent
f814882550
commit
a71b9f2318
@ -40,6 +40,9 @@ type TableState = {
|
|||||||
selectedCells: Set<string>;
|
selectedCells: Set<string>;
|
||||||
searchKeyword: string;
|
searchKeyword: string;
|
||||||
filteredRows: ParentRow[];
|
filteredRows: ParentRow[];
|
||||||
|
filters: {
|
||||||
|
[key: string]: (string | number)[];
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
function getCellHash(cell: Cell) {
|
function getCellHash(cell: Cell) {
|
||||||
@ -55,6 +58,7 @@ class TableVis extends React.PureComponent<InternalTableProps, TableState> {
|
|||||||
selectedCells: new Set(),
|
selectedCells: new Set(),
|
||||||
searchKeyword: '',
|
searchKeyword: '',
|
||||||
filteredRows: [],
|
filteredRows: [],
|
||||||
|
filters: props.filters,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +96,7 @@ class TableVis extends React.PureComponent<InternalTableProps, TableState> {
|
|||||||
const content = Object.values(row.data)
|
const content = Object.values(row.data)
|
||||||
.join('|')
|
.join('|')
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
return content.indexOf(value) >= 0;
|
return content.indexOf(value.toLowerCase()) >= 0;
|
||||||
});
|
});
|
||||||
this.setState({
|
this.setState({
|
||||||
searchKeyword: value,
|
searchKeyword: value,
|
||||||
@ -106,22 +110,25 @@ class TableVis extends React.PureComponent<InternalTableProps, TableState> {
|
|||||||
TableState
|
TableState
|
||||||
> = (props: InternalTableProps, state: TableState) => {
|
> = (props: InternalTableProps, state: TableState) => {
|
||||||
const { filters } = props;
|
const { filters } = props;
|
||||||
const { selectedCells } = state;
|
const { selectedCells, filters: prevFilters } = state;
|
||||||
const newSelectedCells = new Set(Array.from(selectedCells));
|
if (prevFilters !== filters) {
|
||||||
Object.keys(filters).forEach(key => {
|
const newSelectedCells = new Set(Array.from(selectedCells));
|
||||||
filters[key].forEach(value => {
|
Object.keys(filters).forEach(key => {
|
||||||
newSelectedCells.add(
|
filters[key].forEach(value => {
|
||||||
getCellHash({
|
newSelectedCells.add(
|
||||||
key,
|
getCellHash({
|
||||||
value,
|
key,
|
||||||
}),
|
value,
|
||||||
);
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
return {
|
||||||
return {
|
...state,
|
||||||
...state,
|
selectedCells: newSelectedCells,
|
||||||
selectedCells: newSelectedCells,
|
};
|
||||||
};
|
}
|
||||||
|
return state;
|
||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
Loading…
Reference in New Issue
Block a user