Add pre-filter option to Time Grain dashboard control - #42849
Conversation
|
Bito Review Skipped - Source Branch Not Found |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #42849 +/- ##
=======================================
Coverage 65.73% 65.73%
=======================================
Files 2843 2843
Lines 162659 162677 +18
Branches 37239 37244 +5
=======================================
+ Hits 106921 106939 +18
- Misses 53645 53646 +1
+ Partials 2093 2092 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Code Review Agent Run #23ff5fActionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
Title: feat(dashboard): add per-dashboard time grain allowlist via
time_grain_allowlistin JSON metadataDescription:
This MR introduces the ability to restrict available time grains at the dashboard level by adding a
time_grain_allowlistfield to the dashboard JSON metadata. When set, all Time Grain native filters on that dashboard will only display the specified time grains, regardless of what the underlying datasource provides.Motivation
Currently, Superset allows global time grain restrictions via
TIME_GRAIN_DENYLISTinsuperset_config.py, but there is no way to limit time grains per dashboard. Users have requested the ability to show different time grain options on different dashboards (e.g., hourly/monthly on Dashboard A, monthly/yearly on Dashboard B) without manually editing each filter's settings.Changes
1. Backend —
superset/dashboards/schemas.pytime_grain_allowlisttoDashboardJSONMetadataSchemaas aList(Str)field withallow_none=True.PUT /api/v1/dashboard/{id}) to accept and validate the new field injson_metadatawithout throwing"Unknown field.".2. Frontend —
TimeGrainFilterPlugin.tsxdashboardInfo.metadata.time_grain_allowlistfrom the Redux store viaReactReduxContext(safe for plugin context whereuseSelectormay fail).optionsbased on the dashboard allowlist. Priority:time_grain_allowlisttimeGrains(existing behavior)useRef(hasInitRef) to applydefaultValueexactly once afteroptionsare ready, preventing race conditions and "Cannot load filter" errors on initial render.validValueis computed directly fromfilterState.valueintersected withoptions, ensuring theSelectcomponent never receives a value that does not exist in its option list.Usage
Edit a dashboard → Edit properties → Advanced → JSON Metadata:
{ "time_grain_allowlist": ["PT1H", "P1M"], "native_filter_configuration": [ ... ] }All Time Grain filters on this dashboard will now show only Hour and Month.
Supported values
PT1SPT1MPT5MPT10MPT15MPT30MPT1HP1DP1WP1W/1970-01-05T00:00:00Z1969-12-29T00:00:00Z/P1WP1MP3MP1YBackward compatibility
time_grain_allowlistis absent from dashboard metadata, behavior is unchanged.[], all time grains are shown (same as no restriction).Testing
PUT /api/v1/dashboard/{id}acceptsjson_metadatawithtime_grain_allowlist.time_grain_allowlistis set.time_grain_allowlistis absent.