diff --git a/frontend/src/metabase/dashboard/actions.js b/frontend/src/metabase/dashboard/actions.js index 0ceab86605032135197d430a93824c561e6e9240..a6dcf4b924acc7c1d987d8bacb78ce32f1e405a9 100644 --- a/frontend/src/metabase/dashboard/actions.js +++ b/frontend/src/metabase/dashboard/actions.js @@ -21,6 +21,7 @@ import { getParameterValuesBySlug, getParameterValuesByIdFromQueryParams, removeDefaultedParametersWithEmptyStringValue, + getParameterValuesByIdFromPreviousValues, } from "metabase/meta/Parameter"; import * as Urls from "metabase/lib/urls"; @@ -382,7 +383,7 @@ export const saveDashboardAndCards = createThunkAction( await dispatch(Dashboards.actions.update(dashboard)); // make sure that we've fully cleared out any dirty state from editing (this is overkill, but simple) - dispatch(fetchDashboard(dashboard.id, null, true)); // disable using query parameters when saving + dispatch(fetchDashboard(dashboard.id, null)); // disable using query parameters when saving }; }, ); @@ -596,6 +597,7 @@ export const markCardAsSlow = createAction(MARK_CARD_AS_SLOW, card => ({ export const fetchDashboard = createThunkAction(FETCH_DASHBOARD, function( dashId, queryParams, + preserveParameters, ) { let result; return async function(dispatch, getState) { @@ -665,11 +667,16 @@ export const fetchDashboard = createThunkAction(FETCH_DASHBOARD, function( dispatch(addFields(result.param_fields)); } - const parameterValuesById = getParameterValuesByIdFromQueryParams( - result.parameters, - queryParams, - removeDefaultedParametersWithEmptyStringValue, - ); + const parameterValuesById = preserveParameters + ? getParameterValuesByIdFromPreviousValues( + result.parameters, + getParameterValues(getState()), + ) + : getParameterValuesByIdFromQueryParams( + result.parameters, + queryParams, + removeDefaultedParametersWithEmptyStringValue, + ); return { ...normalize(result, dashboard), // includes `result` and `entities` diff --git a/frontend/src/metabase/dashboard/components/DashboardHeader.jsx b/frontend/src/metabase/dashboard/components/DashboardHeader.jsx index a6e406be0ea63b201c59aa682c44a35e4475926c..7afb4afa78153444fea4275b61102c004de3dc8a 100644 --- a/frontend/src/metabase/dashboard/components/DashboardHeader.jsx +++ b/frontend/src/metabase/dashboard/components/DashboardHeader.jsx @@ -128,6 +128,7 @@ export default class DashboardHeader extends Component { this.props.fetchDashboard( this.props.dashboard.id, this.props.location.query, + true, ); } diff --git a/frontend/src/metabase/dashboard/hoc/DashboardControls.jsx b/frontend/src/metabase/dashboard/hoc/DashboardControls.jsx index 324367d054bc892395122095843fc8af94b5ffb0..97d8a12b32d28863d353ab410ca6353de43580ae 100644 --- a/frontend/src/metabase/dashboard/hoc/DashboardControls.jsx +++ b/frontend/src/metabase/dashboard/hoc/DashboardControls.jsx @@ -189,6 +189,7 @@ export default (ComposedComponent: React.Class) => await this.props.fetchDashboard( this.props.dashboardId, this.props.location.query, + true, ); this.props.fetchDashboardCardData({ reload: true, diff --git a/frontend/src/metabase/meta/Parameter.js b/frontend/src/metabase/meta/Parameter.js index bbea324a2f16383a4598c1cd718f3e52703a81ec..fe3e79b052d1fc08ba7b175a949b27d90225690e 100644 --- a/frontend/src/metabase/meta/Parameter.js +++ b/frontend/src/metabase/meta/Parameter.js @@ -698,6 +698,17 @@ export function getParameterValuesByIdFromQueryParams( return Object.fromEntries(idValuePairs); } +export function getParameterValuesByIdFromPreviousValues( + parameters, + parameterValues, +) { + const parameterEntries = parameters + .map(p => [p.id, parameterValues[p.id]]) + .filter(([id, value]) => value != null); + + return Object.fromEntries(parameterEntries); +} + export function getParameterValuesBySlug( parameters, parameterValuesById,