From 28981e5d461f7e1a1f338f6d2b234e20f2414bb9 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 11 Jan 2024 17:46:50 +0100 Subject: [PATCH] :bug: Fix import of zip files from v2 to v2 --- common/src/app/common/files/builder.cljc | 7 +++++++ frontend/src/app/main/render.cljs | 2 +- frontend/src/app/worker/import.cljs | 13 ++++++++++--- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/files/builder.cljc b/common/src/app/common/files/builder.cljc index ac9b24f6e8..0f838c147c 100644 --- a/common/src/app/common/files/builder.cljc +++ b/common/src/app/common/files/builder.cljc @@ -508,6 +508,7 @@ grc/empty-rect) name (:name data) path (:path data) + component-id (:component-id data) main-instance-id (:main-instance-id data) main-instance-page (:main-instance-page data) attrs (-> data @@ -547,11 +548,17 @@ (defn finish-component [file] (let [component-id (:current-component-id file) + component-data (ctkl/get-component (:data file) component-id) + component (lookup-shape file component-id) children (->> component :shapes (mapv #(lookup-shape file %))) file (cond + ;; Components-v2 component we skip this step + (and component-data (:main-instance-id component-data)) + file + (empty? children) (commit-change file diff --git a/frontend/src/app/main/render.cljs b/frontend/src/app/main/render.cljs index a9a943a274..861935a54c 100644 --- a/frontend/src/app/main/render.cljs +++ b/frontend/src/app/main/render.cljs @@ -508,7 +508,7 @@ (mf/deps objects) (fn [] (frame-wrapper-factory objects)))] - [:> "symbol" #js {:id (str root-id) + [:> "symbol" #js {:id (str (:id component)) :viewBox vbox "penpot:path" path "penpot:main-instance-id" main-instance-id diff --git a/frontend/src/app/worker/import.cljs b/frontend/src/app/worker/import.cljs index cc7e3dff52..ef8abf2d6b 100644 --- a/frontend/src/app/worker/import.cljs +++ b/frontend/src/app/worker/import.cljs @@ -137,7 +137,11 @@ :is-shared (:shared context) :project-id (:project-id context) :create-page false - :features features}))) + + ;; If the features object exists send that. Otherwise we remove the components/v2 because + ;; if the features attribute doesn't exist is a version < 2.0. The other features will + ;; be kept so the shapes are created full featured + :features (d/nilv (:features context) (disj features "components/v2"))}))) (defn link-file-libraries "Create a new file on the back-end" @@ -154,7 +158,8 @@ [context file] (let [file-id (:id file) session-id (uuid/next) - batches (->> (fb/generate-changes file) + changes (fb/generate-changes file) + batches (->> changes (partition change-batch-size change-batch-size nil) (mapv vec)) @@ -538,7 +543,9 @@ (rx/merge-map (comp d/kebab-keys parser/string->uuid)) (rx/mapcat (fn [[id media]] - (let [media (assoc media :id (resolve id))] + (let [media (-> media + (assoc :id (resolve id)) + (update :name str))] (->> (get-file context :media id media) (rx/map (fn [blob] (let [content (.slice blob 0 (.-size blob) (:mtype media))]