forked from geosolutions-it/geonode-mapstore-client
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix - Duplicated API requests on viewer resource load (#1676) * Enhance link system between map and mapviewers (#1677) * Configuration update for the plugins available inside the context creator (#1675) * #1683: Enable the 3D plugin in the default GeoNode map configuration (#1684) * #1685 - Fix: Mapviewer doesn't show configure plugin steps (#1686) * #1685 - Fix: Mapviewer doesn't show configure plugin steps * Refresh map on unlink viewer resource * #1689: Add a warning when closing an unsaved map viewer (#1690) --------- Co-authored-by: Suren <dsuren1@gmail.com>
- Loading branch information
Showing
6 changed files
with
113 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
geonode_mapstore_client/client/js/plugins/save/withPrompt.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import React, { useRef, useEffect } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { getMessageById } from '@mapstore/framework/utils/LocaleUtils'; | ||
import { Prompt } from 'react-router-dom'; | ||
|
||
|
||
export default (Component) => { | ||
const PromptComponent = (props, {messages}) => { | ||
const dirtyState = useRef(); | ||
dirtyState.current = props.dirtyState; | ||
useEffect(() => { | ||
function onBeforeUnload(event) { | ||
if (dirtyState.current) { | ||
(event || window.event).returnValue = null; | ||
} | ||
} | ||
window.addEventListener('beforeunload', onBeforeUnload); | ||
return () => { | ||
window.removeEventListener('beforeunload', onBeforeUnload); | ||
}; | ||
}, []); | ||
|
||
return props.enabled | ||
? <><Component {...props}/> | ||
<Prompt | ||
when={!!props.dirtyState} | ||
message={(/* nextLocation, action */) => { | ||
const confirmed = window.confirm(getMessageById(messages, 'gnviewer.prompPendingChanges')); // eslint-disable-line no-alert | ||
// if confirm the path should be the next one | ||
if (confirmed) { | ||
return true; | ||
} | ||
window.history.back(); // to return back to previous path | ||
// currently it's not possible to replace the pathname | ||
// without side effect | ||
// such as reloading of the page | ||
return false; | ||
}} | ||
/> | ||
</> | ||
: null | ||
; | ||
}; | ||
|
||
PromptComponent.contextTypes = { | ||
messages: PropTypes.object | ||
}; | ||
return PromptComponent; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters