0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-09 16:30:37 -05:00

🐛 Fix invalid page flows on comp-v2 migration

This commit is contained in:
Andrey Antukh 2024-01-24 14:34:04 +01:00
parent aaeb8c8868
commit e4f4ab9221

View file

@ -29,6 +29,7 @@
[app.common.types.components-list :as ctkl] [app.common.types.components-list :as ctkl]
[app.common.types.container :as ctn] [app.common.types.container :as ctn]
[app.common.types.file :as ctf] [app.common.types.file :as ctf]
[app.common.types.page :as ctp]
[app.common.types.pages-list :as ctpl] [app.common.types.pages-list :as ctpl]
[app.common.types.shape :as cts] [app.common.types.shape :as cts]
[app.common.types.shape-tree :as ctst] [app.common.types.shape-tree :as ctst]
@ -100,15 +101,16 @@
;; FILE PREPARATION BEFORE MIGRATION ;; FILE PREPARATION BEFORE MIGRATION
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def valid-color? (sm/lazy-validator ::ctc/recent-color))
(def valid-fill? (sm/lazy-validator ::cts/fill))
(def valid-stroke? (sm/lazy-validator ::cts/stroke))
(def valid-flow? (sm/lazy-validator ::ctp/flow))
(defn- prepare-file-data (defn- prepare-file-data
"Apply some specific migrations or fixes to things that are allowed in v1 but not in v2, "Apply some specific migrations or fixes to things that are allowed in v1 but not in v2,
or that are the result of old bugs." or that are the result of old bugs."
[file-data libraries] [file-data libraries]
(let [detached-ids (volatile! #{}) (let [detached-ids (volatile! #{})
valid-color? (sm/validator ::ctc/recent-color)
valid-fill? (sm/validator ::cts/fill)
valid-stroke? (sm/validator ::cts/stroke)
detach-shape detach-shape
(fn [container shape] (fn [container shape]
;; Detach a shape. If it's inside a component, add it to detached-ids, for further use. ;; Detach a shape. If it's inside a component, add it to detached-ids, for further use.
@ -159,6 +161,14 @@
(update :pages-index update-vals fix-container) (update :pages-index update-vals fix-container)
(d/update-when :components update-vals fix-container)))) (d/update-when :components update-vals fix-container))))
;; Some pages has invalid data on flows, we proceed just to
;; delete them.
delete-invalid-flows
(fn [file-data]
(update file-data :pages-index update-vals
(fn [page]
(d/update-in-when page [:options :flows] #(filterv valid-flow? %)))))
delete-big-geometry-shapes delete-big-geometry-shapes
(fn [file-data] (fn [file-data]
;; At some point in time, we had a bug that generated shapes ;; At some point in time, we had a bug that generated shapes
@ -511,6 +521,7 @@
(d/update-when :components update-vals fix-container))))] (d/update-when :components update-vals fix-container))))]
(-> file-data (-> file-data
(delete-invalid-flows)
(fix-bad-children) (fix-bad-children)
(fix-misc-shape-issues) (fix-misc-shape-issues)
(fix-recent-colors) (fix-recent-colors)