You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "sonfire186 (via GitHub)" <gi...@apache.org> on 2026/08/06 15:34:26 UTC
[PR] Add pre-filter option to Time Grain dashboard control [superset]
sonfire186 opened a new pull request, #42849:
URL: https://github.com/apache/superset/pull/42849
**Title:** feat(dashboard): add per-dashboard time grain allowlist via `time_grain_allowlist` in JSON metadata
**Description:**
This MR introduces the ability to restrict available time grains at the **dashboard level** by adding a `time_grain_allowlist` field 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_DENYLIST` in `superset_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.py`
- Added `time_grain_allowlist` to `DashboardJSONMetadataSchema` as a `List(Str)` field with `allow_none=True`.
- This allows the dashboard API (`PUT /api/v1/dashboard/{id}`) to accept and validate the new field in `json_metadata` without throwing `"Unknown field."`.
#### 2. Frontend — `TimeGrainFilterPlugin.tsx`
- Reads `dashboardInfo.metadata.time_grain_allowlist` from the Redux store via `ReactReduxContext` (safe for plugin context where `useSelector` may fail).
- Filters `options` based on the dashboard allowlist. Priority:
1. Dashboard `time_grain_allowlist`
2. Filter-level `timeGrains` (existing behavior)
3. All datasource time grains (fallback)
- Uses `useRef` (`hasInitRef`) to apply `defaultValue` exactly once after `options` are ready, preventing race conditions and "Cannot load filter" errors on initial render.
- `validValue` is computed directly from `filterState.value` intersected with `options`, ensuring the `Select` component never receives a value that does not exist in its option list.
### Usage
Edit a dashboard → **Edit properties** → **Advanced** → **JSON Metadata**:
```json
{
"time_grain_allowlist": ["PT1H", "P1M"],
"native_filter_configuration": [ ... ]
}
```
All Time Grain filters on this dashboard will now show only **Hour** and **Month**.
### Supported values
| Value | Label |
|-------|-------|
| `PT1S` | Second |
| `PT1M` | Minute |
| `PT5M` | 5 Minutes |
| `PT10M` | 10 Minutes |
| `PT15M` | 15 Minutes |
| `PT30M` | 30 Minutes |
| `PT1H` | Hour |
| `P1D` | Day |
| `P1W` | Week |
| `P1W/1970-01-05T00:00:00Z` | Week starting Monday |
| `1969-12-29T00:00:00Z/P1W` | Week ending Sunday |
| `P1M` | Month |
| `P3M` | Quarter |
| `P1Y` | Year |
### Backward compatibility
- If `time_grain_allowlist` is absent from dashboard metadata, behavior is unchanged.
- If present but empty `[]`, all time grains are shown (same as no restriction).
### Testing
- [ ] Verify `PUT /api/v1/dashboard/{id}` accepts `json_metadata` with `time_grain_allowlist`.
- [ ] Verify Time Grain filter shows only allowed grains when `time_grain_allowlist` is set.
- [ ] Verify filter works normally when `time_grain_allowlist` is absent.
- [ ] Verify no "Cannot load filter" error on first dashboard load with default value.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5207008248
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5208381212
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5207128729
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/42849?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 56.18%. Comparing base ([`ea8fa58`](https://app.codecov.io/gh/apache/superset/commit/ea8fa58158a9a3b321d1d35a36e2452137d06d8c?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`5441107`](https://app.codecov.io/gh/apache/superset/commit/54411070a0d3504ee778b721a2ded5bbf028652e?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
> :exclamation: There is a different number of reports uploaded between BASE (ea8fa58) and HEAD (5441107). Click for more details.
>
> <details><summary>HEAD has 4 uploads less than BASE</summary>
>
>| Flag | BASE (ea8fa58) | HEAD (5441107) |
>|------|------|------|
>|python|6|2|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #42849 +/- ##
==========================================
- Coverage 65.73% 56.18% -9.56%
==========================================
Files 2843 2843
Lines 162659 162639 -20
Branches 37239 37232 -7
==========================================
- Hits 106921 91372 -15549
- Misses 53645 70424 +16779
+ Partials 2093 843 -1250
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/42849/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/42849/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `37.96% <100.00%> (+<0.01%)` | :arrow_up: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/42849/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/42849/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/42849/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.87% <100.00%> (+<0.01%)` | :arrow_up: |
| [python](https://app.codecov.io/gh/apache/superset/pull/42849/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.92% <100.00%> (-19.29%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/42849/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit](https://app.codecov.io/gh/apache/superset/pull/42849/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/42849?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5763332145
Heads up, the PR title itself doesn't match the required conventional-commit format (that's why lint-check is red) — needs to start with something like `feat(dashboard):`. And lint-frontend's still failing on the same TS error I flagged before, dashboardTimeGrainAllowlist.length possibly undefined on line 122 — looks like the oxfmt commit only reformatted, didn't touch that. Still curious about the useSelector question above and why this needs a separate allowlist mechanism instead of extending the per-filter one; happy to fix the title/lint myself if you'd rather focus on that design question.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5563833802
Interesting idea for scoping time grains per dashboard. One thing I'd want changed before this goes further: pulling dashboardInfo.metadata straight out of useContext(ReactReduxContext) + store.getState() instead of useSelector means this won't re-render when that state changes elsewhere, and it's inconsistent with how every other component in `dashboard/` reads Redux state. Worth switching to useSelector like the rest of the codebase. Separately, the branch has conflicts now and lint/pre-commit/docker-build are red, so it'll need a rebase and a clean CI run too.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5647690067
Thanks for tackling this! A dashboard-level time grain allowlist is a nice addition on top of the per-filter one.
CI's failing on a real TS error though: `dashboardTimeGrainAllowlist.length` on line 114 needs a null check since `time_grain_allowlist` is optional in the schema. Once that's fixed and the pipeline's green I'll take another look.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #42849:
URL: https://github.com/apache/superset/pull/42849#discussion_r3730200980
##########
superset-frontend/src/filters/components/TimeGrain/TimeGrainFilterPlugin.tsx:
##########
@@ -50,6 +51,11 @@ export default function PluginFilterTimegrain(
} = props;
const { defaultValue } = formData;
+ const reduxContext = useContext(ReactReduxContext);
+ const dashboardTimeGrainAllowlist: string[] | undefined =
+ reduxContext?.store?.getState?.()?.dashboardInfo?.metadata
+ ?.time_grain_allowlist;
Review Comment:
**Suggestion:** The component reads Redux state imperatively through `getState()` but never subscribes to store updates. If the filter mounts before dashboard hydration, or the metadata changes while the dashboard is open, this component will not rerender for the new allowlist and will continue displaying the fallback options. Read this value through a Redux subscription such as `useSelector`, or otherwise trigger a rerender when dashboard metadata changes. [stale reference]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ⚠️ Dashboard metadata changes do not update mounted time-grain filters.
- ⚠️ Users may see options inconsistent with saved dashboard configuration.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9d2bc3b5d38041288a024d7533407e2b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9d2bc3b5d38041288a024d7533407e2b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(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/filters/components/TimeGrain/TimeGrainFilterPlugin.tsx
**Line:** 54:57
**Comment:**
*Stale Reference: The component reads Redux state imperatively through `getState()` but never subscribes to store updates. If the filter mounts before dashboard hydration, or the metadata changes while the dashboard is open, this component will not rerender for the new allowlist and will continue displaying the fallback options. Read this value through a Redux subscription such as `useSelector`, or otherwise trigger a rerender when dashboard metadata changes.
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%2F42849&comment_hash=b1873f2ccd2dfc1892947d27da243eae78cd8a1e399f03584888d9a00b45456f&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42849&comment_hash=b1873f2ccd2dfc1892947d27da243eae78cd8a1e399f03584888d9a00b45456f&reaction=dislike'>👎</a>
##########
superset-frontend/src/filters/components/TimeGrain/TimeGrainFilterPlugin.tsx:
##########
@@ -101,22 +104,51 @@ export default function PluginFilterTimegrain(
);
}
- const options = (data || [])
- .map((row: { name: string; duration: string }) => {
- const { name, duration } = row;
- return {
- label: name,
- value: duration,
- };
- })
- // Apply allowlist filter if timeGrains is configured, but keep current selection visible
- .filter(option => {
- const allowlist = formData.timeGrains;
- if (!allowlist || allowlist.length === 0) {
- return true;
- }
- return allowlist.includes(option.value) || value.includes(option.value);
- });
+ const options = useMemo(() => {
+ const allOptions = (data || [])
+ .map((row: { name: string; duration: string }) => {
+ const { name, duration } = row;
+ return {
+ label: name,
+ value: duration,
+ };
+ });
+
+ const allowlist =
+ dashboardTimeGrainAllowlist?.length > 0
+ ? dashboardTimeGrainAllowlist
+ : formData.timeGrains;
+
+ if (!allowlist || allowlist.length === 0) {
+ return allOptions;
+ }
+
+ const allowedSet = new Set(allowlist);
+ return allOptions.filter(option => allowedSet.has(option.value));
+ }, [data, dashboardTimeGrainAllowlist, formData.timeGrains]);
+
+ const validValue = useMemo(() => {
+ if (options.length === 0) return [];
+ const optionValues = new Set(options.map(o => o.value));
+ return value.filter(v => optionValues.has(v));
+ }, [value, options]);
Review Comment:
**Suggestion:** Filtering the controlled `Select` value removes any currently active grain that is outside the new allowlist without clearing the corresponding `filterState` or data mask. The backend can therefore continue querying with a grain that is invisible in the control, leaving the user unable to see or clear the active selection. Preserve the active value in the displayed options, or explicitly clear and publish the invalid selection when the allowlist changes. [api mismatch]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Native filter can query using an invisible time grain.
- ⚠️ Users cannot clear excluded active selections through the control.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=2e05bacbd2774a8da42df8d106e3d188&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=2e05bacbd2774a8da42df8d106e3d188&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(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/filters/components/TimeGrain/TimeGrainFilterPlugin.tsx
**Line:** 130:134
**Comment:**
*Api Mismatch: Filtering the controlled `Select` value removes any currently active grain that is outside the new allowlist without clearing the corresponding `filterState` or data mask. The backend can therefore continue querying with a grain that is invisible in the control, leaving the user unable to see or clear the active selection. Preserve the active value in the displayed options, or explicitly clear and publish the invalid selection when the allowlist changes.
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%2F42849&comment_hash=f42fd66077e140fe19a2cdad232545677b8c369bae4c5702fe4583402b19ffae&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42849&comment_hash=f42fd66077e140fe19a2cdad232545677b8c369bae4c5702fe4583402b19ffae&reaction=dislike'>👎</a>
##########
superset-frontend/src/filters/components/TimeGrain/TimeGrainFilterPlugin.tsx:
##########
@@ -101,22 +104,51 @@ export default function PluginFilterTimegrain(
);
}
- const options = (data || [])
- .map((row: { name: string; duration: string }) => {
- const { name, duration } = row;
- return {
- label: name,
- value: duration,
- };
- })
- // Apply allowlist filter if timeGrains is configured, but keep current selection visible
- .filter(option => {
- const allowlist = formData.timeGrains;
- if (!allowlist || allowlist.length === 0) {
- return true;
- }
- return allowlist.includes(option.value) || value.includes(option.value);
- });
+ const options = useMemo(() => {
+ const allOptions = (data || [])
+ .map((row: { name: string; duration: string }) => {
+ const { name, duration } = row;
+ return {
+ label: name,
+ value: duration,
+ };
+ });
+
+ const allowlist =
+ dashboardTimeGrainAllowlist?.length > 0
+ ? dashboardTimeGrainAllowlist
+ : formData.timeGrains;
+
+ if (!allowlist || allowlist.length === 0) {
+ return allOptions;
+ }
+
+ const allowedSet = new Set(allowlist);
+ return allOptions.filter(option => allowedSet.has(option.value));
+ }, [data, dashboardTimeGrainAllowlist, formData.timeGrains]);
+
+ const validValue = useMemo(() => {
+ if (options.length === 0) return [];
+ const optionValues = new Set(options.map(o => o.value));
+ return value.filter(v => optionValues.has(v));
+ }, [value, options]);
+
+ const hasInitRef = useRef(false);
+ useEffect(() => {
+ if (hasInitRef.current) return;
+ if (options.length === 0) return;
+
+ const optionValues = new Set(options.map(o => o.value));
+ const target = ensureIsArray<string>(defaultValue).filter(v =>
+ optionValues.has(v),
+ );
+
+ hasInitRef.current = true;
+
+ if (target.length > 0) {
+ handleChange(target);
Review Comment:
**Suggestion:** The one-shot initialization runs after the effect that applies `filterState.value`, so when options become available it unconditionally replaces an already-restored or user-selected value with `defaultValue`. This can overwrite the active dashboard filter during asynchronous data or dashboard hydration. Only apply the default when there is no current filter-state value, or give the restored filter state precedence. [logic error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Restored native-filter selections can be replaced on data arrival.
- ⚠️ Dashboard filter state and visible selection become incorrect.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c9d99cd65ac640f89789b7fc7b890f1c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c9d99cd65ac640f89789b7fc7b890f1c&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(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/filters/components/TimeGrain/TimeGrainFilterPlugin.tsx
**Line:** 141:149
**Comment:**
*Logic Error: The one-shot initialization runs after the effect that applies `filterState.value`, so when options become available it unconditionally replaces an already-restored or user-selected value with `defaultValue`. This can overwrite the active dashboard filter during asynchronous data or dashboard hydration. Only apply the default when there is no current filter-state value, or give the restored filter state precedence.
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%2F42849&comment_hash=eb58458d3ba3f1834ddea7389cc869422c667c7c8e725d57e85dbca9e208f551&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F42849&comment_hash=eb58458d3ba3f1834ddea7389cc869422c667c7c8e725d57e85dbca9e208f551&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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard): add pre-filter option to Time Grain dashboard control [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5765934953
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - 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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard): add pre-filter option to Time Grain dashboard control [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5763539727
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | 939f6058bee4c2582e719ef4ea2113ed1a797ebb |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6ab154a57c00dc00084550cd |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-42849--superset-docs-preview.netlify.app](https://deploy-preview-42849--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
|<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#q1YqKMrPLShRslJS0lFKKkrMS84AsgsSS5IzdI2BQimpBTn5lZ4pQEGzxCRDU5NEU_NkA4MUIDawMDE1NUhOUaoFAA) |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-42849--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard): add pre-filter option to Time Grain dashboard control [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-6488243320
## <a href="https://codeant.ai/" title="CodeAnt AI"><img src="https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/codeant-block-purple-v2.svg" width="28" height="28" align="absmiddle" style="vertical-align:middle" alt="CodeAnt" /></a> CodeAnt PR Risk
**🟡 Medium Risk**
- The PR needs attention before merging because restored dashboard filter selections may be ignored in favor of the local default.
- The filter no longer synchronizes its value from filterState, so external selection changes may not appear in the control.
- The allowlist is read imperatively from Redux, so metadata updates after mount will not refresh the available options.
**Assessed commit:** `ba2ad5c5ba6a`
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5685314949
Ease of implementation isn't really enough justification for a second allowlist mechanism with no UI though, especially since the per-filter one already exists and works today. Any appetite for building on that UI instead of the new JSON field?
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "sonfire186 (via GitHub)" <gi...@apache.org>.
sonfire186 commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5678406952
> especially since it's only reachable by hand-editing JSON with no UI for it
ease of implementation
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5676476192
Thanks for tackling this! There's already a per-filter `timeGrains` allowlist in `TimeGrainFilterPlugin.tsx`. Curious why this needed a new dashboard-level `time_grain_allowlist` in JSON metadata instead of building on that, especially since it's only reachable by hand-editing JSON with no UI for it.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5704643678
This has conflicts with master now, and a handful of checks are actually failing, not just the review gate (lint-check, lint-frontend, pre-commit, docker-build). Happy to rebase and clean up the lint if you want, or I can just take it from here since maintainer edits are enabled.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] Add pre-filter option to Time Grain dashboard control [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5722136596
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - 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 <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</details>
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard): add pre-filter option to Time Grain dashboard control [superset]
Posted by "rusackas (via GitHub)" <gi...@apache.org>.
rusackas commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-5769552953
Title and lint are sorted now, thanks. The `unit-tests`/`unit-tests-required` reds look like the artifact-upload step hitting a 403 from GitHub, not anything in the diff (all 16k+ tests actually passed), so nothing to fix on your end there.
As noted above though, `dashboardTimeGrainAllowlist` is still pulled via `useContext(ReactReduxContext)` + `store.getState()` instead of `useSelector`, and I'm still not sure why this needs its own `time_grain_allowlist` field instead of extending the per-filter `timeGrains` allowlist that already exists. Would still like to see those addressed before this moves further.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] feat(dashboard): add pre-filter option to Time Grain dashboard control [superset]
Posted by "rusackas (via GitHub) via notifications" <no...@superset.apache.org>.
rusackas commented on PR #42849:
URL: https://github.com/apache/superset/pull/42849#issuecomment-7429457841
Heya @sonfire186, checking back in on the two questions above (`useSelector`, and reusing the per-filter `timeGrains` allowlist). If you're short on time, happy to carry this forward on a fresh PR with credit to you.
--
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: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org