Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(native-filters): Show/Hide filter bar by metdata ff #14261

Merged
merged 14 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions superset-frontend/src/dashboard/actions/hydrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ export const hydrateDashboard = (dashboardData, chartData, datasourcesData) => (
filterSetsConfig: metadata?.filter_sets_configuration || [],
});

if (!metadata) {
metadata = {};
}

metadata.show_native_filters =
Copy link
Member

Choose a reason for hiding this comment

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

@simcha90 @amitmiran137 @villebro should this use the DASHBOARD_NATIVE_FILTERS feature flag for defining the fallback rather than defaulting to true? We've seen instances at Airbnb where dashboard native filters are showing up in the dashboard metadata even though the feature is disabled.

dashboardData?.metadata?.show_native_filters ?? true;

if (isFeatureEnabled(FeatureFlag.DASHBOARD_CROSS_FILTERS)) {
// If user just added cross filter to dashboard it's not saving it scope on server,
// so we tweak it until user will update scope and will save it in server
Expand All @@ -314,10 +321,6 @@ export const hydrateDashboard = (dashboardData, chartData, datasourcesData) => (
) ?? {}
)?.behaviors ?? [];

if (!metadata) {
metadata = {};
}

if (!metadata.chart_configuration) {
metadata.chart_configuration = {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
const dashboardLayout = useSelector<RootState, DashboardLayout>(
state => state.dashboardLayout.present,
);
const showNativeFilters = useSelector<RootState, boolean>(
state => state.dashboardInfo.metadata?.show_native_filters,
);
const canEdit = useSelector<RootState, boolean>(
({ dashboardInfo }) => dashboardInfo.dash_edit_perm,
);
const editMode = useSelector<RootState, boolean>(
state => state.dashboardState.editMode,
);
Expand All @@ -112,9 +118,10 @@ const DashboardBuilder: FC<DashboardBuilderProps> = () => {
const filters = useFilters();
const filterValues = Object.values<Filter>(filters);

const nativeFiltersEnabled = isFeatureEnabled(
FeatureFlag.DASHBOARD_NATIVE_FILTERS,
);
const nativeFiltersEnabled =
showNativeFilters &&
isFeatureEnabled(FeatureFlag.DASHBOARD_NATIVE_FILTERS) &&
(canEdit || (!canEdit && filterValues.length !== 0));

const [dashboardFiltersOpen, setDashboardFiltersOpen] = useState(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import FilterConfigurationLink from 'src/dashboard/components/nativeFilters/Filt
import { useFilters } from 'src/dashboard/components/nativeFilters/FilterBar/state';
import { Filter } from 'src/dashboard/components/nativeFilters/types';
import { getFilterBarTestId } from '..';
import { RootState } from '../../../../types';

const TitleArea = styled.h4`
display: flex;
Expand Down Expand Up @@ -79,7 +80,7 @@ const Header: FC<HeaderProps> = ({
}) => {
const filters = useFilters();
const filterValues = Object.values<Filter>(filters);
const canEdit = useSelector<any, boolean>(
const canEdit = useSelector<RootState, boolean>(
({ dashboardInfo }) => dashboardInfo.dash_edit_perm,
);

Expand Down
5 changes: 5 additions & 0 deletions superset-frontend/src/dashboard/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ export type Chart = {
export type DashboardLayout = { [key: string]: LayoutItem };
export type DashboardLayoutState = { present: DashboardLayout };
export type DashboardState = { editMode: boolean; directPathToChild: string[] };
export type DashboardInfo = {
dash_edit_perm: boolean;
metadata: { show_native_filters: boolean };
};

/** Root state of redux */
export type RootState = {
charts: { [key: string]: Chart };
dashboardLayout: DashboardLayoutState;
dashboardFilters: {};
dashboardState: DashboardState;
dashboardInfo: DashboardInfo;
dataMask: DataMaskStateWithId;
};

Expand Down
1 change: 1 addition & 0 deletions superset/dashboards/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def validate_json_metadata(value: Union[bytes, bytearray, str]) -> None:


class DashboardJSONMetadataSchema(Schema):
show_native_filters = fields.Boolean()
# native_filter_configuration is for dashboard-native filters
native_filter_configuration = fields.List(fields.Dict(), allow_none=True)
# chart_configuration for now keeps data about cross-filter scoping for charts
Expand Down