Skip to content

Enhance dashboard parameter handling: persist updated values and apply saved parameters - #7570

Merged
eradman merged 13 commits into
getredash:masterfrom
vladenisov:save-dashboard-parameters
Dec 12, 2025
Merged

eradman merged 13 commits into
getredash:masterfrom
vladenisov:save-dashboard-parameters

Conversation

@vladenisov

@vladenisov vladenisov commented Nov 12, 2025 •

Copy link
Copy Markdown
Member

What type of PR is this?

  • Refactor
  • Feature
  • Bug Fix
  • New Query Runner (Data Source)
  • New Alert Destination
  • Other

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.

  • Queue dashboard-level parameter edits while the dashboard is in edit mode.
  • Persist the queued values only when “Done Editing” is clicked, keeping Query and Dashboard editors aligned.
  • Surface any save failures via notifications and restore the queued values so nothing is lost silently.

How is this tested?

  • Unit tests (pytest, jest)
  • E2E Tests (Cypress)
  • Manually
  • N/A
  1. Create query with params
  2. Create dashboard and add query widget there
  3. Check the default value and change it
  4. Open new dashboard from dashboards list
  5. You'll see changed value

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings (if there are UI changes)

@vladenisov
vladenisov marked this pull request as ready for review November 12, 2025 11:40
@vladenisov

Copy link
Copy Markdown
Member Author

I skipped the Restyled check to give the reviewer a chance to look at the code that was changed.

I would recommend running yarn prettier separately to change all files in the repository.

@yoshiokatsuneo

Copy link
Copy Markdown
Contributor

@denisov-vlad

Thank you for your PR !
I also see this issue, and feel annoying. It is cool that you are trying to fix the issue !

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 persistParameterValues function 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.

Comment on lines +188 to +192
.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))

Copilot AI Nov 14, 2025

Copy link

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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;

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Suggested change
pendingParameterValuesRef.current = pendingValues;
pendingParameterValuesRef.current = pendingValues;
throw error;

Copilot uses AI. Check for mistakes.
Comment on lines +268 to +271
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;

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@yoshiokatsuneo

Copy link
Copy Markdown
Contributor

@denisov-vlad

