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

Warn users on browser refresh if unsaved changes #470

Merged
merged 1 commit into from
Nov 7, 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
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
Loading