mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
DashboardPrompt: Implement beforeunload handler (#37490)
This commit is contained in:
parent
4da398014f
commit
81cf09af9e
@ -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, () => {
|
||||
|
Loading…
Reference in New Issue
Block a user