Am creating the PR at this stage.. there is more refactoring to do, but I want to reduce the number of files in the PR 😉
This one is the essence of the change - the next steps are:
replicate these changes across all usages of useQueryParams
remove the hooks useFilterByuseSortBy & usePagination
rework existing tests
The core of the problem is that the current hooks aren't sharing state.. so a list of items is retrieved by two separate calls, and each has different query params, though the code is expecting to see the same list of results.
I've lifted the queryParams state out, so it is created in the page context. Almost always, this is within the table context, so have created a query params context which is instantiated by the table context. For the cases where the queryParams are used outside of the table context (Name search is one) then the query params context can be instantiated separately.
Fixes #1204
Am creating the PR at this stage.. there is more refactoring to do, but I want to reduce the number of files in the PR 😉 This one is the essence of the change - the next steps are:
useQueryParams
useFilterBy
useSortBy
&usePagination
The core of the problem is that the current hooks aren't sharing state.. so a list of items is retrieved by two separate calls, and each has different query params, though the code is expecting to see the same list of results.
I've lifted the queryParams state out, so it is created in the page context. Almost always, this is within the table context, so have created a query params context which is instantiated by the table context. For the cases where the queryParams are used outside of the table context (Name search is one) then the query params context can be instantiated separately.
Will also replace the
useSharedSort
implementation required by this PR: https://github.com/openmsupply/openmsupply-client/pull/1017 as I expect that won't be needed now.