fix bug when remote pagination have same filter conds but change pages will cause data doesnt reflect

This commit is contained in:
AllenFang
2018-01-21 17:12:07 +08:00
parent 2263282629
commit 045ca4adb0
2 changed files with 24 additions and 3 deletions
+5 -3
View File
@@ -23,12 +23,14 @@ export default (Base, {
componentWillReceiveProps({ isDataChanged, store, columns }) {
// consider to use lodash.isEqual
if (JSON.stringify(this.state.currFilters) !== JSON.stringify(store.filters)) {
const isRemoteFilter = this.isRemoteFiltering() || this.isRemotePagination();
if (isRemoteFilter ||
JSON.stringify(this.state.currFilters) !== JSON.stringify(store.filters)) {
// I think this condition only isRemoteFilter is enough
store.filteredData = store.getAllData();
this.setState(() => ({ isDataChanged: true, currFilters: store.filters }));
} else if (isDataChanged) {
if (!(this.isRemoteFiltering() || this.isRemotePagination()) &&
Object.keys(this.state.currFilters).length > 0) {
if (!isRemoteFilter && Object.keys(this.state.currFilters).length > 0) {
store.filteredData = filters(store, columns, _)(this.state.currFilters);
}
this.setState(() => ({ isDataChanged }));
@@ -133,6 +133,25 @@ describe('Wrapper', () => {
expect(instance.state.currFilters).toBe(nextProps.store.filters);
});
});
describe('when remote filter is enabled', () => {
let props;
const nextData = [];
beforeEach(() => {
props = createTableProps({ remote: { filter: true } });
createFilterWrapper(props);
nextProps = createTableProps({ remote: { filter: true } });
nextProps.store.setAllData(nextData);
instance.componentWillReceiveProps(nextProps);
});
it('should setting states correctly', () => {
expect(nextProps.store.filteredData).toEqual(nextData);
expect(instance.state.isDataChanged).toBeTruthy();
expect(instance.state.currFilters).toBe(nextProps.store.filters);
});
});
});
describe('onFilter', () => {