-
Notifications
You must be signed in to change notification settings - Fork 11.6k
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: New panel in a dashboard is not deleted after "Discard"-ing changes in Panel Edit #66476
Conversation
@@ -131,6 +132,10 @@ export class PanelEditorUnconnected extends PureComponent<Props> { | |||
}; | |||
|
|||
onDiscard = () => { | |||
// if this is a newly created panel we want to remove it from the dashboard | |||
// todo how do we check it's a new panel? |
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.
not sure you can right now, would have to add some new state to it, I know we have had a "isNew" state before but seems to be gone now.
Just make sure we don't save this new state prop / get's removed when you leave panel edit (without discarding)
} else { | ||
dashboard && removePanel(dashboard, sourcePanel, true); | ||
} | ||
} |
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 is one way of handling the new panel: adding a prop to the model and looking for it when leaving the editing page (because Apply
and going back would not remove the property from the model).
Another way would be to let the Panel Edit page know whether its panel is new (with an "isNew
" URL param e.g.) and let it call removePanel()
on discard. That way we wouldn't have to worry about Apply
and "going back manually" because only the Add
buttons would trigger the URL with isNew
param.
Hello @polibb!
Please, if the current pull request addresses a bug fix, label it with the |
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.
Hey @polibb, fantastic job tackling this challenging issue! 🙌🏾 You've made great progress. I quickly tested it and noticed a small problem.
When editing a panel, if a user saves to the DB and then hits "discard," the changes are still discarded even though they're saved in the database.
DiscardAlsoRemoveChangesWhenTheyAreSavedInBackend.mp4
@axelavargas nice catch! I tried it in play and am seeing this bug easily. However, this PR only solves bug related to a new panel discarding when the panel itself is not discarded as an entity. The discarded changes on an existing panel is in a different area and will need another approach (regardless of the |
…g changes in Panel Edit (#66476) * add isNew notPersistedProperty to PanelModel * if panel is newly created and user "Discard"s it, the panel is removed entirely * add Todo's for when we remove the emptyDashboardPage FF * add isNew to new panel after file dropping on dashboard page * handle the "Apply" case * CSV file dropping is not relevant to a new panel bc it doesnt open edit page (cherry picked from commit fe23c76)
What is this feature?
Remove newly created panel from dashboard when it is discarded during editing it before it is ever saved to the dashboard.
Problem?
How do we distinguish between a panel that was just added to the dashboard and a panel that was always there?
In the first case when we hit "Discard" during editing we want it deleted from the dashboard model, but in the second case we want to only clean up the last changes on it.
We are always adding the panel to the dashboard immediately when creating it, before going to editing it: https://github.com/grafana/grafana/blob/main/public/app/features/dashboard/utils/dashboard.ts#L17
I have added a suggestion about where and which method we might want to use to remove the panel when we hit "Discard", but don't know how to make the distinction between new and existing panel.
Which issue(s) does this PR fix?:
Fixes #65588
Special notes for your reviewer:
Please check that: