Skip to content

Commit

Permalink
Store only persistent filters
Browse files Browse the repository at this point in the history
Signed-off-by: yaacov <[email protected]>
  • Loading branch information
yaacov committed Jul 18, 2024
1 parent 459ad42 commit d22ce27
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion packages/common/src/components/FilterGroup/useUrlFilters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,15 @@ function convertFiltersToSearchParams(fields, filters) {
* @returns {Function} - The function to set state and update URL.
*/
function createSetStateAndUrl(setSelectedFilters, updateSearchParams, updateUserSettings, fields) {
const persistentFieldIds = fields.filter((f) => f?.isPersistent).map((f) => f.resourceFieldId);

return (filters) => {
if (updateUserSettings) {
updateUserSettings(filters);
const persistentFilters = Object.fromEntries(
Object.entries(filters || {}).filter(([key]) => persistentFieldIds.includes(key)),
);

updateUserSettings(persistentFilters);
}
setSelectedFilters(filters);
updateSearchParams(convertFiltersToSearchParams(fields, filters));
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/components/Page/userSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const sanitizeFields = (fields: unknown): { resourceFieldId: string; isVisible?:
* @param pageId key suffix - together with PLUGIN_NAME used to load/save data.
*/
export const loadUserSettings = ({ pageId }): UserSettings => {
const key = `${process.env.PLUGIN_NAME}-${pageId}`;
const key = `${process.env.PLUGIN_NAME}/${pageId}`;
const { fields, perPage, filters } = parseOrClean(key);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const saveRestOrRemoveKey = (key: string, { rest }: { [k: string]: { [n: string]
* @param userSettingsKeySuffix - The key name together with PLUGIN_NAME used to load/save data.
*/
export const loadUserSettings = ({ userSettingsKeySuffix }): OverviewUserSettings => {
const key = `${process.env.PLUGIN_NAME}-${userSettingsKeySuffix}`;
const key = `${process.env.PLUGIN_NAME}/${userSettingsKeySuffix}`;
const { hideWelcome } = parseOrClean(key);

return {
Expand Down

0 comments on commit d22ce27

Please sign in to comment.