diff --git a/superset-frontend/src/components/Menu/Menu.tsx b/superset-frontend/src/components/Menu/Menu.tsx index 6733d6a059..0875b85f8a 100644 --- a/superset-frontend/src/components/Menu/Menu.tsx +++ b/superset-frontend/src/components/Menu/Menu.tsx @@ -27,6 +27,7 @@ import { Row, Col, Grid } from 'antd'; import Icon from 'src/components/Icon'; import RightMenu from './MenuRight'; import { Languages } from './LanguagePicker'; +import { URL_PARAMS } from '../../constants'; interface BrandProps { path: string; @@ -158,7 +159,7 @@ export function Menu({ return () => window.removeEventListener('resize', windowResize); }, []); - const standalone = getUrlParam('standalone', 'boolean'); + const standalone = getUrlParam(URL_PARAMS.standalone); if (standalone) return <>; const renderSubMenu = ({ diff --git a/superset-frontend/src/constants.ts b/superset-frontend/src/constants.ts index ad7683681b..bfa7033697 100644 --- a/superset-frontend/src/constants.ts +++ b/superset-frontend/src/constants.ts @@ -23,9 +23,19 @@ export const BOOL_TRUE_DISPLAY = 'True'; export const BOOL_FALSE_DISPLAY = 'False'; export const URL_PARAMS = { - standalone: 'standalone', - preselectFilters: 'preselect_filters', -}; + standalone: { + name: 'standalone', + type: 'number', + }, + preselectFilters: { + name: 'preselect_filters', + type: 'object', + }, + showFilters: { + name: 'show_filters', + type: 'boolean', + }, +} as const; /** * Faster debounce delay for inputs without expensive operation. diff --git a/superset-frontend/src/dashboard/actions/hydrate.js b/superset-frontend/src/dashboard/actions/hydrate.js index 2928df6573..d86ae8c78e 100644 --- a/superset-frontend/src/dashboard/actions/hydrate.js +++ b/superset-frontend/src/dashboard/actions/hydrate.js @@ -27,7 +27,6 @@ import { import { chart } from 'src/chart/chartReducer'; import { initSliceEntities } from 'src/dashboard/reducers/sliceEntities'; import { getInitialState as getInitialNativeFilterState } from 'src/dashboard/reducers/nativeFilters'; -import { getParam } from 'src/modules/utils'; import { applyDefaultFormData } from 'src/explore/store'; import { buildActiveFilters } from 'src/dashboard/util/activeDashboardFilters'; import findPermission, { @@ -54,6 +53,8 @@ import getFilterConfigsFromFormdata from 'src/dashboard/util/getFilterConfigsFro import getLocationHash from 'src/dashboard/util/getLocationHash'; import newComponentFactory from 'src/dashboard/util/newComponentFactory'; import { TIME_RANGE } from 'src/visualizations/FilterBox/FilterBox'; +import { URL_PARAMS } from 'src/constants'; +import { getUrlParam } from 'src/utils/urlUtils'; import { FeatureFlag, isFeatureEnabled } from '../../featureFlags'; import extractUrlParams from '../util/extractUrlParams'; @@ -77,9 +78,9 @@ export const hydrateDashboard = (dashboardData, chartData, datasourcesData) => ( }); try { // allow request parameter overwrite dashboard metadata - preselectFilters = JSON.parse( - getParam('preselect_filters') || metadata.default_filters, - ); + preselectFilters = + getUrlParam(URL_PARAMS.preselectFilters) || + JSON.parse(metadata.default_filters); } catch (e) { // } diff --git a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx index 877cea9c3f..807fe46b75 100644 --- a/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx +++ b/superset-frontend/src/dashboard/components/DashboardBuilder/DashboardBuilder.tsx @@ -120,7 +120,9 @@ const DashboardBuilder: FC = () => { isFeatureEnabled(FeatureFlag.DASHBOARD_NATIVE_FILTERS) && (canEdit || (!canEdit && filterValues.length !== 0)); - const [dashboardFiltersOpen, setDashboardFiltersOpen] = useState(true); + const [dashboardFiltersOpen, setDashboardFiltersOpen] = useState( + getUrlParam(URL_PARAMS.showFilters) ?? true, + ); const toggleDashboardFiltersOpen = (visible?: boolean) => { setDashboardFiltersOpen(visible ?? !dashboardFiltersOpen); @@ -152,7 +154,7 @@ const DashboardBuilder: FC = () => { : undefined; const hideDashboardHeader = - getUrlParam(URL_PARAMS.standalone, 'number') === + getUrlParam(URL_PARAMS.standalone) === DashboardStandaloneMode.HIDE_NAV_AND_TITLE; const barTopOffset = diff --git a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx index 9b9aefe03b..06f5f35014 100644 --- a/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx +++ b/superset-frontend/src/dashboard/components/Header/HeaderActionsDropdown/index.jsx @@ -168,7 +168,7 @@ class HeaderActionsDropdown extends React.PureComponent { window.location.pathname, getActiveFilters(), window.location.hash, - getUrlParam(URL_PARAMS.standalone, 'number'), + getUrlParam(URL_PARAMS.standalone), ); window.location.replace(url); break; diff --git a/superset-frontend/src/dashboard/util/getDashboardUrl.ts b/superset-frontend/src/dashboard/util/getDashboardUrl.ts index d3cf06c668..7eb817a095 100644 --- a/superset-frontend/src/dashboard/util/getDashboardUrl.ts +++ b/superset-frontend/src/dashboard/util/getDashboardUrl.ts @@ -30,12 +30,12 @@ export default function getDashboardUrl( // convert flattened { [id_column]: values } object // to nested filter object newSearchParams.set( - URL_PARAMS.preselectFilters, + URL_PARAMS.preselectFilters.name, JSON.stringify(serializeActiveFilterValues(filters)), ); if (standalone) { - newSearchParams.set(URL_PARAMS.standalone, standalone.toString()); + newSearchParams.set(URL_PARAMS.standalone.name, standalone.toString()); } const hashSection = hash ? `#${hash}` : ''; diff --git a/superset-frontend/src/explore/components/EmbedCodeButton.jsx b/superset-frontend/src/explore/components/EmbedCodeButton.jsx index 24b62ecd11..46eed0bb0c 100644 --- a/superset-frontend/src/explore/components/EmbedCodeButton.jsx +++ b/superset-frontend/src/explore/components/EmbedCodeButton.jsx @@ -69,7 +69,7 @@ export default class EmbedCodeButton extends React.Component { generateEmbedHTML() { const srcLink = `${window.location.origin + getURIDirectory()}?r=${ this.state.shortUrlId - }&${URL_PARAMS.standalone}=1&height=${this.state.height}`; + }&${URL_PARAMS.standalone.name}=1&height=${this.state.height}`; return ( '