Thank you for updating.
And again, I think the parameters should be saved only when "Done Editing" button(Not "Apply Changes" 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.

@vladenisov

vladenisov commented Nov 14, 2025 •

Copy link
Copy Markdown
Member Author

@denisov-vlad

Thank you for updating. And again, I think the parameters should be saved only when "Done Editing" button(Not "Apply Changes" 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.

Hi @yoshiokatsuneo

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.

@yoshiokatsuneo

Copy link
Copy Markdown
Contributor

@denisov-vlad

Thank you !
I'm sorry I was wrong. The PR is actually working as described.

And, I think refreshDashboard() function should just refresh dashboard as named. How about ?

@vladenisov

vladenisov commented Nov 17, 2025 •

Copy link
Copy Markdown
Member Author

@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 refreshDashboard.

@yoshiokatsuneo

Copy link
Copy Markdown
Contributor

@denisov-vlad

Thank you for updating. The behavior looks good !
And for about the code, I think it is a bit unclear from the code when the parameters are saved.

How about making it easier to understand ?
For example, how about saving the parameter on onclick event handler of "Done Editing" button so that people can see the flow ?

@vladenisov

Copy link
Copy Markdown
Member Author

@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 yoshiokatsuneo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for the update !
I added comments.

@@ -144,16 +154,60 @@ function useDashboard(dashboardData) {
[loadWidget]
);

const persistParameterValues = useCallback(
parameterValues => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can't we just save parameterValues ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Comment thread client/app/services/dashboard.js Resolved
@vladenisov

Copy link
Copy Markdown
Member Author

Thank you for the update ! I added comments.

@yoshiokatsuneo I´ve pushed some changes again. Could you check it please?

Comment thread client/app/services/dashboard.js Resolved
@vladenisov

Copy link
Copy Markdown
Member Author

@yoshiokatsuneo is it ok now?

@yoshiokatsuneo

Copy link
Copy Markdown
Contributor

@denisov-vlad Sorry for late, but I' ll check it out.

Comment thread client/app/services/dashboard.js Resolved
return updateDashboard({
options: {
...currentDashboard.options,
parameterValues: parameterValues,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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()),
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

agree with parameters key and list instead of dict, but used globalParameters instead of data.options.parameters

Comment thread client/app/services/dashboard.js Outdated
@@ -210,10 +210,14 @@ Dashboard.prototype.getParametersDefs = function getParametersDefs() {
});
}
});
const mergedValues = {
..._.mapValues(globalParams, p => p.value),
...(this.options.parameterValues || {}),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And, following the parameter interface, I think this line can be below.

...Object.fromEntries((this.options.parameters || {}).map( param => [param.name, param.value]))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

|| [] instead of || {}, but done

@vladenisov

Copy link
Copy Markdown
Member Author

Hi @yoshiokatsuneo

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.

@yoshiokatsuneo

yoshiokatsuneo commented Dec 4, 2025 •

Copy link
Copy Markdown
Contributor

@denisov-vlad
Sorry for late. I was a bit busy.

I noticed that the saved parameter have extra "locals" array field in the options.parameters.
For example, how about removing following lines from getParametersDefs function not to save the extra "locals" field ?

            // add to locals list
            globalParams[mapping.mapTo].locals.push(param);

@vladenisov

vladenisov commented Dec 5, 2025 •

Copy link
Copy Markdown
Member Author

@denisov-vlad Sorry for late. I was a bit busy.

I noticed that the saved parameter have extra "locals" array field in the options.parameters. For example, how about removing following lines from getParametersDefs function not to save the extra "locals" field ?

            // add to locals list
            globalParams[mapping.mapTo].locals.push(param);

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 locals for now.

@yoshiokatsuneo

Copy link
Copy Markdown
Contributor

@denisov-vlad

Ah, sorry.
How about adding "locals" to the omit list at the toSaveableObject function in the Parameter class like below not to save needless "locals" field ?
(client/app/services/parameters/Parameter.js)

  /** Get a saveable version of the Parameter by omitting unnecessary props */
  toSaveableObject() {
    return omit(this, ["$$value", "urlPrefix", "pendingValue", "parentQueryId", "locals"]);
  }

@vladenisov

Copy link
Copy Markdown
Member Author

@yoshiokatsuneo Done. Tested with omitting locals and everything works fine.

@yoshiokatsuneo

Copy link
Copy Markdown
Contributor

@denisov-vlad Thank you!

@yoshiokatsuneo

Copy link
Copy Markdown
Contributor

@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.
How do you feel about the PR?

Thank you.

@eradman

eradman commented Dec 11, 2025

Copy link
Copy Markdown
Collaborator

This is a nice feature, and seems to work well. Also switching the parameter type Text to Dropdown List did not break anything

postgres=# select jsonb_pretty(options) from dashboards;
-[ RECORD 1 ]+-------------------------------------------
jsonb_pretty | {                                         +
             |     "parameters": [                       +
             |         {                                 +
             |             "name": "type",               +
             |             "type": "enum",               +
             |             "title": "type",              +
             |             "value": "Mac OS",            +
             |             "global": false,              +
             |             "enumOptions": "Linux\nMac OS"+
             |         }                                 +
             |     ]                                     +
             | }

postgres=# select jsonb_pretty(options) from queries;
-[ RECORD 1 ]+-------------------------------------------
jsonb_pretty | {                                         +
             |     "parameters": [                       +
             |         {                                 +
             |             "name": "type",               +
             |             "type": "enum",               +
             |             "title": "type",              +
             |             "value": "Linux",             +
             |             "global": false,              +
             |             "enumOptions": "Linux\nMac OS"+
             |         }                                 +
             |     ],                                    +
             |     "apply_auto_limit": true              +
             | }

eradman
eradman previously approved these changes Dec 11, 2025
@eradman

eradman commented Dec 12, 2025

Copy link
Copy Markdown
Collaborator

Applied the prettier changes, if it passes we will rebase

vladenisov and others added 13 commits December 11, 2025 20:26
…boardEditControl for improved parameter persistence
…ters and merge parameter values for improved persistence
…d remove unnecessary checks for improved clarity
…veable objects for improved clarity and consistency
@eradman
eradman force-pushed the save-dashboard-parameters branch from 83e5ad2 to 29c3f97 Compare December 12, 2025 01:26
@eradman
eradman enabled auto-merge (squash) December 12, 2025 01:38
@eradman
eradman merged commit 4353a82 into getredash:master Dec 12, 2025
@yoshiokatsuneo

Copy link
Copy Markdown
Contributor

@denisov-vlad Thank you for your contribution !

@yoshiokatsuneo

Copy link
Copy Markdown
Contributor

@eradman Thank you for the review and testing !

@vladenisov

Copy link
Copy Markdown
Member Author

Thanks!

woogakoki added a commit to wooga/redash that referenced this pull request Feb 25, 2026
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants