Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/app/pages/dashboards/DashboardPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ function DashboardComponent(props) {
const [bottomPanelStyles, setBottomPanelStyles] = useState({});
const onParametersEdit = parameters => {
const paramOrder = map(parameters, "name");
updateDashboard({ options: { globalParamOrder: paramOrder } });
updateDashboard({ options: { ...(dashboard.options || {}), globalParamOrder: paramOrder } });
};

useEffect(() => {
Expand Down
51 changes: 46 additions & 5 deletions client/app/pages/dashboards/hooks/useDashboard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect, useMemo, useCallback, useRef } from "react";
import { isEmpty, includes, compact, map, has, pick, keys, extend, every, get } from "lodash";
import { isEmpty, includes, compact, map, has, pick, keys, extend, every, get, isEqual } from "lodash";
import notification from "@/services/notification";
import location from "@/services/location";
import url from "@/services/url";
Expand Down Expand Up @@ -144,14 +144,55 @@ function useDashboard(dashboardData) {
[loadWidget]
);

const persistParameterValues = useCallback(
updatedParameters => {
if (!canEditDashboard || isEmpty(updatedParameters)) {
return Promise.resolve();
}

const currentDashboard = dashboardRef.current;
const currentValues = get(currentDashboard, "options.parameterValues", {});
const nextValues = extend({}, currentValues);
let hasChanges = false;

updatedParameters.forEach(param => {
if (!param) {
return;
}

if (!isEqual(nextValues[param.name], param.value)) {
nextValues[param.name] = param.value;
hasChanges = true;
}
});

if (!hasChanges) {
return Promise.resolve();
}

return updateDashboard({
options: extend({}, get(currentDashboard, "options", {}), { parameterValues: nextValues }),
});
},
[canEditDashboard, updateDashboard]
);

const refreshDashboard = useCallback(
updatedParameters => {
if (!refreshing) {
setRefreshing(true);
loadDashboard(true, updatedParameters).finally(() => setRefreshing(false));
if (refreshing) {
return;
}

setRefreshing(true);
Promise.resolve(persistParameterValues(updatedParameters))
.catch(error => {
console.error("Failed to persist parameter values:", error);
notification.error("Parameter values could not be saved. Your changes may not be persisted.");
})
.then(() => loadDashboard(true, updatedParameters))
Copy link

Copilot AI Nov 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error in persistParameterValues is caught but the promise chain continues to loadDashboard even if persistence fails. This means the dashboard will refresh with new values that haven't been saved. Consider returning early or skipping the refresh if persistence fails to prevent showing unsaved state.

Suggested change
.catch(error => {
console.error("Failed to persist parameter values:", error);
notification.error("Parameter values could not be saved. Your changes may not be persisted.");
})
.then(() => loadDashboard(true, updatedParameters))
.then(() => {
// Only refresh dashboard if persistence succeeded
loadDashboard(true, updatedParameters);
})
.catch(error => {
console.error("Failed to persist parameter values:", error);
notification.error("Parameter values could not be saved. Your changes may not be persisted.");
// Do not refresh dashboard if persistence failed
})

Copilot uses AI. Check for mistakes.
.finally(() => setRefreshing(false));
},
[refreshing, loadDashboard]
[refreshing, loadDashboard, persistParameterValues]
);

const archiveDashboard = useCallback(() => {
Expand Down
6 changes: 5 additions & 1 deletion client/app/services/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ Dashboard.prototype.getParametersDefs = function getParametersDefs() {
});
}
});
const savedParameterValues = _.get(this, "options.parameterValues", {});
const resultingGlobalParams = _.values(
_.each(globalParams, param => {
param.setValue(param.value); // apply global param value to all locals
const valueToApply = _.has(savedParameterValues, param.name)
? savedParameterValues[param.name]
: param.value;
param.setValue(valueToApply); // apply global param value (saved or default) to all locals
param.fromUrlParams(queryParams); // try to initialize from url (may do nothing)
})
);
Expand Down
Loading