From 5f0c3204154df0e0f3fe944078119a4c03280cba Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Thu, 2 Mar 2023 07:29:51 +1300 Subject: [PATCH] chore: Deprecate show_native_filters (#23228) --- .../dashboard/nativeFilters.test.ts | 1 - .../spec/fixtures/mockDashboardState.js | 2 +- superset-frontend/src/constants.ts | 4 -- .../src/dashboard/actions/hydrate.js | 3 - .../DashboardBuilder.test.tsx | 1 - .../components/DashboardBuilder/state.ts | 6 -- .../FilterBarSettings.test.tsx | 1 - superset-frontend/src/dashboard/types.ts | 1 - superset/dashboards/schemas.py | 1 - ...c0a3ea245b61_remove_show_native_filters.py | 57 +++++++++++++++++++ tests/unit_tests/fixtures/assets_configs.py | 2 - 11 files changed, 58 insertions(+), 21 deletions(-) create mode 100644 superset/migrations/versions/2023-02-28_14-46_c0a3ea245b61_remove_show_native_filters.py diff --git a/superset-frontend/cypress-base/cypress/integration/dashboard/nativeFilters.test.ts b/superset-frontend/cypress-base/cypress/integration/dashboard/nativeFilters.test.ts index e934a47bfb68f..7e1d3d5371bb5 100644 --- a/superset-frontend/cypress-base/cypress/integration/dashboard/nativeFilters.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/dashboard/nativeFilters.test.ts @@ -119,7 +119,6 @@ function prepareDashboardFilters( }); if (dashboardId) { const jsonMetadata = { - show_native_filters: true, native_filter_configuration: allFilters, timed_refresh_immune_slices: [], expanded_slices: {}, diff --git a/superset-frontend/spec/fixtures/mockDashboardState.js b/superset-frontend/spec/fixtures/mockDashboardState.js index 0895ccf386955..737e38aef59e0 100644 --- a/superset-frontend/spec/fixtures/mockDashboardState.js +++ b/superset-frontend/spec/fixtures/mockDashboardState.js @@ -113,6 +113,6 @@ export const overwriteConfirmMetadata = { slug: null, owners: [], json_metadata: - '{"timed_refresh_immune_slices":[],"expanded_slices":{},"refresh_frequency":0,"default_filters":"{}","color_scheme":"supersetColors","label_colors":{"0":"#FCC700","1":"#A868B7","15":"#3CCCCB","30":"#A38F79","45":"#8FD3E4","age":"#1FA8C9","Yes,":"#1FA8C9","Female":"#454E7C","Prefer":"#5AC189","No,":"#FF7F44","Male":"#666666","Prefer not to say":"#E04355","Ph.D.":"#FCC700","associate\'s degree":"#A868B7","bachelor\'s degree":"#3CCCCB","high school diploma or equivalent (GED)":"#A38F79","master\'s degree (non-professional)":"#8FD3E4","no high school (secondary school)":"#A1A6BD","professional degree (MBA, MD, JD, etc.)":"#ACE1C4","some college credit, no degree":"#FEC0A1","some high school":"#B2B2B2","trade, technical, or vocational training":"#EFA1AA","No, not an ethnic minority":"#1FA8C9","Yes, an ethnic minority":"#454E7C","":"#5AC189","Yes":"#FF7F44","No":"#666666","last_yr_income":"#E04355","More":"#A1A6BD","Less":"#ACE1C4","I":"#FEC0A1","expected_earn":"#B2B2B2","Yes: Willing To":"#EFA1AA","No: Not Willing to":"#FDE380","No Answer":"#D3B3DA","In an Office (with Other Developers)":"#9EE5E5","No Preference":"#D1C6BC","From Home":"#1FA8C9"},"show_native_filters":true,"color_scheme_domain":["#1FA8C9","#454E7C","#5AC189","#FF7F44","#666666","#E04355","#FCC700","#A868B7","#3CCCCB","#A38F79","#8FD3E4","#A1A6BD","#ACE1C4","#FEC0A1","#B2B2B2","#EFA1AA","#FDE380","#D3B3DA","#9EE5E5","#D1C6BC"],"shared_label_colors":{"Male":"#5ac19e","Female":"#1f86c9","":"#5AC189","Prefer not to say":"#47457c","No Answer":"#e05043","Yes, an ethnic minority":"#666666","No, not an ethnic minority":"#ffa444","age":"#1FA8C9"},"cross_filters_enabled":false,"filter_scopes":{},"chart_configuration":{},"positions":{}}', + '{"timed_refresh_immune_slices":[],"expanded_slices":{},"refresh_frequency":0,"default_filters":"{}","color_scheme":"supersetColors","label_colors":{"0":"#FCC700","1":"#A868B7","15":"#3CCCCB","30":"#A38F79","45":"#8FD3E4","age":"#1FA8C9","Yes,":"#1FA8C9","Female":"#454E7C","Prefer":"#5AC189","No,":"#FF7F44","Male":"#666666","Prefer not to say":"#E04355","Ph.D.":"#FCC700","associate\'s degree":"#A868B7","bachelor\'s degree":"#3CCCCB","high school diploma or equivalent (GED)":"#A38F79","master\'s degree (non-professional)":"#8FD3E4","no high school (secondary school)":"#A1A6BD","professional degree (MBA, MD, JD, etc.)":"#ACE1C4","some college credit, no degree":"#FEC0A1","some high school":"#B2B2B2","trade, technical, or vocational training":"#EFA1AA","No, not an ethnic minority":"#1FA8C9","Yes, an ethnic minority":"#454E7C","":"#5AC189","Yes":"#FF7F44","No":"#666666","last_yr_income":"#E04355","More":"#A1A6BD","Less":"#ACE1C4","I":"#FEC0A1","expected_earn":"#B2B2B2","Yes: Willing To":"#EFA1AA","No: Not Willing to":"#FDE380","No Answer":"#D3B3DA","In an Office (with Other Developers)":"#9EE5E5","No Preference":"#D1C6BC","From Home":"#1FA8C9"},"color_scheme_domain":["#1FA8C9","#454E7C","#5AC189","#FF7F44","#666666","#E04355","#FCC700","#A868B7","#3CCCCB","#A38F79","#8FD3E4","#A1A6BD","#ACE1C4","#FEC0A1","#B2B2B2","#EFA1AA","#FDE380","#D3B3DA","#9EE5E5","#D1C6BC"],"shared_label_colors":{"Male":"#5ac19e","Female":"#1f86c9","":"#5AC189","Prefer not to say":"#47457c","No Answer":"#e05043","Yes, an ethnic minority":"#666666","No, not an ethnic minority":"#ffa444","age":"#1FA8C9"},"cross_filters_enabled":false,"filter_scopes":{},"chart_configuration":{},"positions":{}}', }, }; diff --git a/superset-frontend/src/constants.ts b/superset-frontend/src/constants.ts index 26282ed5fcd85..40d0b22aec8b1 100644 --- a/superset-frontend/src/constants.ts +++ b/superset-frontend/src/constants.ts @@ -51,10 +51,6 @@ export const URL_PARAMS = { name: 'filter_set', type: 'string', }, - showFilters: { - name: 'show_filters', - type: 'boolean', - }, expandFilters: { name: 'expand_filters', type: 'boolean', diff --git a/superset-frontend/src/dashboard/actions/hydrate.js b/superset-frontend/src/dashboard/actions/hydrate.js index 8625a2952ac13..e0b17b737dc67 100644 --- a/superset-frontend/src/dashboard/actions/hydrate.js +++ b/superset-frontend/src/dashboard/actions/hydrate.js @@ -305,9 +305,6 @@ export const hydrateDashboard = const nativeFilters = getInitialNativeFilterState({ filterConfig: metadata?.native_filter_configuration || [], }); - metadata.show_native_filters = isFeatureEnabled( - FeatureFlag.DASHBOARD_NATIVE_FILTERS, - ); if (isFeatureEnabled(FeatureFlag.DASHBOARD_CROSS_FILTERS)) { metadata.chart_configuration = getCrossFiltersConfiguration( diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx index fc651e52b706c..3a641660da418 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.test.tsx @@ -281,7 +281,6 @@ describe('DashboardBuilder', () => { dashboardInfo: { ...mockState.dashboardInfo, dash_edit_perm: true, - metadata: { show_native_filters: true }, }, }); const filterbar = getByTestId('dashboard-filters-panel'); diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts b/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts index 850d195f44e07..807228213891c 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/state.ts @@ -30,11 +30,6 @@ import { // eslint-disable-next-line import/prefer-default-export export const useNativeFilters = () => { const [isInitialized, setIsInitialized] = useState(false); - const showNativeFilters = useSelector( - state => - (getUrlParam(URL_PARAMS.showFilters) ?? true) && - state.dashboardInfo.metadata?.show_native_filters, - ); const canEdit = useSelector( ({ dashboardInfo }) => dashboardInfo.dash_edit_perm, ); @@ -47,7 +42,6 @@ export const useNativeFilters = () => { ); const nativeFiltersEnabled = - showNativeFilters && isFeatureEnabled(FeatureFlag.DASHBOARD_NATIVE_FILTERS) && (canEdit || (!canEdit && filterValues.length !== 0)); diff --git a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBarSettings/FilterBarSettings.test.tsx b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBarSettings/FilterBarSettings.test.tsx index 344e891365a50..10fd66d7078a0 100644 --- a/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBarSettings/FilterBarSettings.test.tsx +++ b/superset-frontend/src/dashboard/components/nativeFilters/FilterBar/FilterBarSettings/FilterBarSettings.test.tsx @@ -33,7 +33,6 @@ const initialState: { dashboardInfo: DashboardInfo } = { userId: '1', metadata: { native_filter_configuration: {}, - show_native_filters: true, chart_configuration: {}, color_scheme: '', color_namespace: '', diff --git a/superset-frontend/src/dashboard/types.ts b/superset-frontend/src/dashboard/types.ts index 87dee0b05ab68..56bccf900e84a 100644 --- a/superset-frontend/src/dashboard/types.ts +++ b/superset-frontend/src/dashboard/types.ts @@ -101,7 +101,6 @@ export type DashboardInfo = { json_metadata: string; metadata: { native_filter_configuration: JsonObject; - show_native_filters: boolean; chart_configuration: JsonObject; color_scheme: string; color_namespace: string; diff --git a/superset/dashboards/schemas.py b/superset/dashboards/schemas.py index f23eee9d27126..c74c7ba52ac67 100644 --- a/superset/dashboards/schemas.py +++ b/superset/dashboards/schemas.py @@ -108,7 +108,6 @@ 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 diff --git a/superset/migrations/versions/2023-02-28_14-46_c0a3ea245b61_remove_show_native_filters.py b/superset/migrations/versions/2023-02-28_14-46_c0a3ea245b61_remove_show_native_filters.py new file mode 100644 index 0000000000000..86eda9c007bca --- /dev/null +++ b/superset/migrations/versions/2023-02-28_14-46_c0a3ea245b61_remove_show_native_filters.py @@ -0,0 +1,57 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""remove_show_native_filters + +Revision ID: c0a3ea245b61 +Revises: f3c2d8ec8595 +Create Date: 2023-02-28 14:46:59.597847 + +""" + +# revision identifiers, used by Alembic. +revision = "c0a3ea245b61" +down_revision = "f3c2d8ec8595" + +import json + +from alembic import op + +from superset import db +from superset.models.dashboard import Dashboard + + +def upgrade(): + bind = op.get_bind() + session = db.Session(bind=bind) + + for dashboard in session.query(Dashboard).all(): + try: + json_metadata = json.loads(dashboard.json_metadata) + + if "show_native_filters" in json_metadata: + del json_metadata["show_native_filters"] + dashboard.json_metadata = json.dumps(json_metadata) + session.merge(dashboard) + except Exception: # pylint: disable=broad-except + pass + + session.commit() + session.close() + + +def downgrade(): + pass diff --git a/tests/unit_tests/fixtures/assets_configs.py b/tests/unit_tests/fixtures/assets_configs.py index 6e78d9e562d10..73bc5921ec42f 100644 --- a/tests/unit_tests/fixtures/assets_configs.py +++ b/tests/unit_tests/fixtures/assets_configs.py @@ -174,7 +174,6 @@ "default_filters": "{}", "color_scheme": "supersetColors", "label_colors": {}, - "show_native_filters": True, "color_scheme_domain": [], "shared_label_colors": {}, "cross_filters_enabled": False, @@ -251,7 +250,6 @@ "default_filters": "{}", "color_scheme": "supersetColors", "label_colors": {}, - "show_native_filters": True, "color_scheme_domain": [], "shared_label_colors": {}, },