Skip to content

Commit

Permalink
Warn users on browser refresh if unsaved changes (#470)
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Ohlsen <[email protected]>
  • Loading branch information
ohltyler authored Nov 7, 2024
1 parent 69c3406 commit 8c20543
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 8c20543

Please sign in to comment.