Skip to content
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

Show a warning when clicking 'I fixed it' if embedded Rapid editor has unsaved changes #2397

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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