From e83c90203e77118e2c9341482c5a3c61e6ec62c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Wed, 29 May 2024 14:57:43 +0200 Subject: [PATCH] :bug: Migration to remove bad swap-slots --- common/src/app/common/files/defaults.cljc | 2 +- common/src/app/common/files/migrations.cljc | 28 ++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/files/defaults.cljc b/common/src/app/common/files/defaults.cljc index 61cd7f1188..721adab70f 100644 --- a/common/src/app/common/files/defaults.cljc +++ b/common/src/app/common/files/defaults.cljc @@ -6,4 +6,4 @@ (ns app.common.files.defaults) -(def version 46) +(def version 47) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index 36860b43e6..363311564e 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -22,6 +22,8 @@ [app.common.schema :as sm] [app.common.svg :as csvg] [app.common.text :as txt] + [app.common.types.component :as ctk] + [app.common.types.file :as ctf] [app.common.types.shape :as cts] [app.common.types.shape.shadow :as ctss] [app.common.uuid :as uuid] @@ -898,6 +900,29 @@ (update :pages-index update-vals update-container) (update :components update-vals update-container)))) +(defn migrate-up-47 + [data] + (letfn [(fix-shape [page shape] + (let [file {:id (:id data) :data data} + component-file (:component-file shape) + ;; On cloning a file, the component-file of the shapes point to the old file id + ;; this is a workaround to be able to found the components in that case + libraries {component-file {:id component-file :data data}} + ref-shape (ctf/find-ref-shape file page libraries shape {:include-deleted? true :with-context? true}) + ref-parent (get (:objects (:container (meta ref-shape))) (:parent-id ref-shape)) + shape-swap-slot (ctk/get-swap-slot shape) + ref-swap-slot (ctk/get-swap-slot ref-shape)] + (if (and (some? shape-swap-slot) + (= shape-swap-slot ref-swap-slot) + (ctk/main-instance? ref-parent)) + (ctk/remove-swap-slot shape) + shape))) + + (update-page [page] + (d/update-when page :objects update-vals (partial fix-shape page)))] + (-> data + (update :pages-index update-vals update-page)))) + (def migrations "A vector of all applicable migrations" [{:id 2 :migrate-up migrate-up-2} @@ -935,4 +960,5 @@ {:id 43 :migrate-up migrate-up-43} {:id 44 :migrate-up migrate-up-44} {:id 45 :migrate-up migrate-up-45} - {:id 46 :migrate-up migrate-up-46}]) + {:id 46 :migrate-up migrate-up-46} + {:id 47 :migrate-up migrate-up-47}])