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

add re-select task button in rapid iframe #2490

Merged
merged 5 commits into from
Nov 13, 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
5 changes: 5 additions & 0 deletions src/components/Widgets/TaskMapWidget/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ export default defineMessages({
id: "Widgets.TaskMapWidget.rapidFailed",
defaultMessage: "Widget Failed! Geometries Null!",
},

reselectTask: {
id: "Widgets.TaskMapWidget.reselectTask",
defaultMessage: "Re-Select Task",
},
})
19 changes: 18 additions & 1 deletion src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { useDispatch } from 'react-redux';
import _get from 'lodash/get';

Expand All @@ -10,6 +10,8 @@
import useHash from '../../../../hooks/UseHash';
import { SET_RAPIDEDITOR } from '../../../../services/RapidEditor/RapidEditor';
import BusySpinner from '../../../BusySpinner/BusySpinner';
import { FormattedMessage } from 'react-intl';
import messages from './../Messages';

/**
* Generate the initial URL hash for the Rapid editor.
Expand Down Expand Up @@ -42,6 +44,7 @@
const dispatch = useDispatch();
const [isLoading, setIsLoading] = useState(true);
const [error, setError] = useState(null);
const iframeRef = useRef(null); // Create a ref for the iframe

Check warning on line 47 in src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx#L47

Added line #L47 was not covered by tests
let initialHash = generateStartingHash({ task, mapBounds, comment });
let [, setHash] = useHash();

Expand All @@ -63,8 +66,21 @@
initialHash += `&token=${token}`;
}

const handleResetHash = () => {
if (iframeRef.current) {
iframeRef.current.contentWindow.location.hash = initialHash;
}
};

Check warning on line 73 in src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx#L69-L73

Added lines #L69 - L73 were not covered by tests

return (
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
<button
onClick={handleResetHash}
className="mr-ml-auto mr-button mr-button--small mr-px-2"
style={{ position: 'absolute', right: '0px', top: '-40px' }}

Check warning on line 80 in src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx#L77-L80

Added lines #L77 - L80 were not covered by tests
>
<FormattedMessage {...messages.reselectTask} />

Check warning on line 82 in src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx#L82

Added line #L82 was not covered by tests
</button>
{isLoading && (
<div style={{ position: 'absolute', top: 0, left: 0, width: '100%', height: '100%', display: 'flex', justifyContent: 'center', alignItems: 'center', zIndex: 1000 }}>
<BusySpinner xlarge />
Expand All @@ -74,6 +90,7 @@
<div>Error: {error.message}</div>
)}
<iframe
ref={iframeRef}

Check warning on line 93 in src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx

View check run for this annotation

Codecov / codecov/patch

src/components/Widgets/TaskMapWidget/RapidEditor/RapidEditor.jsx#L93

Added line #L93 was not covered by tests
id="rapid-container-root"
style={{ width: '100%', height: '100%' }}
src={`/static/rapid-editor.html${initialHash}`}
Expand Down