Skip to content

SmythOS Studio: Open-Source Visual AI Agent Builder and deployable runtime stack from SmythOS. Start with an intuitive drag-and-drop workspace, extend with custom code, and deploy your agents anywhere — local, cloud, or edge — with full governance and control.

Implement unsaved changes handling and auto-save confirmation in sidebarEditValues function

Muhammad Hamza Khanc20f700641d7
diff --git a/packages/app/src/builder-ui/ui/dialogs.ts b/packages/app/src/builder-ui/ui/dialogs.ts
index 58e4fbf9..39905c7c 100644
--- a/packages/app/src/builder-ui/ui/dialogs.ts
+++ b/packages/app/src/builder-ui/ui/dialogs.ts
@@ -1314,14 +1314,25 @@ export function sidebarEditValues({
if (typeof onSave === 'function') onSave.apply({ sidebar }, [result]);
window['workspace']?.emit?.('componentUpdated', result);
resolve(result);
+ return true;
};
const closeBtn: HTMLButtonElement = sidebar.querySelector('.close-btn');
if (closeBtn) {
closeBtn.onclick = async (e) => {
- // Save on 'x' only for standard single-tab Settings sidebars
+ let saveResult = null;
+ // Check if there are unsaved changes and save them before closing
+ const changed = isSettingsChanged();
+ if (changed) {
+ // Try to save changes before closing
+ saveResult = await performAutoSave(e);
+ if (saveResult === false) {
+ // If save failed due to validation errors, don't close
+ return;
+ }
+ }
- if (typeof onBeforeCancel === 'function') {
+ if (typeof onBeforeCancel === 'function' && !saveResult) {
const canClose = await onBeforeCancel.apply({ sidebar }, [sidebar]);
if (!canClose) return;
}