Closed krishanthvs closed 1 month ago
@krishanthvs Hello there! I'm here to help you with any issues you may have in Superset. I can assist with bug fixes, answer questions, and guide you on how to become a contributor. Looking forward to assisting you!
The reason you are unable to view the filter option in Superset version master/latest-dev is due to the removal of the filter_bar_orientation
from the dashboard's json_metadata
. This change was made in the pull request #22248 [1].
Additionally, there are new configuration options and settings related to filters introduced in recent versions of Superset. For example, the DASHBOARD_NATIVE_FILTERS
feature flag has been permanently enabled, and the deprecated Filter Box code has been removed, with existing filter boxes automatically migrated to native filters [2][3][4].
For more details, you can refer to the UPDATING.md file in the Superset repository.
To continue talking to Dosu, mention @dosu.
@dosu How to add filters in superset dashboard
To add filters in a Superset dashboard, you can use predefined filter classes or programmatically add native filters. Here are the steps:
Example of applying a filter to a query:
from superset.dashboards.filters import DashboardTitleOrSlugFilter
# Example query to filter dashboards by title or slug
query = db.session.query(Dashboard)
filter_value = "example_title_or_slug"
filtered_query = DashboardTitleOrSlugFilter().apply(query, filter_value)
dashboards = filtered_query.all()
You can also add native filters programmatically using the following TypeScript function:
import { SAMPLE_DASHBOARD_1 } from 'cypress/utils/urls';
import { interceptCharts, interceptDatasets, interceptGet } from './utils';
export function prepareDashboardFilters(
filters: { name: string; column: string; datasetId: number }[],
) {
cy.createSampleDashboards([0]);
cy.request({
method: 'GET',
url: `api/v1/dashboard/1-sample-dashboard`,
}).then(res => {
const { body } = res;
const dashboardId = body.result.id;
const allFilters: Record<string, unknown>[] = [];
filters.forEach((f, i) => {
allFilters.push({
id: `NATIVE_FILTER-fLH0pxFQ${i}`,
controlValues: {
enableEmptyFilter: false,
defaultToFirstItem: false,
multiSelect: true,
searchAllOptions: false,
inverseSelection: false,
},
name: f.name,
filterType: 'filter_select',
targets: [
{
datasetId: f.datasetId,
column: { name: f.column },
},
],
defaultDataMask: {
extraFormData: {},
filterState: {},
ownState: {},
},
cascadeParentIds: [],
scope: {
rootPath: ['ROOT_ID'],
excluded: [],
},
type: 'NATIVE_FILTER',
description: '',
chartsInScope: [5],
tabsInScope: [],
});
});
if (dashboardId) {
const jsonMetadata = {
native_filter_configuration: allFilters,
timed_refresh_immune_slices: [],
expanded_slices: {},
refresh_frequency: 0,
color_scheme: '',
label_colors: {},
shared_label_colors: {},
color_scheme_domain: [],
cross_filters_enabled: false,
positions: {
DASHBOARD_VERSION_KEY: 'v2',
ROOT_ID: { type: 'ROOT', id: 'ROOT_ID', children: ['GRID_ID'] },
GRID_ID: {
type: 'GRID',
id: 'GRID_ID',
children: ['ROW-0rHnUz4nMA'],
parents: ['ROOT_ID'],
},
HEADER_ID: {
id: 'HEADER_ID',
type: 'HEADER',
meta: { text: '1 - Sample dashboard' },
},
'CHART-DF6EfI55F-': {
type: 'CHART',
id: 'CHART-DF6EfI55F-',
children: [],
parents: ['ROOT_ID', 'GRID_ID', 'ROW-0rHnUz4nMA'],
meta: {
width: 4,
height: 50,
chartId: 5,
sliceName: 'Most Populated Countries',
},
},
'ROW-0rHnUz4nMA': {
type: 'ROW',
id: 'ROW-0rHnUz4nMA',
children: ['CHART-DF6EfI55F-'],
parents: ['ROOT_ID', 'GRID_ID'],
meta: { background: 'BACKGROUND_TRANSPARENT' },
},
},
default_filters: '{}',
filter_scopes: {},
chart_configuration: {},
};
return cy
.request({
method: 'PUT',
url: `api/v1/dashboard/${dashboardId}`,
body: {
json_metadata: JSON.stringify(jsonMetadata),
},
})
.then(() => visitDashboard(false));
}
return cy;
});
}
This function allows you to add native filters to a dashboard by specifying the filter details and updating the dashboard's metadata [1][2].
To continue talking to Dosu, mention @dosu.
@dosu i want to add a date filter and location filter to my dashboard
To add a date filter and a location filter to your Superset dashboard, follow these steps:
Here is an example of how the date filter options are defined:
export const COMMON_RANGE_OPTIONS: SelectOptionType[] = [
{ value: 'Last day', label: 'Last day' },
{ value: 'Last week', label: 'Last week' },
{ value: 'Last month', label: 'Last month' },
{ value: 'Last quarter', label: 'Last quarter' },
{ value: 'Last year', label: 'Last year' },
];
Once you have added and configured the filters, click on the "Save" button to apply the changes to your dashboard. The filters will now be available for users to interact with and filter the data displayed in the dashboard.
By following these steps, you can successfully add both date and location filters to your Superset dashboard [1].
To continue talking to Dosu, mention @dosu.
@dosu I am unable to view this Drag and drop a "Filter Box" from the components panel to your dashboard
To view and use the "Filter Box" component in the Superset dashboard, you need to interact with the FilterBar
component. The FilterBar
component can be configured to be either horizontal or vertical and includes action buttons for applying and clearing filters.
Here is a simplified example of how you might use the FilterBar
component:
import React from 'react';
import FilterBar, { FilterBarOrientation } from 'src/dashboard/components/nativeFilters/FilterBar';
const MyDashboard = () => {
const verticalConfig = {
filtersOpen: true,
height: 400,
offset: 0,
toggleFiltersBar: () => {},
width: 300,
};
return (
<div>
<FilterBar
orientation={FilterBarOrientation.Vertical}
verticalConfig={verticalConfig}
hidden={false}
/>
{/* Other dashboard components */}
</div>
);
};
export default MyDashboard;
In this example, the FilterBar
is configured to be vertical with specific dimensions and is not hidden. You can customize the verticalConfig
and orientation
as needed for your dashboard layout.
Additionally, the FilterControls
component within the FilterBar
handles the rendering of filters and their interactions. It supports both vertical and horizontal orientations and includes features like collapsing out-of-scope filters and handling cross-filters [1][2][3].
To continue talking to Dosu, mention @dosu.
@dosu can this be assigned to some support team. Need this fixed asap
It seems like we need your specialized knowledge on this, @rusackas.
To continue talking to Dosu, mention @dosu.
@rusackas can you please help me on this
@krishanthvs filter box has been deprecated for 4.0 i think. We switched to native filters and you should be able to open the native filter bar on the left side of a dashboard as it might be collapsed and then you can create your filters. I don't think there is a Superset how to doc, but Preset has one that is pretty descriptive on how to create a filter. https://docs.preset.io/docs/managing-filters
Bug description
I am unable to view the filter option
Screenshots/recordings
No response
Superset version
master / latest-dev
Python version
3.11
Node version
Not applicable
Browser
Chrome
Additional context
No response
Checklist