due to container will always set source data via store.setAllData so that handle the filtered data in the filter wrapper

This commit is contained in:
AllenFang 2018-01-21 15:44:11 +08:00
parent 79d5a51a39
commit a2d082babf
2 changed files with 6 additions and 1 deletions

View File

@ -24,6 +24,7 @@ export default (Base, {
componentWillReceiveProps({ isDataChanged, store, columns }) {
// consider to use lodash.isEqual
if (JSON.stringify(this.state.currFilters) !== JSON.stringify(store.filters)) {
store.filteredData = store.getAllData();
this.setState(() => ({ isDataChanged: true, currFilters: store.filters }));
} else if (isDataChanged) {
if (!(this.isRemoteFiltering() || this.isRemotePagination()) &&

View File

@ -106,7 +106,7 @@ describe('Wrapper', () => {
});
});
describe('when props.isDataChanged is true and remote is enable', () => {
describe('when props.isDataChanged is true', () => {
beforeEach(() => {
nextProps = createTableProps({ isDataChanged: true });
instance.componentWillReceiveProps(nextProps);
@ -118,13 +118,17 @@ describe('Wrapper', () => {
});
describe('when props.store.filters is different from current state.currFilters', () => {
const nextData = [];
beforeEach(() => {
nextProps = createTableProps();
nextProps.store.filters = { price: { filterVal: 20, filterType: FILTER_TYPE.TEXT } };
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);
});