Skip to content

Commit

Permalink
Warn users on browser refresh if unsaved changes (#470) (#471)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8c20543)

Signed-off-by: Tyler Ohlsen <[email protected]>
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
1 parent 55e51bc commit 0365306
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 17 additions & 0 deletions public/pages/workflow_detail/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,23 @@ export function WorkflowDetailHeader(props: WorkflowDetailHeaderProps) {
? ingestSaveButtonDisabled
: searchSaveButtonDisabled;

// Add warning when exiting with unsaved changes
function alertFn(e: BeforeUnloadEvent) {
e.preventDefault();
}

// Hook for warning of unsaved changes if a browser refresh is detected
useEffect(() => {
if (!saveDisabled) {
window.addEventListener('beforeunload', alertFn);
} else {
window.removeEventListener('beforeunload', alertFn);
}
return () => {
window.removeEventListener('beforeunload', alertFn);
};
}, [saveDisabled]);

// Utility fn to update the workflow UI config only, based on the current form values.
// A get workflow API call is subsequently run to fetch the updated state.
async function updateWorkflowUiConfig() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ export function QuickConfigureModal(props: QuickConfigureModalProps) {
history.replace(
constructUrlWithParams(
APP_PATH.WORKFLOWS,

workflow.id,
dataSourceId
)
Expand Down

0 comments on commit 0365306

Please sign in to comment.