Skip to content

Commit

Permalink
fix(SystemsTable): Fix resetting to default filters (#1985)
Browse files Browse the repository at this point in the history
* fix(SystemsTable): Remove redundant removeFilter call

* fix(SystemsTable): Do not spread current params on reset
  • Loading branch information
bastilian authored Sep 25, 2023
1 parent 0340bad commit 6201326
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/Helpers/TableToolbarHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ export const buildActiveFilters = (currentFilters, filterRuleValues = []) => {

export const removeFilters = (chips, apply, reset = false, defaultFilters = {}) => {
if (reset) {
removeFilters(chips, apply);
apply({ ...defaultFilters, page: 1 });
apply({ ...defaultFilters, page: 1, reset });
return;
}

Expand Down
10 changes: 10 additions & 0 deletions src/Helpers/TableToolbarHelper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ const mockGeneralChip = {
const mockApply = jest.fn();

describe('TableToolbarHelper', () => {
afterEach(() => {
jest.clearAllMocks();
});

it('Should handleChangePage apply with provided page', () => {
const testPage = 1;
const testApply = jest.fn();
Expand Down Expand Up @@ -149,6 +153,12 @@ describe('TableToolbarHelper', () => {
expect(mockApply).toHaveBeenCalledWith({ rule_presence: undefined, rule: '', page: 1 });
});

it('Should reset to default filters when given and reset is ture', () => {
removeFilters([mockGeneralChip], mockApply, true, { rule_presence: "true" });
expect(mockApply).toHaveBeenCalledTimes(1);
expect(mockApply).toHaveBeenCalledWith({ rule_presence: 'true', page: 1, reset: true });
});

it('Should remove search filters and multi value filters with only one value safely', () => {
const mockSingleValueChips = [
{
Expand Down
10 changes: 7 additions & 3 deletions src/Store/Reducers/SystemsPageStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ export const initialState = {
export const SystemsPageStore = (state = initialState, action) => {
let newState = { ...state };
switch (action.type) {
case ActionTypes.CHANGE_SYSTEMS_PARAMS:
case ActionTypes.CHANGE_SYSTEMS_PARAMS: {
const { reset, ...params } = action.payload;
newState.params = {
...newState.params,
...action.payload,
...!reset ? newState.params : {},
...params,
page_size: action.payload.page_size || newState.params.page_size
};

return newState;
}

case ActionTypes.CHANGE_COLUMNS_SYSTEM_LIST:
return {
...newState,
Expand Down

0 comments on commit 6201326

Please sign in to comment.