Skip to content

feat: Add Dashboard Filter Support for Alert Reports - #32196

Merged
hughhhh merged 106 commits into
masterfrom
hm/ar-filters
Sep 16, 2025
Merged

feat: Add Dashboard Filter Support for Alert Reports#32196
hughhhh merged 106 commits into
masterfrom
hm/ar-filters

Conversation

@hughhhh

@hughhhh hughhhh commented Feb 9, 2025

Copy link
Copy Markdown
Member

Summary

This PR introduces a new feature that allows users to configure dashboard filters when creating alert reports. The feature is controlled by the ALERT_REPORTS_FILTER feature flag and enables users to specify which native filters should be applied when generating dashboard reports.

Key Features

  • Dashboard Filter Selection: Users can now select specific native filters from a dashboard when creating alert reports
  • Filter Value Configuration: Support for configuring filter values including:
    • Time range filters (filter_time)
    • Range filters (filter_range) with min/max values
    • Select filters (filter_select) with multiple value selection
    • Time column filters (filter_timecolumn)
    • Time grain filters (filter_timegrain)
  • Dynamic Filter Options: Filter values are dynamically fetched based on the selected dashboard and filter type
  • Validation: Comprehensive validation ensures filter configurations are complete before saving

Technical Implementation

Frontend Changes

  • AlertReportModal.tsx: Enhanced with filter selection UI components
    • Added TreeSelect for filter selection
    • Implemented filter value configuration controls
    • Added validation for filter completeness
    • Integrated with existing dashboard state management

Backend Changes

  • Report Execution: Modified to apply configured filters when generating reports
  • API Integration: Enhanced to fetch filter options and validate filter configurations
  • Data Processing: Added support for processing filter values in report generation

Feature Flag

  • ALERT_REPORTS_FILTER: New feature flag to control the dashboard filter functionality
  • Defaults to True in development environments
  • Can be disabled for production if needed

User Experience

  1. Filter Selection: When creating a dashboard report, users can select from available native filters
  2. Value Configuration: For each selected filter, users can configure appropriate values:
    • Date ranges for time filters
    • Min/max values for range filters
    • Multiple selections for select filters
  3. Validation: The system validates that all selected filters have proper values configured
  4. Report Generation: When the report runs, it applies the configured filters to generate filtered dashboard content

Testing

  • Added comprehensive unit tests for filter validation
  • Integration tests for filter value processing
  • UI component tests for filter selection interface

Configuration

The feature is enabled by default but can be controlled via the ALERT_REPORTS_FILTER feature flag in superset_config.py:

"ALERT_REPORTS_FILTER": True 
"ALERT_REPORTS_TABS": True

Breaking Changes

None - this is a purely additive feature that doesn't affect existing functionality.

Documentation

  • Updated feature flags documentation to include the new ALERT_REPORTS_FILTER flag
  • Added inline code comments explaining filter processing logic

This enhancement significantly improves the flexibility of alert reports by allowing users to generate

@github-actions github-actions Bot added the api Related to the REST API label Feb 9, 2025
@dosubot dosubot Bot added the alert-reports Namespace | Anything related to the Alert & Reports feature label Feb 9, 2025
@hughhhh
hughhhh force-pushed the hm/ar-filters branch 2 times, most recently from 4f78062 to 6db36be Compare February 9, 2025 13:04
@korbit-ai

korbit-ai Bot commented Feb 9, 2025

Copy link
Copy Markdown

I was unable to post the issues I found. This could be because a force push or squash has changed the commit history since I scanned this pull request. You can get another review by commenting /korbit-review.

@hughhhh
hughhhh force-pushed the hm/ar-filters branch 2 times, most recently from 72774cd to d6adc97 Compare February 9, 2025 13:07
Comment thread superset/commands/dashboard/permalink/create.py Outdated

@heidijosweeenz1997 heidijosweeenz1997 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Withdraw in to my commonwealth bank

@michael-s-molina
michael-s-molina marked this pull request as draft February 10, 2025 18:26
@hughhhh
hughhhh force-pushed the hm/ar-filters branch 2 times, most recently from 8574ad9 to a3c7b96 Compare February 10, 2025 19:42
@github-actions

Copy link
Copy Markdown
Contributor

@sadpandajoe Processing your ephemeral environment request here. Action: up. More information on how to use or configure ephemeral environments

@github-actions

Copy link
Copy Markdown
Contributor

@sadpandajoe Ephemeral environment spinning up at http://44.245.216.87:8080. Credentials are 'admin'/'admin'. Please allow several minutes for bootstrapping and startup.

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

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.

Code Review Agent Run #b010e8

Actionable Suggestions - 23
  • tests/integration_tests/reports/commands/execute_dashboard_report_tests.py - 2
    • Dashboard state access broken by structure change · Line 52-55
    • Broken dashboard state access pattern · Line 95-98
  • superset-frontend/src/features/alerts/AlertReportModal.tsx - 14
  • superset/reports/models.py - 4
  • superset/commands/report/execute.py - 2
  • tests/unit_tests/reports/model_test.py - 1
