From 5874f1cc7a2a3c5689eadf4a73c0e1b35891986c Mon Sep 17 00:00:00 2001 From: rob Date: Wed, 11 Mar 2026 00:59:37 -0300 Subject: [PATCH] Keep strategy dialog open on save failure Previously the dialog closed immediately after submitting, before knowing if the save succeeded. If there was an error (e.g., duplicate name), users had to recreate their entire strategy. Now the dialog only closes on success, and shows a helpful error message on failure so users can fix the issue without losing work. Co-Authored-By: Claude Opus 4.5 --- src/static/Strategies.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/static/Strategies.js b/src/static/Strategies.js index 991af5c..7c0a39d 100644 --- a/src/static/Strategies.js +++ b/src/static/Strategies.js @@ -1461,9 +1461,17 @@ class Strategies { if (data.success && data.strategy) { this.dataManager.addNewStrategy(data.strategy); this.uiManager.updateStrategiesHtml(this.dataManager.getAllStrategies()); + // Close the dialog only on success + this.uiManager.hideForm(); } else { console.error("Failed to create strategy:", data.message); - alert(`Strategy creation failed: ${data.message}`); + // Keep dialog open and show error - user can fix the issue + const errorMsg = data.message || 'Unknown error'; + if (errorMsg.toLowerCase().includes('name') || errorMsg.toLowerCase().includes('exists')) { + alert(`Strategy name already exists. Please choose a different name.`); + } else { + alert(`Strategy creation failed: ${errorMsg}`); + } } } @@ -1475,6 +1483,9 @@ class Strategies { if (data.success) { console.log("Strategy updated successfully:", data); + // Close the dialog on success + this.uiManager.hideForm(); + // Locate the strategy in the local state by its tbl_key const updatedStrategyKey = data.strategy.tbl_key; const updatedAt = data.updated_at; @@ -1523,7 +1534,13 @@ class Strategies { } } else { console.error("Failed to update strategy:", data.message); - alert(`Strategy update failed: ${data.message}`); + // Keep dialog open and show error - user can fix the issue + const errorMsg = data.message || 'Unknown error'; + if (errorMsg.toLowerCase().includes('name') || errorMsg.toLowerCase().includes('exists')) { + alert(`Strategy name already exists. Please choose a different name.`); + } else { + alert(`Strategy update failed: ${errorMsg}`); + } } } @@ -1704,7 +1721,8 @@ class Strategies { // Determine message type based on action const messageType = action === 'new' ? 'new_strategy' : 'edit_strategy'; this.comms.sendToApp(messageType, strategyData); - this.uiManager.hideForm(); + // Don't hide form here - wait for server response + // Form will be hidden in handleStrategyCreated/handleStrategyUpdated on success } else { console.error("Comms instance not available or invalid action type."); }