Skip to content
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

fix: LEAP-1409: Add preserving hidden filters during filter operations #6782

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});
Loading