Skip to content
Snippets Groups Projects
Unverified Commit 99e9e330 authored by Alexander Polyankin's avatar Alexander Polyankin Committed by GitHub
Browse files

Do not reset filters when saving, cancelling, refreshing dashboards periodically (#17165)

parent a9dd888e
No related branches found
No related tags found
No related merge requests found
......@@ -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`
......
......@@ -128,6 +128,7 @@ export default class DashboardHeader extends Component {
this.props.fetchDashboard(
this.props.dashboard.id,
this.props.location.query,
true,
);
}
......
......@@ -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,
......
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment