Repository navigation
Enhance dashboard parameter handling: persist updated values and apply saved parameters - #7570
Conversation
|
I skipped the Restyled check to give the reviewer a chance to look at the code that was changed. I would recommend running |
|
@denisov-vlad Thank you for your PR ! I think the parameters should be saved only when "Done Editing" button is clicked, as the "Done Editing" button is for saving, and it makes the behavior of the Query Editor and the Dashboard Editor consistent. |
There was a problem hiding this comment.
Pull Request Overview
This PR implements the ability to persist dashboard parameter values when the Apply button is clicked. This addresses the need to maintain customized parameter values across dashboard sessions without requiring query cloning or static parameters. The implementation establishes a new parameter precedence order: URL parameters override dashboard-saved parameters, which in turn override query-defined default parameters.
- Introduces parameter value persistence in
dashboard.options.parameterValues - Implements
persistParameterValuesfunction to save parameter updates to the backend - Updates parameter loading to check for saved values before applying defaults
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| client/app/services/dashboard.js | Modified getParametersDefs to load saved parameter values from dashboard options and apply them before URL parameters |
| client/app/pages/dashboards/hooks/useDashboard.js | Added persistParameterValues function and integrated it into the refreshDashboard flow with error handling |
| client/app/pages/dashboards/DashboardPage.jsx | Fixed onParametersEdit to preserve existing dashboard options when updating parameter order |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .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)) |
There was a problem hiding this comment.
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.
| .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 | |
| }) |
There was a problem hiding this comment.
Pull Request Overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Promise.resolve(persistParameterValues(pendingValues)).catch(error => { | ||
| console.error("Failed to persist parameter values:", error); | ||
| notification.error("Parameter values could not be saved. Your changes may not be persisted."); | ||
| pendingParameterValuesRef.current = pendingValues; |
There was a problem hiding this comment.
The error handling here may not work as intended. The updateDashboard function (lines 68-96) catches errors but doesn't re-throw them, meaning the promise resolves successfully even when the save fails. As a result, this catch block will not execute for most failure scenarios (except for cases where Dashboard.save itself rejects), and users won't see the error message or have their pending values restored. Consider modifying the implementation to properly detect and handle save failures.
| pendingParameterValuesRef.current = pendingValues; | |
| pendingParameterValuesRef.current = pendingValues; | |
| throw error; |
| Promise.resolve(persistParameterValues(pendingValues)).catch(error => { | ||
| console.error("Failed to persist parameter values:", error); | ||
| notification.error("Parameter values could not be saved. Your changes may not be persisted."); | ||
| pendingParameterValuesRef.current = pendingValues; |
There was a problem hiding this comment.
There's a potential race condition if the user re-enters edit mode while a persist operation is still in flight. If the persist operation then fails and tries to restore values at line 271, it could overwrite the new edit session's (empty) pending values with old values from the previous session. Consider tracking an edit session ID or timestamp to ensure restored values belong to the current session.
|
@denisov-vlad Thank you for updating. |
Have you tested it? It saves changes only after "Done editing" button click. I had tried to find any other option to save params, but the only way I found is with that button. Also added some info to the PR message. |
|
@denisov-vlad Thank you ! And, I think |
|
@yoshiokatsuneo The logic is consistent with the queries. The parameters are updated in edit mode, but after clicking Apply Changes and then Done Editing. I have now simplified the code a little and removed it from |
|
@denisov-vlad Thank you for updating. The behavior looks good ! How about making it easier to understand ? |
|
@yoshiokatsuneo I hope I understood you correctly. I'm not a developer and haven't explored the front-end code in depth, but I hope everything is okay now. |
yoshiokatsuneo
left a comment
There was a problem hiding this comment.
Thank you for the update !
I added comments.
| @@ -144,16 +154,60 @@ function useDashboard(dashboardData) { | |||
| [loadWidget] | |||
| ); | |||
|
|
|||
| const persistParameterValues = useCallback( | |||
| parameterValues => { | |||
There was a problem hiding this comment.
Can't we just save parameterValues ?
There was a problem hiding this comment.
I'm not sure that it's possible right now. We must update options and there could be globalParamOrder key. With my approach we will save all the keys in this field.
@yoshiokatsuneo I´ve pushed some changes again. Could you check it please? |
|
@yoshiokatsuneo is it ok now? |
|
@denisov-vlad Sorry for late, but I' ll check it out. |
| return updateDashboard({ | ||
| options: { | ||
| ...currentDashboard.options, | ||
| parameterValues: parameterValues, |
There was a problem hiding this comment.
I think it is nice to interface compatible with queries.
So, how about using parameters array as queries.options.parameters like:
options: {
...currentDashboard.options,
parameters: map(data.options.parameters, p => globalParameters.toSaveableObject()),
}
There was a problem hiding this comment.
agree with parameters key and list instead of dict, but used globalParameters instead of data.options.parameters
| @@ -210,10 +210,14 @@ Dashboard.prototype.getParametersDefs = function getParametersDefs() { | |||
| }); | |||
| } | |||
| }); | |||
| const mergedValues = { | |||
| ..._.mapValues(globalParams, p => p.value), | |||
| ...(this.options.parameterValues || {}), | |||
There was a problem hiding this comment.
And, following the parameter interface, I think this line can be below.
...Object.fromEntries((this.options.parameters || {}).map( param => [param.name, param.value]))
There was a problem hiding this comment.
|| [] instead of || {}, but done
|
Is everything okay now? Maybe we can do a merge? I have a big project that's stalled because I'm waiting for these changes. |
|
@denisov-vlad I noticed that the saved parameter have extra "locals" array field in the options.parameters. |
Don't really know how it works, but removing this line disables query update after changing param, so it will be updated only after page refresh, so I prefer to add |
|
@denisov-vlad Ah, sorry. |
|
@yoshiokatsuneo Done. Tested with omitting |
|
@denisov-vlad Thank you! |
|
@eradman I think this PR is good enough, and makes Redash better by enabling to save dashboard parameter. But, I just want to hear your thought to make sure. Thank you. |
|
This is a nice feature, and seems to work well. Also switching the parameter type Text to Dropdown List did not break anything |
|
Applied the prettier changes, if it passes we will rebase |
…y saved parameters
…iting and improve value update logic
…nce of current parameter values
…boardEditControl for improved parameter persistence
…ters and merge parameter values for improved persistence
…d remove unnecessary checks for improved clarity
…s and streamline dashboard options merging
…g for improved clarity and functionality
… and improve clarity
…veable objects for improved clarity and consistency
83e5ad2 to
29c3f97
Compare
|
@denisov-vlad Thank you for your contribution ! |
|
@eradman Thank you for the review and testing ! |
|
Thanks! |
* master: (69 commits) Update Python version to 3.13 (getredash#7636) Update plotly.js to 3.3.1, react-pivottable to 0.11.0 (getredash#7634) Add charset option to RDS MySQL datasource (getredash#7616) Aggregate y value for same x (getredash#7631) fix(mysql): Change default charset to utf8mb4 (getredash#7615) Update packages for compatibility with setuptools 82 (getredash#7622) Snapshot: 26.02.0-dev chore: support ipv6 for server in docker (getredash#7596) Add impersonation option in trino datasource (getredash#7605) Fix Elasticsearch connector configuration key mismatch (getredash#7607) duckdb: Show catalog (database) where applicable (e.g. Motherduck) (getredash#7599) Snapshot: 26.01.0-dev Feature/catch notsupported exception (getredash#7573) Multi-org: format base path, not including protocol (getredash#7260) fix(destinations): Handle unicode characters in webhook notifications (getredash#7586) Persist updated values and apply saved dashboard parameters (getredash#7570) Add ibm-db package to enable DB2 as datasource: (getredash#7581) Snapshot: 25.12.0-dev PostgreSQL: allow connection parameters to be specified (getredash#7579) Add lineShape option for Line and Area charts (getredash#7582) ...
What type of PR is this?
Description
Added support for saving dashboard parameters after clicking the Apply button. This is useful when using query templates and inserting them into different dashboards. Without this logic, there are two solutions: cloning queries or making parameters static.
Now they are used in the following order: url, dashboard parameters, query parameters.
How is this tested?
Related Tickets & Documents
Mobile & Desktop Screenshots/Recordings (if there are UI changes)