From 2de0c90fc7421f0d9b05440db2f46107ea1a4ada Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?luis=CE=B4=CE=BC?= Date: Thu, 26 Jun 2025 09:16:59 +0200 Subject: [PATCH] :bug: Remove empty properties starting with the last one (#6757) * :bug: Remove empty properties starting with the last one * :sparkles: MR changes --------- Co-authored-by: Pablo Alba --- .../src/app/main/data/workspace/variants.cljs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/frontend/src/app/main/data/workspace/variants.cljs b/frontend/src/app/main/data/workspace/variants.cljs index f70aaf8b46..29e2518c93 100644 --- a/frontend/src/app/main/data/workspace/variants.cljs +++ b/frontend/src/app/main/data/workspace/variants.cljs @@ -179,7 +179,8 @@ (defn remove-empty-properties - "Remove a property for all components when its value is empty for all of them" + "Remove every empty property for all components when their respective values are empty + for all of them" [variant-id] (ptk/reify ::remove-empty-properties ptk/WatchEvent @@ -191,25 +192,29 @@ variant-components (cfv/find-variant-components data objects variant-id) - properties-empty (->> variant-components - (mapcat :variant-properties) - (group-by :name) - (mapv (fn [[_ v]] - (->> v (mapv :value) (remove empty?)))) - (mapv empty?)) + properties-empty-pos (->> variant-components + (mapcat :variant-properties) + (group-by :name) + (map-indexed + (fn [i [_ v]] + [i (->> v + (map :value) + (remove empty?) + empty?)])) + (reverse)) changes (-> (pcb/empty-changes it page-id) (pcb/with-library-data data) (pcb/with-objects objects)) changes (reduce - (fn [changes [idx property-empty?]] + (fn [changes [pos property-empty?]] (if property-empty? (-> changes - (clvp/generate-remove-property variant-id idx)) + (clvp/generate-remove-property variant-id pos)) changes)) changes - (map-indexed vector properties-empty)) + properties-empty-pos) undo-id (js/Symbol)]