codeant-ai-for-open-source[bot] commented on code in PR #40000:
URL: https://github.com/apache/superset/pull/40000#discussion_r3215202298
##########
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx:
##########
@@ -93,7 +93,11 @@ export const applyTimeGrainAllowlist = (
allowedTimeGrains: string[] | undefined,
results: ChartDataResponseResult[],
): ChartDataResponseResult[] => {
- if (filterType !== 'filter_timegrain' || !allowedTimeGrains?.length) {
+ if (
+ (filterType !== 'filter_timegrain' &&
+ filterType !== 'chart_customization_timegrain') ||
+ !allowedTimeGrains?.length
+ ) {
Review Comment:
**Suggestion:** Applying `applyTimeGrainAllowlist` to chart customizations
at the data-fetch layer drops any currently selected value that is outside the
configured allowlist before it reaches the plugin. The time-grain plugin is
explicitly designed to keep the current selection visible
(`allowlist.includes(...) || value.includes(...)`), but this pre-filter removes
those rows too early, so edited dashboards can lose visibility of existing
selections. Keep fetch-time filtering only for native timegrain filters (or
move this logic entirely to plugin rendering for customizations). [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Chart customization timegrain dropdown hides previously selected grains.
- ⚠️ Dashboard editors may unknowingly drop existing timegrain selections.
- ⚠️ Inconsistent behavior between native and customization timegrain
controls.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Configure a chart customization time grain control so its `filterType` is
`chart_customization_timegrain` and it has a `time_grains` allowlist (e.g.
`['PT1H',
'P1D']`). At runtime this configuration is passed into `FilterValue` via the
`filter` prop
in `FilterValue.tsx:134-151`, where `isCustomization` is true and
`allowedTimeGrains` is
read from `(filter as TimeGrainFilterConfig).time_grains` at
`FilterValue.tsx:148-151`.
2. Ensure the chart customization's current saved selection (from
`filter.dataMask` /
`filterState.value`) includes at least one duration that is *not* in the
configured
allowlist, for example `P1W`. The backend still returns all available time
grains for the
dataset, including `P1W`, in the chart data response consumed by
`FilterValue` via
`getChartDataRequest` in the `useEffect` starting around
`FilterValue.tsx:210-224`.
3. When `getChartDataRequest` resolves, `FilterValue` sets local state by
calling
`setState(applyTimeGrainAllowlist(filterType, allowedTimeGrains, ...))` at
`FilterValue.tsx:286-325`. Because `filterType ===
'chart_customization_timegrain'` and
`allowedTimeGrains` is non-empty, `applyTimeGrainAllowlist` at
`FilterValue.tsx:91-118`
filters `result.data` to only rows whose `duration` is in the allowlist,
removing any rows
for `P1W` and other disallowed durations *before* they reach the plugin.
4. The chart customization time grain plugin (`TimeGrainFilterPlugin`) then
builds its
`options` from the filtered `data` and applies its own allowlist filter with
selection-preservation in
`chartCustomizations/components/TimeGrain/TimeGrainFilterPlugin.tsx:122-129`,
where it
intends to keep the current value visible via
`allowlist.includes(option.value) ||
value.includes(option.value)`. However, because the `P1W` row was already
removed by
`applyTimeGrainAllowlist`, no option is created for `P1W`, so the plugin
cannot preserve
or display that selected value. As a result, an edited dashboard with a chart
customization timegrain control and a disallowed-but-previously-selected
value will lose
visibility of that selection in the dropdown.
```
</details>
[Fix in
Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2Fdashboard%2Fcomponents%2FnativeFilters%2FFilterBar%2FFilterControls%2FFilterValue.tsx%0A%2A%2ALine%3A%2A%2A%2096%3A100%0A%2A%2AComment%3A%2A%2A%0A%09%2ALogic%20Error%3A%20Applying%20%60applyTimeGrainAllowlist%60%20to%20chart%20customizations%20at%20the%20data-fetch%20layer%20drops%20any%20currently%20selected%20value%20that%20is%20outside%20the%20configured%20allowlist%20before%20it%20reaches%20the%20plugin.%20The%20time-grain%20plugin%20is%20explicitly%20designed%20to%20keep%20the%20current%20selection%20visible%20%28%60allowlist.includes%28...%29%20%7C%7C%20value.includes%28...%29%60%29%2C%20but%20this%20pre-filter%20removes%20those%20rows%20too%20early%2C%20so%20edited%20dashboards%20can%20lose%20visibility%20of%20existing%20selections.%20Keep%20fetch-time%20filtering%20only%20for%20native%20timegr
ain%20filters%20%28or%20move%20this%20logic%20entirely%20to%20plugin%20rendering%20for%20customizations%29.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
| [Fix in VSCode
Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20a%20comment%20left%20during%20a%20code%20review.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fsrc%2Fdashboard%2Fcomponents%2FnativeFilters%2FFilterBar%2FFilterControls%2FFilterValue.tsx%0A%2A%2ALine%3A%2A%2A%2096%3A100%0A%2A%2AComment%3A%2A%2A%0A%09%2A
Logic%20Error%3A%20Applying%20%60applyTimeGrainAllowlist%60%20to%20chart%20customizations%20at%20the%20data-fetch%20layer%20drops%20any%20currently%20selected%20value%20that%20is%20outside%20the%20configured%20allowlist%20before%20it%20reaches%20the%20plugin.%20The%20time-grain%20plugin%20is%20explicitly%20designed%20to%20keep%20the%20current%20selection%20visible%20%28%60allowlist.includes%28...%29%20%7C%7C%20value.includes%28...%29%60%29%2C%20but%20this%20pre-filter%20removes%20those%20rows%20too%20early%2C%20so%20edited%20dashboards%20can%20lose%20visibility%20of%20existing%20selections.%20Keep%20fetch-time%20filtering%20only%20for%20native%20timegrain%20filters%20%28or%20move%20this%20logic%20entirely%20to%20plugin%20rendering%20for%20customizations%29.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AOnce%20fix%20is%20im
plemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
**Line:** 96:100
**Comment:**
*Logic Error: Applying `applyTimeGrainAllowlist` to chart
customizations at the data-fetch layer drops any currently selected value that
is outside the configured allowlist before it reaches the plugin. The
time-grain plugin is explicitly designed to keep the current selection visible
(`allowlist.includes(...) || value.includes(...)`), but this pre-filter removes
those rows too early, so edited dashboards can lose visibility of existing
selections. Keep fetch-time filtering only for native timegrain filters (or
move this logic entirely to plugin rendering for customizations).
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40000&comment_hash=4fbc13c7c03d8b82f4b7207d66ea0fa0dc0cbae4c1ccc83007ca679176b83f8d&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40000&comment_hash=4fbc13c7c03d8b82f4b7207d66ea0fa0dc0cbae4c1ccc83007ca679176b83f8d&reaction=dislike'>👎</a>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]