Add element not found for deleted generic filter #3767
Add element not found for deleted generic filter #3767ghazwarhili wants to merge 29 commits intomainfrom
Conversation
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-autocomplete.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
src/components/results/common/global-filter/global-filter-provider.tsx
Outdated
Show resolved
Hide resolved
…neric-filter-deleted' into add-element-not-found-case-of-generic-filter-deleted
…neric-filter-deleted' into add-element-not-found-case-of-generic-filter-deleted
📝 WalkthroughWalkthroughProvider now marks missing generic global filters with a Changes
Sequence DiagramsequenceDiagram
participant Provider as global-filter-provider
participant Backend as Backend API
participant Store as Redux Store
participant UI as Chip Components
rect rgba(100,150,200,0.5)
Note over Provider,UI: Batch fetching and marking missing filters deleted
end
Provider->>Backend: Fetch generic filter(s) (parallel)
Backend-->>Provider: 404 Not Found
Provider->>Store: Dispatch addToGlobalFilterOptions([{...genericFilter, deleted: true}], tableType, tableUuid)
Store-->>UI: State updated with deleted flag
UI->>UI: getResultsGlobalFiltersChipStyle(element)
alt element.deleted == true
UI->>UI: Apply resultsGlobalFilterStyles.chipNotFound
else
UI->>UI: Apply style from FILTER_TYPE_STYLE_MAP
end
UI-->>Provider: Render chips with updated styles/labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/redux/globalFiltersMiddleware.ts`:
- Around line 37-47: The switch case handling ADD_GLOBAL_FILTERS /
ADD_TO_GLOBAL_FILTER_OPTIONS / REMOVE_GLOBAL_FILTERS / CLEAR_GLOBAL_FILTERS uses
index = tableId ?? tableType and proceeds to schedule backend syncs and call
setComputationResultGlobalFilters, markEditingGlobalFilter,
unmarkEditingGlobalFilter even when index is undefined; add an early guard in
that switch block (inside the case handling these action types in
globalFiltersMiddleware) that checks if tableType and tableId are both missing
(index == null/undefined) and if so skip the backend sync/marking logic and
simply continue (e.g., return next(action) or break), preventing calls to
setComputationResultGlobalFilters(studyUuid, undefined, ...), creation of
debouncedSyncTimers["undefined"], and
markEditingGlobalFilter/unmarkEditingGlobalFilter with undefined keys.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fe9636de-2741-4ba9-b9f1-29ab289bdc03
📒 Files selected for processing (8)
src/components/results/common/global-filter/global-filter-autocomplete.tsxsrc/components/results/common/global-filter/global-filter-provider.tsxsrc/components/results/common/global-filter/global-filter-styles.tssrc/components/results/common/global-filter/global-filter-types.tssrc/components/results/common/global-filter/global-filter-utils.tssrc/components/results/common/global-filter/selected-global-filters.tsxsrc/redux/actions.tssrc/redux/globalFiltersMiddleware.ts
| const filteredOptions = options | ||
| // Allows to find the translated countries (and not their countryCodes) when the user inputs a search value | ||
| .filter((option: GlobalFilter) => { | ||
| if (option.deleted) return false; |
There was a problem hiding this comment.
As described in the comment :
// Filter / sort the options 'on the fly' based on the user's search input value and the category he selected (country, voltage level, recent...)
Deleted filters should not appear whatever the input or the category.
So this code should be in the use memo below.
There was a problem hiding this comment.
I totally agree
fixed
| if (path !== genericFilter.path || label !== genericFilter.label) { | ||
| dispatch( | ||
| addToGlobalFilterOptions( | ||
| [{ ...genericFilter, path: path, label: label ?? genericFilter.label }], |
There was a problem hiding this comment.
This code is problematic if label is undefined. I don't remember why we have this line ?
There was a problem hiding this comment.
because the find + optional chaining (?.)
if find doesn’t locate anything, it returns undefined
So this becomes: undefined?.elementName => label = undefined
fixed by
const label = response.find((parent) => parent.type === ElementType.FILTER)?.elementName ?? genericFilter.label;
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/components/results/common/global-filter/global-filter-provider.tsx (1)
100-100: Update the comment to reflect current behavior.The comment says "remove them if they do not exist anymore" but the implementation now marks filters with
deleted: trueinstead of removing them. This allows users to see "element not found" in the UI.📝 Suggested comment update
- // Check the selected global filters and remove them if they do not exist anymore. + // Check the selected global filters and mark them as deleted if they no longer exist.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/components/results/common/global-filter/global-filter-provider.tsx` at line 100, Update the inline comment that currently reads "remove them if they do not exist anymore" to reflect the current behavior: instead of removing missing filters the code marks them with deleted: true so they remain visible in the UI as "element not found"; change the comment near the filtering logic in global-filter-provider.tsx (the check that processes selected global filters) to explicitly state that missing filters are flagged with deleted: true rather than removed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/components/results/common/global-filter/global-filter-provider.tsx`:
- Line 100: Update the inline comment that currently reads "remove them if they
do not exist anymore" to reflect the current behavior: instead of removing
missing filters the code marks them with deleted: true so they remain visible in
the UI as "element not found"; change the comment near the filtering logic in
global-filter-provider.tsx (the check that processes selected global filters) to
explicitly state that missing filters are flagged with deleted: true rather than
removed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 023b92bc-7271-4dd0-8c50-ae3665d14c50
📒 Files selected for processing (2)
src/components/results/common/global-filter/global-filter-autocomplete.tsxsrc/components/results/common/global-filter/global-filter-provider.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
- src/components/results/common/global-filter/global-filter-autocomplete.tsx
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/redux/globalFiltersMiddleware.ts (1)
58-70:⚠️ Potential issue | 🟠 MajorDeleted filters can still be persisted via the selected list.
Line 69 excludes deleted filters only from
recentGlobalFilters, but Line 58 still includes deleted entries inselectedGlobalFilters. If a deleted generic filter is still selected, it can still be sent inglobalFiltersand re-saved server-side.💡 Proposed fix
- const selectedGlobalFilters = state.globalFilterOptions.filter((filter) => - selectedFiltersIds.includes(filter.id) - ); + const selectedGlobalFilters = state.globalFilterOptions.filter( + (filter) => selectedFiltersIds.includes(filter.id) && !filter.deleted + );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/redux/globalFiltersMiddleware.ts` around lines 58 - 70, selectedGlobalFilters currently includes entries from state.globalFilterOptions without excluding deleted filters, so deleted global filters can be sent back; update the selection logic in the selectedGlobalFilters computation (the filter over state.globalFilterOptions that uses selectedFiltersIds) to also exclude options where opt.deleted is true (consistent with the recentGlobalFilters check), ensuring both selectedGlobalFilters and recentGlobalFilters only contribute non-deleted entries to globalFilters.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@src/redux/globalFiltersMiddleware.ts`:
- Around line 58-70: selectedGlobalFilters currently includes entries from
state.globalFilterOptions without excluding deleted filters, so deleted global
filters can be sent back; update the selection logic in the
selectedGlobalFilters computation (the filter over state.globalFilterOptions
that uses selectedFiltersIds) to also exclude options where opt.deleted is true
(consistent with the recentGlobalFilters check), ensuring both
selectedGlobalFilters and recentGlobalFilters only contribute non-deleted
entries to globalFilters.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7f2ce882-fcb4-4081-a8af-922816065ce5
📒 Files selected for processing (1)
src/redux/globalFiltersMiddleware.ts
|






PR Summary
Add 'Element Not Found' for deleted generic filter