From 0a02e526ee36163052e35c6fe5888a0e630eb7cb Mon Sep 17 00:00:00 2001 From: Luis de Dios Date: Thu, 7 Aug 2025 07:41:07 +0200 Subject: [PATCH] :sparkles: Treat empty names as a malformed formula (#7073) --- .../app/common/logic/variant_properties.cljc | 2 +- .../src/app/main/data/workspace/variants.cljs | 38 ++++++++++--------- .../main/ui/workspace/sidebar/layer_name.cljs | 2 +- .../sidebar/options/menus/component.cljs | 2 +- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/common/src/app/common/logic/variant_properties.cljc b/common/src/app/common/logic/variant_properties.cljc index 65f7fd8be3..499a4f487f 100644 --- a/common/src/app/common/logic/variant_properties.cljc +++ b/common/src/app/common/logic/variant_properties.cljc @@ -71,7 +71,7 @@ component (ctcl/get-component data component-id true) main-id (:main-instance-id component)] (-> changes - (pcb/update-shapes [main-id] (if (str/blank? value) + (pcb/update-shapes [main-id] (if (nil? value) #(dissoc % :variant-error) #(assoc % :variant-error value)))))) diff --git a/frontend/src/app/main/data/workspace/variants.cljs b/frontend/src/app/main/data/workspace/variants.cljs index 8733abda7f..c9834b847a 100644 --- a/frontend/src/app/main/data/workspace/variants.cljs +++ b/frontend/src/app/main/data/workspace/variants.cljs @@ -135,25 +135,27 @@ (defn update-error - "Updates the error in a component" - [component-id value] - (ptk/reify ::update-error - ptk/WatchEvent - (watch [it state _] - (let [page-id (:current-page-id state) - data (dsh/lookup-file-data state) - objects (-> (dsh/get-page data page-id) - (get :objects)) + "Sets or unsets an error for a component" + ([component-id] + (update-error component-id nil)) + ([component-id value] + (ptk/reify ::update-error + ptk/WatchEvent + (watch [it state _] + (let [page-id (:current-page-id state) + data (dsh/lookup-file-data state) + objects (-> (dsh/get-page data page-id) + (get :objects)) - changes (-> (pcb/empty-changes it page-id) - (pcb/with-library-data data) - (pcb/with-objects objects) - (clvp/generate-set-variant-error component-id value)) - undo-id (js/Symbol)] - (rx/of - (dwu/start-undo-transaction undo-id) - (dch/commit-changes changes) - (dwu/commit-undo-transaction undo-id)))))) + changes (-> (pcb/empty-changes it page-id) + (pcb/with-library-data data) + (pcb/with-objects objects) + (clvp/generate-set-variant-error component-id value)) + undo-id (js/Symbol)] + (rx/of + (dwu/start-undo-transaction undo-id) + (dch/commit-changes changes) + (dwu/commit-undo-transaction undo-id))))))) (defn remove-property diff --git a/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs b/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs index 7d56ceb848..144e27a2e6 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/layer_name.cljs @@ -73,7 +73,7 @@ (if (ctv/valid-properties-formula? name) (st/emit! (dwv/update-properties-names-and-values component-id variant-id variant-properties (ctv/properties-formula->map name)) (dwv/remove-empty-properties variant-id) - (dwv/update-error component-id nil)) + (dwv/update-error component-id)) (st/emit! (dwv/update-properties-names-and-values component-id variant-id variant-properties {}) (dwv/remove-empty-properties variant-id) (dwv/update-error component-id name))) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs index 2d48f73cb9..ccc4604eec 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs @@ -339,7 +339,7 @@ (let [value (d/nilv (str/trim value) "")] (doseq [id component-ids] (st/emit! (dwv/update-property-value id pos value)) - (st/emit! (dwv/update-error id nil)))))) + (st/emit! (dwv/update-error id)))))) update-property-name (mf/use-fn