-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persist selected filters in checks results inside Redux #1445
Conversation
fe9e421
to
ddde3a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
Just a couple of suggestions if they help.
Additionally, as we discussed, just noting that the filter in the query string gets wiped out when navigating among the pages.
However this does not impact the feature which works just fine. I am ok with the tradeoff if it's too much of a hassle re-applying the qs when we have saved filters and we navigate back to the executions results.
@@ -4,14 +4,25 @@ import Filter from '@components/Table/Filter'; | |||
|
|||
export const RESULT_FILTER_FIELD = 'result'; | |||
|
|||
function ChecksResultFilters({ onChange }) { | |||
const getFilters = (savedFilters, searchParams) => | |||
savedFilters && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I am getting it right in the worst case savedFilters
comes as an empty array, so this initial check might be not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could come as undefined, updated it to have a default prop 👍
const getFilters = (savedFilters, searchParams) => | ||
savedFilters && | ||
savedFilters.length >= 0 && | ||
searchParams.getAll('health').length === 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could extract this searchParams.getAll('health')
outside of getFilters
function.
I am aware it wouldn't change much 😅, so not a biggie. However if you want to give it a go here's the changes it would require.
function ChecksResultFilters() {
//...
const qsFilters = searchParams.getAll('health');
useEffect(() => {
const selectedFilters = getFilters(savedFilters, qsFilters);
setFiltersForField({
//...
});
}, [searchParams, savedFilters]);
//...
return (
<div className="flex">
<Filter
//...
value={getFilters(savedFilters, qsFilters)}
/>
</div>
);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried and the component exploded in my face 😅
/> | ||
); | ||
|
||
expect(screen.getAllByText('test-cluster')).toHaveLength(2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about squashing this test and the previous one in a it.each
version with two scenarios?
One scenario that does not pass a savedFilters
(or an empty one) but it provides the route with querystring, another scenario that does provide the savedFilters
without querystring.
At the end the expectations are the same for the two tests 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it calls for too much refactor that you don't feel like addressing, keep it as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dottorblaster The code looks good.
I only commented the naming part (our beloved naming).
I think we could generalize this. We will have sooner than later checks that are not only cluster based, so what about making the state already generic?
The usage would be exactly the same, we just need to build the payload correctly, that's all.
@@ -0,0 +1,17 @@ | |||
import { createSlice } from '@reduxjs/toolkit'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rename this file to checksResultsFilters
. Surely we will want to use this for future visualizations, where we have hosts based results, but I expect the execution results view being the same, as data will be coming from wanda in the same way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right
name: 'clusterChecksResultsFilters', | ||
initialState, | ||
reducers: { | ||
setClusterFilters: (state, { payload: { clusterID, filters } }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about making this generic setChecksResultsFilters
.
Getting the { id: filters }
payload. I'm just thinking for future uses where we don't only have checks for clusters.
All of our resouces (clusters, hosts, sap systesms) are identified by uuid, so there wouldn't be any collision.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right again :D
name: 'clusterChecksResultsFilters', | ||
initialState, | ||
reducers: { | ||
setClusterFilters: (state, { payload: { clusterID, filters } }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, the code is ultra simple, but what about adding a test?
@@ -101,9 +101,11 @@ function ExecutionResults({ | |||
executionData, | |||
executionError, | |||
clusterSelectedChecks = [], | |||
savedFilters, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we maybe add an empty list as default?
To make things a bit more secure, and in fact it would even help to story book
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me check if nothing explodes, sure
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I managed to assign a default prop but I had to declare it outside the inline scope. Left a comment about that, hope it's ok
7c62a09
to
585ca15
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
528b971
to
8cc32fa
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dottorblaster It looks great!
I would simply change clusterID
by resourceID/groupID
to finish making it generic now that we changed the files/state names.
(Maybe run find all
thing in the changes hehe, as clusterID
is everywhere, specially on the tests)
@@ -0,0 +1,4 @@ | |||
export const getSelectedFilters = | |||
(clusterID) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change clusterID
by groupID/resourceID
once we started making it generic
name: 'checksResultsFilters', | ||
initialState, | ||
reducers: { | ||
setSelectedFilters: (state, { payload: { clusterID, filters } }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clusterID
by resourceID
maybe?
onStartExecution={(clusterId, hosts, selectedChecks, navigate) => | ||
dispatch(executionRequested(clusterId, hosts, selectedChecks, navigate)) | ||
} | ||
onSaveFilters={(filters) => | ||
dispatch(setSelectedFilters({ clusterID, filters })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`setSelectedFilters({ resourceID: clusterID, filters })
1d09f71
to
9190c5f
Compare
Save filters in redux when filtering checks results
9190c5f
to
a43a4ff
Compare
Saving applied filters into a redux slice so when the user comes back we just restore previously applied state
How was this tested?
Jest test added