Skip to content

Commit

Permalink
fix: don't persist controlled values
Browse files Browse the repository at this point in the history
  • Loading branch information
schummar committed Sep 2, 2022
1 parent 7e02bad commit cf16935
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/internalState/tableStateStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,20 @@ export function useTableStateStorage(table: Store<InternalTableState<any>>) {
) {
if (key === 'filterValues') {
for (const [id, value] of data[key]) {
if (state.filters.get(id)?.persist ?? true) {
if (state.filters.get(id)?.persist ?? state.filters.get(id)?.value === undefined) {
state.filterValues.set(id, value);
}
}
} else {
state[key] = data[key];

if (key === 'expanded' || key === 'hiddenColumns' || key === 'selection' || key === 'sort') {
if (state.props[key] !== undefined) {
continue;
}

state.props[`on${(key.slice(0, 1).toUpperCase() + key.slice(1)) as Capitalize<typeof key>}Change`]?.(data[key]);
}

state[key] = data[key];
}
}
}
Expand Down Expand Up @@ -146,11 +150,20 @@ export function useTableStateStorage(table: Store<InternalTableState<any>>) {
if (key === 'filterValues') {
data[key] = new Map();
for (const [id, value] of state.filterValues) {
if (state.filters.get(id)?.persist ?? true) {
if (state.filters.get(id)?.persist ?? state.filters.get(id)?.value === undefined) {
data.filterValues.set(id, value);
}
}
} else {
if (
key === 'expanded' ||
key === 'hiddenColumns' ||
key === 'selection' ||
(key === 'sort' && state.props[key] !== undefined)
) {
continue;
}

data[key] = state[key];
}
}
Expand Down

0 comments on commit cf16935

Please sign in to comment.