Skip to content

fix: warn before closing Generate YAML form with unsaved changes (DE-903)#1711

Open
skwowet wants to merge 1 commit intomainfrom
bugfix/DE-903
Open

fix: warn before closing Generate YAML form with unsaved changes (DE-903)#1711
skwowet wants to merge 1 commit intomainfrom
bugfix/DE-903

Conversation

@skwowet
Copy link
Collaborator

@skwowet skwowet commented Feb 26, 2026

Summary

  • Warn users about unsaved changes in the Generate YAML modal.
  • Show a confirmation dialog when closing via Escape, clicking outside, or the X button.
  • Add a beforeunload listener to prevent data loss on page refresh when the form is dirty.

Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
@skwowet skwowet self-assigned this Feb 26, 2026
Copilot AI review requested due to automatic review settings February 26, 2026 14:20
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds unsaved-change protection to the “Generate YAML security file” modal to reduce accidental data loss during modal dismissal and page unload.

Changes:

  • Adds closeFunction handling to intercept Escape / click-outside closes with a confirmation prompt.
  • Updates the header close (X) button to use the same confirmation flow.
  • Adds a beforeunload listener when the form is considered “dirty” to warn on refresh/navigation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +178 to +203
const hasUnsavedChanges = computed(() => !!type.value);

const confirmClose = (): boolean => {
if (!hasUnsavedChanges.value) return true;
return window.confirm('You have unsaved changes. Are you sure you want to close? All progress will be lost.');
};

const handleClose = () => {
if (confirmClose()) {
isModalOpen.value = false;
}
};

const onBeforeUnload = (event: BeforeUnloadEvent) => {
if (hasUnsavedChanges.value) {
event.preventDefault();
}
};

watch(hasUnsavedChanges, (dirty) => {
if (dirty) {
window.addEventListener('beforeunload', onBeforeUnload);
} else {
window.removeEventListener('beforeunload', onBeforeUnload);
}
});
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hasUnsavedChanges only depends on type, so once a user selects a template the beforeunload listener remains active even after the modal is closed (and also after closing via overlay/Escape through closeFunction). This can cause an unload warning when the modal isn’t open. Consider tying the dirty state to isModalOpen (e.g., only warn when open), or clearing/resetting type/step/form (and thus removing the listener) whenever the modal closes.

Copilot uses AI. Check for mistakes.

const onBeforeUnload = (event: BeforeUnloadEvent) => {
if (hasUnsavedChanges.value) {
event.preventDefault();
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The beforeunload handler calls event.preventDefault(), but most browsers only show the confirmation prompt if event.returnValue is also set (typically to an empty string). Update the handler to set event.returnValue when hasUnsavedChanges is true so the refresh/navigation warning reliably appears.

Suggested change
event.preventDefault();
event.preventDefault();
event.returnValue = '';

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants