🐛 Remove empty properties starting with the last one (#6757)

* 🐛 Remove empty properties starting with the last one

*  MR changes

---------

Co-authored-by: Pablo Alba <pablo.alba@kaleidos.net>
This commit is contained in:
luisδμ 2025-06-26 09:16:59 +02:00 committed by GitHub
parent 7cd0e28c3b
commit 2de0c90fc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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)]