-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Persist selected filters in checks results inside Redux (#1445)
Save filters in redux when filtering checks results
- Loading branch information
1 parent
5a499bf
commit e9c5856
Showing
10 changed files
with
158 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
|
||
const initialState = {}; | ||
|
||
export const checksResultsFiltersSlice = createSlice({ | ||
name: 'checksResultsFilters', | ||
initialState, | ||
reducers: { | ||
setSelectedFilters: (state, { payload: { resourceID, filters } }) => { | ||
state[resourceID] = filters; | ||
}, | ||
}, | ||
}); | ||
|
||
export const { setSelectedFilters } = checksResultsFiltersSlice.actions; | ||
|
||
export default checksResultsFiltersSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import checksResultsFiltersReducer, { | ||
setSelectedFilters, | ||
} from './checksResultsFilters'; | ||
|
||
describe('Catalog reducer', () => { | ||
it('should set catalog on loading state', () => { | ||
const initialState = {}; | ||
|
||
const resourceID = faker.datatype.uuid(); | ||
|
||
const filters = ['warning']; | ||
|
||
const action = setSelectedFilters({ resourceID, filters }); | ||
|
||
const expectedState = { | ||
[resourceID]: filters, | ||
}; | ||
|
||
expect(checksResultsFiltersReducer(initialState, action)).toEqual( | ||
expectedState | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export const getSelectedFilters = | ||
(resourceID) => | ||
({ checksResultsFilters }) => | ||
checksResultsFilters[resourceID] || []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { faker } from '@faker-js/faker'; | ||
|
||
import { getSelectedFilters } from './checksResultsFilters'; | ||
|
||
describe('getSelectedFilters', () => { | ||
it('should return an empty array if the cluster ID is not found', () => { | ||
const resourceID = faker.datatype.uuid(); | ||
|
||
expect( | ||
getSelectedFilters(resourceID)({ checksResultsFilters: {} }) | ||
).toEqual([]); | ||
}); | ||
|
||
it('should return a list of selected filters when the cluster ID is found', () => { | ||
const resourceID = faker.datatype.uuid(); | ||
const state = { | ||
checksResultsFilters: { [resourceID]: ['passing', 'critical'] }, | ||
}; | ||
|
||
expect(getSelectedFilters(resourceID)(state)).toEqual([ | ||
'passing', | ||
'critical', | ||
]); | ||
}); | ||
}); |