Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Prevent undo functionality from referencing incorrect dashboard edits #31809

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

fardin-developer
Copy link
Contributor

Fixes #31344

Description

This PR fixes a bug where the "Undo" button displays actions from a previously edited dashboard after switching to a new one. The issue occurred because the dashboardLayout.past array, which stores the undo history, was not cleared when switching between dashboards or entering edit mode.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Before

https://drive.google.com/file/d/1ddAJXwsBFAmTHtpjKqo-fRAzk6fu4aek/view?usp=sharing

After

https://drive.google.com/file/d/1fvomN09d4G_87We-YfOaAurMTTcQ7dAO/view?usp=sharing

Key Changes:

Reset Dashboard History:

Introduced the resetDashboardPast function to ensure the dashboardLayout.past array is cleared when toggling edit mode.
Edit Button Update:

Updated the "Edit Dashboard" button to call the resetDashboardPast function via boundActionCreators.clearDashboardHistory() when clicked.

Reproduction Steps

  • Navigate to a dashboard (Dashboard A).
  • Click "Edit" and make changes. Save the dashboard.
  • Navigate to the dashboard list and select another dashboard (Dashboard B).
  • Click "Edit" on Dashboard B.
  • Press the "Undo" button.

Expected Behavior:

  • The undo button should be disabled when first editing Dashboard B.
  • Undo actions should not reflect changes made in Dashboard A.

…rryover issues. Ensure undo actions apply only to the current dashboard.
@dosubot dosubot bot added the dashboard:editmode Related to te Dashboard edit mode label Jan 12, 2025
Copy link

@korbit-ai korbit-ai bot left a comment

Choose a reason for hiding this comment

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

Review by Korbit AI

Korbit automatically attempts to detect when you fix issues in new commits.
Category Issue Fix Detected
Functionality Improper Redux State Mutation ▹ view

Need a new review? Comment /korbit-review on this PR and I'll review your latest changes.

Korbit Guide: Usage and Customization

Interacting with Korbit

  • You can manually ask Korbit to review your PR using the /korbit-review command in a comment at the root of your PR.
  • You can ask Korbit to generate a new PR description using the /korbit-generate-pr-description command in any comment on your PR.
  • Too many Korbit comments? I can resolve all my comment threads if you use the /korbit-resolve command in any comment on your PR.
  • Chat with Korbit on issues we post by tagging @korbit-ai in your reply.
  • Help train Korbit to improve your reviews by giving a 👍 or 👎 on the comments Korbit posts.

Customizing Korbit

  • Check out our docs on how you can make Korbit work best for you and your team.
  • Customize Korbit for your organization through the Korbit Console.

Feedback and Support

Comment on lines 270 to 275
export function resetDashboardPast() {
return (dispatch, getState) => {
const { dashboardLayout } = getState();
dashboardLayout.past = []; // Set `past` as an empty array
};
}

This comment was marked as resolved.

Copy link
Member

Choose a reason for hiding this comment

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

@fardin-developer I don't think you should edit the state here? Why not in the reducers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

clearing history from redux undo

@@ -668,6 +673,7 @@ const Header = () => {
NavExtension,
boundActionCreators.onRedo,
boundActionCreators.onUndo,
boundActionCreators.clearDashboardHistory(),
Copy link
Member

Choose a reason for hiding this comment

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

You're executing the function in the dependent list

Suggested change
boundActionCreators.clearDashboardHistory(),
boundActionCreators.clearDashboardHistory,

@geido geido requested a review from kgabryje January 15, 2025 18:14
@kgabryje
Copy link
Member

Looks great, once Justin’s comment is addressed it’s good to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dashboard:editmode Related to te Dashboard edit mode size/S
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hitting undo on a dashboard shows last edited dashboard
4 participants