(cherry picked from commit 81cf09af9e)
Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
This commit is contained in:
co-authored by
Ashley Harrison
parent
2549519180
commit
dd42424a01
@@ -50,6 +50,22 @@ export const DashboardPrompt = React.memo(({ dashboard }: Props) => {
|
||||
};
|
||||
}, [dashboard]);
|
||||
|
||||
useEffect(() => {
|
||||
const handleUnload = (event: BeforeUnloadEvent) => {
|
||||
if (ignoreChanges(dashboard, original)) {
|
||||
return;
|
||||
}
|
||||
if (hasChanges(dashboard, original)) {
|
||||
event.preventDefault();
|
||||
// No browser actually displays this message anymore.
|
||||
// But Chrome requires it to be defined else the popup won't show.
|
||||
event.returnValue = '';
|
||||
}
|
||||
};
|
||||
window.addEventListener('beforeunload', handleUnload);
|
||||
return () => window.removeEventListener('beforeunload', handleUnload);
|
||||
}, [dashboard, original]);
|
||||
|
||||
// Handle saved events
|
||||
useEffect(() => {
|
||||
const savedEventUnsub = appEvents.subscribe(DashboardSavedEvent, () => {
|
||||
|
||||
Reference in New Issue
Block a user