Skip to content

Commit

Permalink
fix: LEAP-1409: Add preserving hidden filters during filter operations
Browse files Browse the repository at this point in the history
Ensure hidden filters are retained and correctly processed in filter-related operations. Introduced `_originalFilters` to store and manage filters not editable by the user, preventing their loss during requests.
  • Loading branch information
Gondragos committed Dec 12, 2024
1 parent bf625fc commit 3fdba42
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
10 changes: 9 additions & 1 deletion web/libs/datamanager/src/stores/Tabs/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ const dataCleanup = (tab, columnIds) => {
if (!data) return { ...tab };

if (data.filters) {
data.filters.items = data.filters.items.filter(({ filter }) => {
data._originalFilters = [];
data.filters.items = data.filters.items.filter((item) => {
const { filter } = item;
data._originalFilters.push(item);
return columnIds.includes(filter.replace(/^filter:/, ""));
});
}
Expand Down Expand Up @@ -305,11 +308,16 @@ export const TabStore = types
return view;
}
const viewSnapshot = getSnapshot(view);
let originalFilters = [];
if (result.filters) {
originalFilters = result.filters.items;
}
const newViewSnapshot = {
...viewSnapshot,
...result,
saved: true,
filters: viewSnapshot.filters,
_originalFilters: originalFilters,
conjunction: viewSnapshot.conjunction,
};

Expand Down
28 changes: 25 additions & 3 deletions web/libs/datamanager/src/stores/Tabs/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ export const Tab = types
target: types.optional(types.enumeration(["tasks", "annotations"]), "tasks"),

filters: types.array(types.late(() => TabFilter)),
// this field keeps information about hidden filters that we can't change so we do not have them in filters
// but these filters should appears on the next request affects selected filters as we do not want to loose them
_originalFilters: types.optional(types.frozen()),
conjunction: types.optional(types.enumeration(["and", "or"]), "and"),
hiddenColumns: types.maybeNull(types.optional(TabHiddenColumns, {})),
ordering: types.optional(types.array(types.string), []),
Expand Down Expand Up @@ -135,16 +138,27 @@ export const Tab = types
},

get serializedFilters() {
return self.validFilters.map((el) => {
const originalFilters = self._originalFilters ? [...self._originalFilters] : [];
return self.validFilters.reduce((acc, el) => {
const filterItem = {
...getSnapshot(el),
type: el.filter.currentType,
};

filterItem.value = normalizeFilterValue(filterItem.type, filterItem.operator, filterItem.value);

return filterItem;
});
// restoring unavailable to edit original (hidden) filters
while (originalFilters[0] && originalFilters[0].filter !== filterItem.filter) {
acc.push(originalFilters.shift());
}
// skipping duplicates
if (originalFilters[0] && originalFilters[0].filter === filterItem.filter) {
originalFilters.shift();
}

acc.push(filterItem);
return acc;
}, []);
},

get selectedCount() {
Expand Down Expand Up @@ -387,6 +401,11 @@ export const Tab = types
}),

deleteFilter(filter) {
const originalIndex = self._originalFilters.findIndex((f) => f.filter === filter.filter.id);
if (originalIndex > -1) {
self._originalFilters = self._originalFilters.filter((_item, index) => originalIndex !== index);
}

const index = self.filters.findIndex((f) => f === filter);

self.filters.splice(index, 1);
Expand Down Expand Up @@ -460,4 +479,7 @@ export const Tab = types
delete sn.selectedItems;

return sn;
})
.postProcessSnapshot(({ _originalFilters, ...snapshot }) => {
return snapshot;
});

0 comments on commit 3fdba42

Please sign in to comment.