Skip to content

Commit

Permalink
Fix combining regular and advanced filters
Browse files Browse the repository at this point in the history
  • Loading branch information
ad-elias committed Oct 18, 2024
1 parent 109a283 commit cbb4b6b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export const useUpsertCombinedViewFilters = (viewBarComponentId?: string) => {
if (isDefined(matchingFilterInUnsavedFilters)) {
const updatedFilters = unsavedToUpsertViewFilters.map((viewFilter) =>
viewFilter.fieldMetadataId ===
matchingFilterInUnsavedFilters.fieldMetadataId
matchingFilterInUnsavedFilters.fieldMetadataId &&
!viewFilter.viewFilterGroupId
? { ...viewFilter, ...upsertedFilter, id: viewFilter.id }
: viewFilter,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,19 @@ export const getCombinedViewFilters = (
const toCreateViewFilters = toUpsertViewFilters.filter(
(toUpsertViewFilter) =>
!viewFilters.some(
(viewFilter) =>
viewFilter.fieldMetadataId === toUpsertViewFilter.fieldMetadataId,
(viewFilter) => viewFilter.id === toUpsertViewFilter.id,
),
);

const toUpdateViewFilters = toUpsertViewFilters.filter((toUpsertViewFilter) =>
viewFilters.some(
(viewFilter) =>
viewFilter.fieldMetadataId === toUpsertViewFilter.fieldMetadataId,
),
viewFilters.some((viewFilter) => viewFilter.id === toUpsertViewFilter.id),
);

const combinedViewFilters = viewFilters
.filter((viewFilter) => !toDeleteViewFilterIds.includes(viewFilter.id))
.map((viewFilter) => {
const toUpdateViewFilter = toUpdateViewFilters.find(
(toUpdateViewFilter) =>
toUpdateViewFilter.fieldMetadataId === viewFilter.fieldMetadataId,
(toUpdateViewFilter) => toUpdateViewFilter.id === viewFilter.id,
);

return toUpdateViewFilter ?? viewFilter;
Expand Down

0 comments on commit cbb4b6b

Please sign in to comment.