You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by am...@apache.org on 2021/04/28 05:40:16 UTC
[superset] 12/12: feat(native-filters): Show/Hide filter bar by
metdata ff (#14261)
This is an automated email from the ASF dual-hosted git repository.
amitmiran pushed a commit to branch 1.2
in repository https://gitbox.apache.org/repos/asf/superset.git
commit d63c6373a8c0886d2f4e01f7171ccca7c423e665
Author: simcha90 <56...@users.noreply.github.com>
AuthorDate: Wed Apr 28 07:49:03 2021 +0300
feat(native-filters): Show/Hide filter bar by metdata ff (#14261)
* fix:fix get permission function
* feat: hide native filters by metadata
* fix: fix show_native_filters name
* fix: metadata
* chore: add migration to hide native_filters in all existing dashboards
* chore: fix pre-commit
* fix: make migration migration dashboard with filter_box only
* fix: pre-commit
* feat: hide filter bar if no permission edit and no filters
* fix: remove migration
Co-authored-by: amitmiran137 <am...@nielsen.com>
(cherry picked from commit 2486fd4f6d8d873a46fca129ddd7fda2838c13f5)
---
superset-frontend/src/dashboard/actions/hydrate.js | 11 +++++++----
.../components/DashboardBuilder/DashboardBuilder.tsx | 13 ++++++++++---
.../components/nativeFilters/FilterBar/Header/index.tsx | 3 ++-
superset-frontend/src/dashboard/types.ts | 5 +++++
superset/dashboards/schemas.py | 1 +
5 files changed, 25 insertions(+), 8 deletions(-)
diff --git a/superset-frontend/src/dashboard/actions/hydrate.js b/superset-frontend/src/dashboard/actions/hydrate.js
index 0206d91..9e4e2b0 100644
--- a/superset-frontend/src/dashboard/actions/hydrate.js
+++ b/superset-frontend/src/dashboard/actions/hydrate.js
@@ -302,6 +302,13 @@ export const hydrateDashboard = (dashboardData, chartData, datasourcesData) => (
filterSetsConfig: metadata?.filter_sets_configuration || [],
});
+ if (!metadata) {
+ metadata = {};
+ }
+
+ metadata.show_native_filters =
+ 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
@@ -314,10 +321,6 @@ export const hydrateDashboard = (dashboardData, chartData, datasourcesData) => (
) ?? {}
)?.behaviors ?? [];
- if (!metadata) {
- metadata = {};
- }
-
if (!metadata.chart_configuration) {
metadata.chart_configuration = {};
}
diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx
index 463a770..23b332e 100644
--- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx
+++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx
@@ -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,
);
@@ -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);
diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Header/index.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Header/index.tsx
index f9844a9..096e58b 100644
--- a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Header/index.tsx
+++ b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/Header/index.tsx
@@ -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;
@@ -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,
);
diff --git a/superset-frontend/src/dashboard/types.ts b/superset-frontend/src/dashboard/types.ts
index 7731a7a..ddc5d8c 100644
--- a/superset-frontend/src/dashboard/types.ts
+++ b/superset-frontend/src/dashboard/types.ts
@@ -44,6 +44,10 @@ 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 = {
@@ -53,6 +57,7 @@ export type RootState = {
dashboardLayout: DashboardLayoutState;
dashboardFilters: {};
dashboardState: DashboardState;
+ dashboardInfo: DashboardInfo;
dataMask: DataMaskStateWithId;
dashboardInfo: JsonObject;
impressionId: string;
diff --git a/superset/dashboards/schemas.py b/superset/dashboards/schemas.py
index 0d89c2c..6293373 100644
--- a/superset/dashboards/schemas.py
+++ b/superset/dashboards/schemas.py
@@ -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