Additional Suggestions - 4
  • superset-frontend/src/features/alerts/AlertReportModal.tsx - 4
    • Incorrect CSS property for inline element · Line 110-110
      The CSS property `align-content: center` is inappropriate for a span element and won't achieve vertical centering. Use `vertical-align: middle` instead to properly center the divider text relative to adjacent InputNumber components.
      Code suggestion
       @@ -110,1 +110,1 @@
      -  align-content: center;
      +  vertical-align: middle;
    • Unused import Button from components · Line 48-48
      The `Button` component is imported but never used in the code. Consider removing this unused import to improve code cleanliness.
      Code suggestion
       @@ -46,7 +46,6 @@
        import {
          AsyncSelect,
      -  Button,
          Checkbox,
          Collapse,
          CollapseLabelInModal,
    • Unused import _isColumnsSortingCoupledToGroup · Line 90-90
      The `_isColumnsSortingCoupledToGroup` import is unused. Remove this import to keep the codebase clean and reduce bundle size.
      Code suggestion
       @@ -87,7 +87,6 @@
        import { useSelector } from 'react-redux';
        import { UserWithPermissionsAndRoles } from 'src/types/bootstrapTypes';
        import { getChartDataRequest } from 'src/components/Chart/chartAction';
      -import { _isColumnsSortingCoupledToGroup } from 'ag-grid-community';
        import DateFilterControl from 'src/explore/components/controls/DateFilterControl';
        import { Icons } from '@superset-ui/core/components/Icons';
        import { StandardModal, ModalFormField } from 'src/components/Modal';
    • Unused parameter in catch block · Line 1108-1108
      The catch block parameter `e` is defined but never used. Either use the error parameter or remove it to follow best practices.
      Code suggestion
       @@ -1108,7 +1108,7 @@
                 })
      -        .catch(e => {
      +        .catch(() => {
                  addDangerToast(t('There was an error retrieving dashboard tabs.'));
                 });
             }
Review Details
  • Files reviewed - 14 · Commit Range: 38bb661..de6df8d
    • superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts
    • superset-frontend/src/features/alerts/AlertReportModal.test.tsx
    • superset-frontend/src/features/alerts/AlertReportModal.tsx
    • superset-frontend/src/features/alerts/types.ts
    • superset/commands/report/execute.py
    • superset/config.py
    • superset/daos/dashboard.py
    • superset/dashboards/api.py
    • superset/reports/models.py
    • superset/views/core.py
    • tests/integration_tests/dashboards/api_tests.py
    • tests/integration_tests/reports/commands/execute_dashboard_report_tests.py
    • tests/integration_tests/reports/commands_tests.py
    • tests/unit_tests/reports/model_test.py
  • 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 Default Agent 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 +52 to +55
extra={
"activeTabs": ["TAB-L1B", "TAB-L2BB"],
"urlParams": [["native_filters", "()"]],
},

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.

Dashboard state access broken by structure change

The extra parameter structure change breaks dashboard state access. The create_dashboard_report function wraps the extra parameter in a dashboard key (line 199 in utils.py), but the test later accesses report_schedule.extra.get("dashboard", {}) (line 62). With the new flat structure, this will return an empty dict instead of the expected dashboard state, causing the CreateDashboardPermalinkCommand to receive incorrect parameters.

Code suggestion
Check the AI-generated fix before applying
Suggested change
extra={
"activeTabs": ["TAB-L1B", "TAB-L2BB"],
"urlParams": [["native_filters", "()"]],
},
extra={"dashboard": {
"activeTabs": ["TAB-L1B", "TAB-L2BB"],
"urlParams": [["native_filters", "()"]],
}},

Code Review Run #b010e8


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

  • Yes, avoid them

Comment on lines +95 to +98
extra={
"active_tabs": ["TAB-L1B", "TAB-L2BB"],
"urlParams": [["native_filters", "()"]],
},

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.

Broken dashboard state access pattern

The flattened extra parameter structure breaks dashboard state access. The create_dashboard_report function wraps the extra parameter under a dashboard key, but the test code expects to access it via report_schedule.extra.get('dashboard', {}). With the new structure, dashboard_state will be an empty dictionary, causing CreateDashboardPermalinkCommand to fail with incorrect parameters. Revert to the nested structure: extra={'dashboard': {'active_tabs': [...], 'urlParams': [...]}} to maintain compatibility.

Code suggestion
Check the AI-generated fix before applying
Suggested change
extra={
"active_tabs": ["TAB-L1B", "TAB-L2BB"],
"urlParams": [["native_filters", "()"]],
},
extra={"dashboard": {"active_tabs": ["TAB-L1B", "TAB-L2BB"], "urlParams": [["native_filters", "()"]]}},

Code Review Run #b010e8


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

  • Yes, avoid them


.filters-trashcan {
width: ${theme.sizeUnit * 10}px;
display: 'flex';

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.

Invalid CSS display property value

Invalid CSS display property value. The display: 'flex' has quotes around 'flex', making it a literal string instead of a CSS value. This will break the flexbox layout. Remove the quotes to fix: display: flex;

Code suggestion
Check the AI-generated fix before applying
Suggested change
display: 'flex';
display: flex;

Code Review Run #b010e8


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

  • Yes, avoid them

color: ${theme.colorIcon};
}
.filters-add-container {
flex: '.25';

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.

Invalid CSS flex property value

Invalid CSS flex property value. The flex: '.25' has quotes around '.25', making it a literal string instead of a numeric CSS value. This will break the flex layout. Remove the quotes to fix: flex: 0.25;

Code suggestion
Check the AI-generated fix before applying
Suggested change
flex: '.25';
flex: 0.25;

Code Review Run #b010e8


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

  • Yes, avoid them

}
.filters-add-container {
flex: '.25';
padding: '${theme.sizeUnit * 3} 0';

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.

Invalid CSS padding template literal

Invalid CSS padding property value. The padding: '${theme.sizeUnit * 3} 0' has quotes around the template literal, preventing theme variable interpolation. This will break the padding calculation. Remove the quotes to fix: padding: ${theme.sizeUnit * 3}px 0;

Code suggestion
Check the AI-generated fix before applying
Suggested change
padding: '${theme.sizeUnit * 3} 0';
padding: ${theme.sizeUnit * 3}px 0;

Code Review Run #b010e8


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

  • Yes, avoid them

native_filter_id or "": {
"id": native_filter_id or "",
"extraFormData": {
"time_grain_sqla": values[0], # grain

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.

IndexError on timegrain filter values access

IndexError risk: values[0] accessed without bounds checking in filter_timegrain handler. This will crash when values list is empty. Add check: values[0] if values else None.

Code suggestion
Check the AI-generated fix before applying
Suggested change
"time_grain_sqla": values[0], # grain
"time_grain_sqla": values[0] if values else None, # grain

Code Review Run #b010e8


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

  • Yes, avoid them

return {
native_filter_id or "": {
"extraFormData": {
"granularity_sqla": values[0] # column_name

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.

IndexError on timecolumn filter values access

IndexError risk: values[0] accessed without bounds checking in filter_timecolumn handler. This will crash when values list is empty. Add check: values[0] if values else None.

Code suggestion
Check the AI-generated fix before applying
Suggested change
"granularity_sqla": values[0] # column_name
"granularity_sqla": values[0] if values else None # column_name

Code Review Run #b010e8


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

  • Yes, avoid them

Comment on lines +324 to +326
"urlParams": [
["native_filters", native_filter_params] # type: ignore
],

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.

Type mismatch in urlParams structure

Type mismatch in urlParams: The DashboardPermalinkState type expects urlParams to be Optional[list[tuple[str, str]]], but the code provides list[list[str]] by using ["native_filters", native_filter_params]. This should be ("native_filters", native_filter_params) to create a tuple instead of a list.

Code suggestion
Check the AI-generated fix before applying
Suggested change
"urlParams": [
["native_filters", native_filter_params] # type: ignore
],
"urlParams": [
("native_filters", native_filter_params) # type: ignore
],

Code Review Run #b010e8


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

  • Yes, avoid them

"activeTabs": None,
"urlParams": None,
"urlParams": [
["native_filters", native_filter_params] # type: ignore

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.

Type mismatch in urlParams structure

Type mismatch in urlParams: DashboardPermalinkState expects list[tuple[str, str]] but the code provides list[list[str]]. Change ["native_filters", native_filter_params] to ("native_filters", native_filter_params) to match the expected tuple type.

Code suggestion
Check the AI-generated fix before applying
Suggested change
["native_filters", native_filter_params] # type: ignore
("native_filters", native_filter_params) # type: ignore

Code Review Run #b010e8


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

  • Yes, avoid them

native_filter_id = "filter_id"
column_name = "column_name"
filter_type = "filter_select"
values = None

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.

Invalid parameter type in test

The test passes None as the values parameter to _generate_native_filter, but the method signature expects list[Optional[str]]. This will cause a TypeError when the method tries to access values[0] for time filters or use values or [] operations. Change values = None to values = [] to match the expected parameter type.

Code suggestion
Check the AI-generated fix before applying
Suggested change
values = None
values = []

Code Review Run #b010e8


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

  • Yes, avoid them

@bito-code-review

bito-code-review Bot commented Sep 3, 2025

Copy link
Copy Markdown
Contributor

Code Review Agent Run #6f609a

Actionable Suggestions - 0
Review Details
  • Files reviewed - 1 · Commit Range: de6df8d..4740851
    • superset-frontend/src/features/alerts/AlertReportModal.tsx
  • Files skipped - 0
  • Tools
    • 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 Default Agent 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

@geido geido left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Approving this as a good major step while we working on refining details / fixing minor issues.

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

Labels

alert-reports Namespace | Anything related to the Alert & Reports feature api Related to the REST API packages size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants