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
Dashboard scene: Discard panel changes disabled/enabled depending of changes #87137
Dashboard scene: Discard panel changes disabled/enabled depending of changes #87137
Conversation
Hello @oscarkilhed!
Please, if the current pull request addresses a bug fix, label it with the |
This PR must be merged before a backport PR will be created. |
this._changeSubs.concat([ | ||
this.queryRunner.subscribeToState(this._updateDirty), | ||
this.dataTransformer.subscribeToState(this._updateDirty), | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was testing this with live data. I was afraid of causing too many calls to this._updateDirty
when streaming. But I found the streaming doesn't work when editing a panel in scenes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was testing wrong, but yes, this is diffing the panel edit for each of the streaming budgets. Why do we need to check the data state? That data is never persisted, right? Probably we just need to check the transforms. We could use something like we do in DashboardScene:
this._changeTrackerSub = this._dashboard.subscribeToEvent(
SceneObjectStateChangedEvent,
this.onStateChanged.bind(this)
);
Then in the callback we could check the changed stuff, and only run the diff when needed:
private onStateChanged({ payload }: SceneObjectStateChangedEvent) {
// If there are no changes in the state, the check is not needed
if (Object.keys(payload.partialUpdate).length === 0) {
return;
}
// SceneQueryRunner includes the DS configuration
if (payload.changedObject instanceof SceneQueryRunner) {
if (!Object.prototype.hasOwnProperty.call(payload.partialUpdate, 'data')) {
return this.detectSaveModelChanges();
}
}
// SceneDataTransformer includes the transformation configuration
if (payload.changedObject instanceof SceneDataTransformer) {
if (!Object.prototype.hasOwnProperty.call(payload.partialUpdate, 'data')) {
return this.detectSaveModelChanges();
}
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try this
@@ -178,12 +180,17 @@ jest.mock('@grafana/runtime', () => ({ | |||
}, | |||
})); | |||
|
|||
mockTransformationsRegistry([calculateFieldTransformer]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing flakiness when resolving all timers
…le' of https://github.com/grafana/grafana into oscark/implement-discard-panel-changes-disable-and-enable
…ard-panel-changes-disable-and-enable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works as expected. Great that you managed to reuse the code from the dashboard change detection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good. Tested locally and discard panel button works as intended now.
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-87137-to-v11.0.x origin/v11.0.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x c3936bbae2e1327194e66d0bb14e110b52a60609 When the conflicts are resolved, stage and commit the changes:
If you have the GitHub CLI installed: # Push the branch to GitHub:
git push --set-upstream origin backport-87137-to-v11.0.x
# Create the PR body template
PR_BODY=$(gh pr view 87137 --json body --template 'Backport c3936bbae2e1327194e66d0bb14e110b52a60609 from #87137{{ "\n\n---\n\n" }}{{ index . "body" }}')
# Create the PR on GitHub
echo "${PR_BODY}" | gh pr create --title "[v11.0.x] Dashboard scene: Discard panel changes disabled/enabled depending of changes" --body-file - --label "type/bug" --label "area/frontend" --label "no-changelog" --label "area/scenes" --label "backport" --base v11.0.x --milestone 11.0.x --web Or, if you don't have the GitHub CLI installed (we recommend you install it!): # Push the branch to GitHub:
git push --set-upstream origin backport-87137-to-v11.0.x
# Create a pull request where the `base` branch is `v11.0.x` and the `compare`/`head` branch is `backport-87137-to-v11.0.x`.
# Remove the local backport branch
git switch main
git branch -D backport-87137-to-v11.0.x |
…ending of changes (#87570) * DashboardScene: Discard panel changes disabled/enabled depending of changes (#87137) --------- Co-authored-by: Ivan Ortega Alba <ivanortegaalba@gmail.com> Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com> (cherry picked from commit c3936bb) * Add line number --------- Co-authored-by: Oscar Kilhed <oscar.kilhed@grafana.com>
What is this feature?
Screen.Recording.2024-04-30.at.16.38.42.mov
This enables and disables the discard panel changes button depending on if the panel has been changed.
The comparison by converting to
Panel
and then running it through jsonDiff similar to what we do to detect dashboard changes might be a bit heavy handed, but it feels fairly robust.Fixes #86974