Skip to content

Commit

Permalink
fix(ui): Do not auto-reload doc.location. Fixes argoproj#4530 (argopr…
Browse files Browse the repository at this point in the history
…oj#4535)

Signed-off-by: Alex Collins <alex_collins@intuit.com>
Signed-off-by: Alex Capras <alexcapras@gmail.com>
  • Loading branch information
alexec authored and alexcapras committed Dec 2, 2020
1 parent 704b087 commit aa232fc
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions ui/src/app/shared/components/error-notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,27 @@ export const ErrorNotice = (props: {style?: CSSProperties; error: Error & {respo
const reloadAfterSeconds = props.reloadAfterSeconds || 120;
const reload = props.onReload || document.location.reload;
const [timeLeft, setTimeLeft] = useState(reloadAfterSeconds);
useEffect(() => {
if (!timeLeft) {
reload();
setTimeLeft(reloadAfterSeconds);
}
const intervalId = setInterval(() => {
setTimeLeft(timeLeft - 1);
}, 1000);
return () => clearInterval(intervalId);
}, [timeLeft]);
const canAutoReload = reload !== document.location.reload; // we cannot automatically call `document.location.reload`
if (canAutoReload) {
useEffect(() => {
if (!timeLeft) {
reload();
setTimeLeft(reloadAfterSeconds);
}
const intervalId = setInterval(() => {
setTimeLeft(timeLeft - 1);
}, 1000);
return () => clearInterval(intervalId);
}, [timeLeft]);
}
return (
<Notice style={props.style}>
<PhaseIcon value='Error' /> {props.error.message || 'Unknown error. Open your browser error console for more information.'}
{props.error.response && props.error.response.body && props.error.response.body.message && ': ' + props.error.response.body.message}:{' '}
<a onClick={() => reload()}>
<i className='fa fa-redo' /> Reload
</a>{' '}
{timeLeft}s
{canAutoReload && `${timeLeft}s`}
</Notice>
);
};

0 comments on commit aa232fc

Please sign in to comment.