GitHub user FrancescoCastaldi added a comment to the discussion: Added the 
ability to add a new filter or overlap a filter using extensions

Hi @shomidrashidi,

This is a great point and a very common requirement, especially for 
organizations that rely on non-Gregorian calendar systems (such as 
Jalali/Persian, Hijri, Buddhist, or custom fiscal/retail 4-4-5 calendars) or 
teams needing bespoke filtering widgets without maintaining a full Superset 
fork.

Here is a breakdown of why this is currently limited, the workarounds available 
today, and what architectural changes would be needed to support 
custom/replacement filters via the Extensions Registry.

---

### 1. Current Architectural Limitation

Native Dashboard Filters in Superset are not ordinary chart components; they 
are registered via the **Chart Plugin system** through `ChartPlugin` 
declarations with specific behaviors:

- In `superset-frontend/src/filters/components/`, each native filter (e.g., 
`Select`, `Range`, `Time`, `TimeGrain`, `TimeColumn`) is registered into the 
global `ChartMetadata` with:
  ```ts
  behaviors: [Behavior.InteractiveChart, Behavior.NativeFilter]
  ```
- **Filter Bar vs. Extension Registry**:
  - The Superset **Extension Registry** 
(`packages/superset-ui-core/src/ui-overrides`) is currently designed to inject 
UI slots (e.g., navbar items, custom headers, menu actions, sub-menus).
  - The **FilterBar** component 
(`src/dashboard/components/nativeFilters/FilterBar/`) queries the filter 
registry directly via `getChartMetadataRegistry().get(filterType)` and has 
hardcoded assumptions around `TimeFilterPlugin` and Day.js/Moment Gregorian 
datetime serialization.
  - As a result, extensions cannot easily intercept or substitute the standard 
`filter_time` component without patching the core frontend bundle.

---

### 2. Practical Solutions Available Today

While native filter extension slots are not yet first-class in the UI override 
registry, you can achieve custom non-Gregorian and bespoke filtering in current 
Superset versions using **Cross-Filtering Chart Plugins**:

#### Custom Cross-Filter Chart Plugin (Recommended Workaround)
You can create and register a custom chart plugin (or an embedded custom 
visualization) that emits cross-filters:
1. Declare your plugin with `Behavior.InteractiveChart`.
2. Implement your calendar/picker UI (e.g., using `moment-jalaali`, 
`date-fns-jalali`, or custom calendar libraries).
3. Convert the selected date range into standard ISO-8601 UTC strings or 
standard SQL adhoc filter formats (`YYYY-MM-DD HH:mm:ss`).
4. Dispatch the filter to the dashboard via `setDataMask`:
   ```ts
   props.setDataMask({
     extraFormData: {
       time_range: `${startIso} : ${endIso}`,
       adhoc_filters: [
         {
           clause: 'WHERE',
           subject: 'your_datetime_column',
           operator: 'TEMPORAL_RANGE',
           comparator: `${startIso} : ${endIso}`,
           expressionType: 'SIMPLE',
         }
       ],
     },
     filterState: {
       value: [startIso, endIso],
     },
   });
   ```
5. Place this chart directly at the top of the dashboard or in a collapsable 
row. It will control all charts across the dashboard exactly like a native 
filter.

---

### 3. Proposed Architectural Path (Towards a PR / SIP)

To natively support this via the Extensions Registry, Superset would benefit 
from the following extension slot additions:

1. **Native Filter Override Hook in `ui-overrides`**:
   Extend `packages/superset-ui-core/src/ui-overrides/types.ts` with a filter 
component resolver:
   ```ts
   export interface ExtensionsRegistry {
     'dashboard.nativeFilter.override'?: (filterType: string) => 
React.ComponentType<any> | undefined;
     'dashboard.nativeFilter.customTypes'?: () => 
Array<NativeFilterPluginDefinition>;
   }
   ```
2. **Dynamic Filter Lookup in `FilterBar`**:
   Update `FilterBar` / `FilterControl` to check 
`extensionsRegistry.get('dashboard.nativeFilter.override')` before falling back 
to `getChartMetadataRegistry().get(filterType)`.
3. **Pluggable Date Engine / Serializer**:
   Decouple the time range formatter from Gregorian Day.js / Moment.js so that 
custom calendar plugins can parse input strings according to their locale 
before serializing to ISO 8601 for SQL queries.

If you are interested in collaborating on this or opening an official **SIP 
(Superset Improvement Proposal)**, I would be glad to discuss the technical 
implementation details and contribute!

GitHub link: 
https://github.com/apache/superset/discussions/43814#discussioncomment-18540234

----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to: 
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to