Skip to content

Commit

Permalink
Show a warning when clicking 'I fixed it' if embedded Rapid editor ha…
Browse files Browse the repository at this point in the history
…s unsaved changes (#2397)
  • Loading branch information
jake-low authored Aug 12, 2024
1 parent 191ca37 commit 4fe7a69
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 12 deletions.
4 changes: 3 additions & 1 deletion src/components/HOCs/WithEditor/WithEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import AppErrors from '../../../services/Error/AppErrors'
* WithEditor provides an editor prop to its WrappedComponent that contains the
* current open editor (if any) from the redux store and the user's currently
* configured editor (or the system default editor if none is configured), as
* well as functions for interacting with editors
* well as functions for interacting with editors. If the embedded Rapid Editor
* is running, it also provides access to the RapidContext.
*
* @author [Neil Rotstan](https://github.com/nrotstan)
*/
Expand All @@ -25,6 +26,7 @@ export const mapStateToProps = state => {
return ({
editor: state.openEditor,
configuredEditor: _get(userEntity, 'settings.defaultEditor', DEFAULT_EDITOR),
rapidContext: _get(state, 'rapidEditor.context'),
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,18 @@ export class ActiveTaskControls extends Component {
}

initiateCompletion = (taskStatus, submitRevision) => {
this.setState({
confirmingTask: this.props.task,
osmComment: `${this.props.task.parent.checkinComment}${constructChangesetUrl(this.props.task)}`,
confirmingStatus: taskStatus,
submitRevision,
})
const hasUnsavedRapidChanges = this.props.rapidContext?.systems.editor.hasChanges()
const intl = this.props.intl
const message = intl.formatMessage(messages.rapidDiscardUnsavedChanges)

if (!hasUnsavedRapidChanges || window.confirm(message)) {
this.setState({
confirmingTask: this.props.task,
osmComment: `${this.props.task.parent.checkinComment}${constructChangesetUrl(this.props.task)}`,
confirmingStatus: taskStatus,
submitRevision,
})
}
}

confirmCompletion = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,9 @@ export default defineMessages({
id: "Task.controls.viewChangeset.label",
defaultMessage: "View Changeset",
},

rapidDiscardUnsavedChanges: {
id: "Widgets.TaskMapWidget.rapidDiscardUnsavedChanges",
defaultMessage: "You have unsaved changes in Rapid which will be discarded. Are you sure you want to proceed?",
},
})
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const RapidEditor = ({
}) => {
const dispatch = useDispatch();
const [rapidLoaded, setRapidLoaded] = useState(window.Rapid !== undefined);
const { context, dom } = useSelector((state) => state.rapidEditor.rapidContext);
const { context, dom } = useSelector((state) => state.rapidEditor);
const windowInit = typeof window !== 'undefined';

// This significantly reduces build time _and_ means different TM instances can share the same download of Rapid.
Expand Down
6 changes: 2 additions & 4 deletions src/services/RapidEditor/RapidEditor.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
export const SET_RAPIDEDITOR = 'SET_RAPIDEDITOR';

const initialState = {
rapidContext: { context: null, dom: null },
};
const initialState = { context: null, dom: null };

export function rapidEditor(state = initialState, action) {
switch (action.type) {
case SET_RAPIDEDITOR: {
return {
...state,
rapidContext: action.context,
...action.context,
};
}
default:
Expand Down

0 comments on commit 4fe7a69

Please sign in to comment.