Skip to content

fix(dashboard): pre-filter time grain for display controls#40000

Open
massucattoj wants to merge 5 commits into
apache:masterfrom
massucattoj:fix/display-control-timegrain-pre-filter
Open

fix(dashboard): pre-filter time grain for display controls#40000
massucattoj wants to merge 5 commits into
apache:masterfrom
massucattoj:fix/display-control-timegrain-pre-filter

Conversation

@massucattoj
Copy link
Copy Markdown
Contributor

SUMMARY

The "Pre-filter available values" option configured for Time Grain controls only worked when the control was created as a Native Filter. When the same control was created as a Display Control (chart
customization), the configured allowlist was silently dropped — the dashboard end user always saw all 14 time grains regardless of what the dashboard author had configured.

This regression had three root causes, all in the parallel plumbing that was added for chart customizations after the native filter pre-filter feature shipped (PR #38922):

  1. Form (author side) — The "Pre-filter available values" checkbox is rendered in FiltersConfigForm.tsx only when itemTypeField === 'filter_timegrain'. Display Controls use chart_customization_timegrain and never
    matched, so the checkbox never rendered.
  2. Save (persistence) — Even if the checkbox had rendered, customizationTransformer.transformFormInput() did not copy time_grains from the form input to the saved ChartCustomization. The native filter equivalent
    (filterTransformer.ts) already does this.
  3. Consumer (read side) — FilterValue.tsx hardcoded allowedTimeGrains = undefined for any chart customization, and applyTimeGrainAllowlist short-circuited unless filterType === 'filter_timegrain'.

The fix mirrors the existing native filter wiring across all three layers and threads the time_grains field through the supporting types (ChartCustomization, ChartCustomizationsFormItem,
PluginFilterTimeGrainCustomizeProps).

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before:
Screenshot 2026-05-10 at 13 20 13

After:
Screenshot 2026-05-10 at 13 48 20

Screenshot 2026-05-10 at 13 46 40

TESTING INSTRUCTIONS

  1. Open any dashboard and click the Filters and controls gear → Add or edit filters and controls.
  2. Click Add display control.
  3. Set:
  • Display control type: Time grain
  • Datasource: any dataset that supports time grains (e.g. birth_names)
  • Display control name: any value
  1. Expand Display control configuration. Verify the "Pre-filter available values" checkbox is present (this is the new behavior).
  2. Check the box, pick a subset of grains (e.g. Day and Week), and Save the dashboard.
  3. On the dashboard, open the new Time Grain control. Verify the dropdown shows only the configured subset.
  4. Edit the control again, leave the checkbox checked but clear all values, save. The dropdown should show all grains again (empty allowlist = no restriction, same backwards-compat behavior as the native filter).
  5. Repeat steps 1–6 with a Native Filter of type Time Grain and confirm there is no regression there.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented May 10, 2026

Code Review Agent Run #ed04e2

Actionable Suggestions - 0
Review Details
  • Files reviewed - 7 · Commit Range: 91e6027..91e6027
    • superset-frontend/packages/superset-ui-core/src/query/types/Dashboard.ts
    • superset-frontend/src/chartCustomizations/components/TimeGrain/TimeGrainFilterPlugin.tsx
    • superset-frontend/src/chartCustomizations/components/TimeGrain/types.ts
    • superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
    • superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx
    • superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/transformers/customizationTransformer.ts
    • superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/types.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot Bot added change:frontend Requires changing the frontend dashboard:native-filters Related to the native filters of the Dashboard labels May 10, 2026
@bito-code-review
Copy link
Copy Markdown
Contributor

The flagged issue is correct: applying applyTimeGrainAllowlist to chart customizations at the data-fetch layer removes selected values outside the allowlist before the plugin can preserve them, causing visibility loss in edited dashboards.

To resolve, modify the condition in applyTimeGrainAllowlist to exclude chart_customization_timegrain, keeping fetch-time filtering only for native filters.

No other comments found in the PR.

superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx

if (filterType !== 'filter_timegrain' || !allowedTimeGrains?.length) {
    return results;
  }

@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

❌ Patch coverage is 44.44444% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.22%. Comparing base (965ec47) to head (388a229).

Files with missing lines Patch % Lines
...ons/components/TimeGrain/TimeGrainFilterPlugin.tsx 0.00% 7 Missing ⚠️
...veFilters/FilterBar/FilterControls/FilterValue.tsx 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #40000      +/-   ##
==========================================
+ Coverage   64.20%   64.22%   +0.02%     
==========================================
  Files        2592     2592              
  Lines      139232   139227       -5     
  Branches    32327    32326       -1     
==========================================
+ Hits        89389    89416      +27     
+ Misses      48308    48276      -32     
  Partials     1535     1535              
Flag Coverage Δ
javascript 67.37% <44.44%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rusackas
Copy link
Copy Markdown
Member

Would love to see the bot comments addressed, and perhaps a test, so we can merge this :D

@pull-request-size pull-request-size Bot added size/L and removed size/M labels May 23, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented May 23, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit cfb6b5a
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a11d266f9f2e50008b9debb
😎 Deploy Preview https://deploy-preview-40000--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@massucattoj massucattoj requested a review from DamianPendrak May 23, 2026 16:09
Copy link
Copy Markdown
Contributor

@bito-code-review bito-code-review Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #995125

Actionable Suggestions - 1
  • superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx - 1
Review Details
  • Files reviewed - 4 · Commit Range: 91e6027..cfb6b5a
    • superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.timeGrain.test.ts
    • superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterControls/FilterValue.tsx
    • superset-frontend/src/dashboard/components/nativeFilters/FiltersConfigModal/FiltersConfigForm/FiltersConfigForm.tsx
    • superset-frontend/src/chartCustomizations/components/TimeGrain/CustomizationTimeGrainsTransformer.integration.test.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

Comment on lines 84 to 119
@@ -143,9 +114,6 @@ const FilterValue: FC<FilterValueProps> = ({
}) => {
const { id, targets, filterType } = filter;
const isCustomization = isChartCustomization(filter);
const allowedTimeGrains = isCustomization
? undefined
: (filter as TimeGrainFilterConfig).time_grains;
const adhocFilters = isCustomization ? undefined : filter.adhoc_filters;
const timeRange = isCustomization ? undefined : filter.time_range;
const granularitySqla = isCustomization ? undefined : filter.granularity_sqla;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Orphaned config with no consumer

Removed applyTimeGrainAllowlist and TimeGrainFilterConfig type, but filterTransformer.ts still persists time_grains from native filter configs into Filter.time_grains. This orphaned configuration has no consumer—users will set time_grains expecting filtered options but see all time grains instead. Either remove the configuration serialization or restore the filtering logic.

Code Review Run #995125


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

change:frontend Requires changing the frontend dashboard:native-filters Related to the native filters of the Dashboard packages size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants