0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-24 07:29:08 -05:00

🐛 Avoid adding empty attributes on update if they doesn't exist

This commit is contained in:
Andrés Moya 2024-01-23 13:12:20 +01:00 committed by Andrey Antukh
parent 1d21bd34f6
commit c679b04ad5

View file

@ -123,7 +123,7 @@
;; Remove any child that does not exist. ;; Remove any child that does not exist.
(letfn [(fix-container (letfn [(fix-container
[container] [container]
(update container :objects update-vals (partial fix-shape container))) (d/update-when container :objects update-vals (partial fix-shape container)))
(fix-shape (fix-shape
[container shape] [container shape]
@ -134,7 +134,7 @@
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
fix-missing-image-metadata fix-missing-image-metadata
(fn [file-data] (fn [file-data]
@ -154,7 +154,7 @@
(-> file-data (-> file-data
(update :pages-index update-vals update-page) (update :pages-index update-vals update-page)
(update :components update-vals update-page)))) (d/update-when :components update-vals update-page))))
;; At some point in time, we had a bug that generated shapes ;; At some point in time, we had a bug that generated shapes
;; with huge geometries that did not validate the ;; with huge geometries that did not validate the
@ -188,7 +188,7 @@
(-> file-data (-> file-data
(update :pages-index update-vals update-page) (update :pages-index update-vals update-page)
(update :components update-vals update-page)))) (d/update-when :components update-vals update-page))))
fix-misc-shape-issues fix-misc-shape-issues
(fn [file-data] (fn [file-data]
@ -229,7 +229,7 @@
(-> file-data (-> file-data
(update :pages-index update-vals update-container) (update :pages-index update-vals update-container)
(update :components update-vals update-container)))) (d/update-when :components update-vals update-container))))
fix-recent-colors fix-recent-colors
(fn [file-data] (fn [file-data]
@ -258,13 +258,13 @@
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
remove-nested-roots remove-nested-roots
(fn [file-data] (fn [file-data]
;; Remove :component-root in head shapes that are nested. ;; Remove :component-root in head shapes that are nested.
(letfn [(fix-container [container] (letfn [(fix-container [container]
(update container :objects update-vals (partial fix-shape container))) (d/update-when container :objects update-vals (partial fix-shape container)))
(fix-shape [container shape] (fix-shape [container shape]
(let [parent (ctst/get-shape container (:parent-id shape))] (let [parent (ctst/get-shape container (:parent-id shape))]
@ -275,13 +275,13 @@
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
add-not-nested-roots add-not-nested-roots
(fn [file-data] (fn [file-data]
;; Add :component-root in head shapes that are not nested. ;; Add :component-root in head shapes that are not nested.
(letfn [(fix-container [container] (letfn [(fix-container [container]
(update container :objects update-vals (partial fix-shape container))) (d/update-when container :objects update-vals (partial fix-shape container)))
(fix-shape [container shape] (fix-shape [container shape]
(let [parent (ctst/get-shape container (:parent-id shape))] (let [parent (ctst/get-shape container (:parent-id shape))]
@ -292,13 +292,13 @@
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
fix-orphan-copies fix-orphan-copies
(fn [file-data] (fn [file-data]
;; Detach shapes that were inside a copy (have :shape-ref) but now they aren't. ;; Detach shapes that were inside a copy (have :shape-ref) but now they aren't.
(letfn [(fix-container [container] (letfn [(fix-container [container]
(update container :objects update-vals (partial fix-shape container))) (d/update-when container :objects update-vals (partial fix-shape container)))
(fix-shape [container shape] (fix-shape [container shape]
(let [parent (ctst/get-shape container (:parent-id shape))] (let [parent (ctst/get-shape container (:parent-id shape))]
@ -310,7 +310,7 @@
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
remap-refs remap-refs
(fn [file-data] (fn [file-data]
@ -354,14 +354,14 @@
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
fix-copies-of-detached fix-copies-of-detached
(fn [file-data] (fn [file-data]
;; Find any copy that is referencing a detached shape inside a component, and ;; Find any copy that is referencing a detached shape inside a component, and
;; undo the nested copy, converting it into a direct copy. ;; undo the nested copy, converting it into a direct copy.
(letfn [(fix-container [container] (letfn [(fix-container [container]
(update container :objects update-vals fix-shape)) (d/update-when container :objects update-vals fix-shape))
(fix-shape [shape] (fix-shape [shape]
(cond-> shape (cond-> shape
@ -372,14 +372,14 @@
:component-root)))] :component-root)))]
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
fix-path-copies fix-path-copies
(fn [file-data] (fn [file-data]
;; If the user has created a copy and then converted into a path, detach it ;; If the user has created a copy and then converted into a path, detach it
;; because the synchronization will no longer work. ;; because the synchronization will no longer work.
(letfn [(fix-container [container] (letfn [(fix-container [container]
(update container :objects update-vals fix-shape)) (d/update-when container :objects update-vals fix-shape))
(fix-shape [shape] (fix-shape [shape]
(if (and (ctk/instance-head? shape) (if (and (ctk/instance-head? shape)
@ -389,14 +389,14 @@
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
transform-to-frames transform-to-frames
(fn [file-data] (fn [file-data]
;; Transform component and copy heads to frames, and set the ;; Transform component and copy heads to frames, and set the
;; frame-id of its childrens ;; frame-id of its childrens
(letfn [(fix-container [container] (letfn [(fix-container [container]
(update container :objects update-vals fix-shape)) (d/update-when container :objects update-vals fix-shape))
(fix-shape [shape] (fix-shape [shape]
(if (or (nil? (:parent-id shape)) (ctk/instance-head? shape)) (if (or (nil? (:parent-id shape)) (ctk/instance-head? shape))
@ -410,7 +410,7 @@
shape))] shape))]
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
remap-frame-ids remap-frame-ids
(fn [file-data] (fn [file-data]
@ -418,7 +418,7 @@
;; to point to the head instance. ;; to point to the head instance.
(letfn [(fix-container (letfn [(fix-container
[container] [container]
(update container :objects update-vals (partial fix-shape container))) (d/update-when container :objects update-vals (partial fix-shape container)))
(fix-shape (fix-shape
[container shape] [container shape]
@ -428,14 +428,14 @@
shape)))] shape)))]
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
fix-frame-ids fix-frame-ids
(fn [file-data] (fn [file-data]
;; Ensure that frame-id of all shapes point to the parent or to the frame-id ;; Ensure that frame-id of all shapes point to the parent or to the frame-id
;; of the parent, and that the destination is indeed a frame. ;; of the parent, and that the destination is indeed a frame.
(letfn [(fix-container [container] (letfn [(fix-container [container]
(update container :objects #(cfh/reduce-objects % fix-shape %))) (d/update-when container :objects #(cfh/reduce-objects % fix-shape %)))
(fix-shape [objects shape] (fix-shape [objects shape]
(let [parent (when (:parent-id shape) (let [parent (when (:parent-id shape)
@ -452,7 +452,7 @@
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
fix-component-nil-objects fix-component-nil-objects
(fn [file-data] (fn [file-data]
@ -464,14 +464,14 @@
(dissoc component :objects)) (dissoc component :objects))
component))] component))]
(-> file-data (-> file-data
(update :components update-vals fix-component)))) (d/update-when :components update-vals fix-component))))
fix-false-copies fix-false-copies
(fn [file-data] (fn [file-data]
;; Find component heads that are not main-instance but have not :shape-ref. ;; Find component heads that are not main-instance but have not :shape-ref.
(letfn [(fix-container (letfn [(fix-container
[container] [container]
(update container :objects update-vals fix-shape)) (d/update-when container :objects update-vals fix-shape))
(fix-shape (fix-shape
[shape] [shape]
@ -482,7 +482,7 @@
shape))] shape))]
(-> file-data (-> file-data
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(update :components update-vals fix-container))))] (d/update-when :components update-vals fix-container))))]
(-> file-data (-> file-data
(remove-missing-children) (remove-missing-children)