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

Refactor to reuse logic from ChangeTracker #87417

Conversation

ivanortegaalba
Copy link
Contributor

No description provided.

@ivanortegaalba ivanortegaalba requested a review from a team as a code owner May 7, 2024 08:57
@ivanortegaalba ivanortegaalba requested review from axelavargas and dprokop and removed request for a team and axelavargas May 7, 2024 08:57
this.setState({ isDirty: diffCount > 0 });
private _onActivate() {
this.loadDataSource();
const changesSub = this.subscribeToEvent(SceneObjectStateChangedEvent, this._handleStateChange);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the events bubble up, we don't need to subscribe to any children, we can subscribe to the VizPanelManager

}, 250);

private _handleStateChange = (event: SceneObjectStateChangedEvent) => {
if (!Object.prototype.hasOwnProperty.call(event.payload.partialUpdate, 'data')) {
this._updateDirty();
if (DashboardSceneChangeTracker.isUpdatingPersistedState(event)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added it as static, to keep all the logic about what changes affects the persisted state in a single place

Copy link
Member

@dprokop dprokop left a comment

Choose a reason for hiding this comment

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

Looks good, but I found one thing that's a bit confusing. This applies when a new panel is added:

  1. Add panel to dashboard
  2. Discard changes and Save buttons are active.
  3. Click Discard and the panel is still added to a dashboard.

Similarly, when refreshing page with panel edit active Save button is active (migrations), but the Discard is deactivated.
This is a bit confusing, not sure what we can do about it.

Comment on lines +110 to +115
private _detectPanelModelChanges = debounce(() => {
const { hasChanges } = getPanelChanges(
vizPanelToPanel(this.state.sourcePanel.resolve()),
vizPanelToPanel(this.state.panel)
);
this.setState({ isDirty: hasChanges });
Copy link
Member

Choose a reason for hiding this comment

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

Should we add some tests for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I agree. This was a poc PR on Oscar's PR to approach the issue, I'll add those test in the original PR 😄

@ivanortegaalba
Copy link
Contributor Author

Looks good, but I found one thing that's a bit confusing. This applies when a new panel is added:

  1. Add panel to dashboard
  2. Discard changes and Save buttons are active.
  3. Click Discard and the panel is still added to a dashboard.

Similarly, when refreshing page with panel edit active Save button is active (migrations), but the Discard is deactivated. This is a bit confusing, not sure what we can do about it.

This is a great finding Dominik, I'll solve this in Oscar's PR. IMO, the discard should not add the panel to the dashboard 👍

Similarly, when refreshing page with panel edit active Save button is active (migrations), but the Discard is deactivated.
About this one, we can't do much, because the save button is enabled because somewhere else has changes. But not the dashboard.
This is one of the reasons why I'd replace "Save Dashboard" to "Apply changes" and commit the panels changes only if that button is hit.

So, I'd not focus on solving this issue of enabling the save button, because we don't really have a way to avoid it. Unless we don't display the save dashboard when editing a panel.

@ivanortegaalba ivanortegaalba added no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes labels May 7, 2024
@ivanortegaalba ivanortegaalba merged commit 8a3417e into oscark/implement-discard-panel-changes-disable-and-enable May 7, 2024
13 of 14 checks passed
@ivanortegaalba ivanortegaalba deleted the iortega/poc-reuse-logic-for-changes-detection branch May 7, 2024 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/frontend no-backport Skip backport of PR no-changelog Skip including change in changelog/release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants