From 19e40175be0c88a2d6f27dc27325be8a9a06e3f1 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 11 Jan 2024 18:05:36 +0100 Subject: [PATCH] :bug: Disable import to v1 from v2 --- common/src/app/common/files/builder.cljc | 1 - frontend/src/app/main/ui/dashboard/import.cljs | 15 +++++++++------ frontend/src/app/worker/import.cljs | 13 +++++++++++-- frontend/translations/en.po | 3 +++ frontend/translations/es.po | 3 +++ 5 files changed, 26 insertions(+), 9 deletions(-) diff --git a/common/src/app/common/files/builder.cljc b/common/src/app/common/files/builder.cljc index 0f838c147..d10b494d9 100644 --- a/common/src/app/common/files/builder.cljc +++ b/common/src/app/common/files/builder.cljc @@ -508,7 +508,6 @@ 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 diff --git a/frontend/src/app/main/ui/dashboard/import.cljs b/frontend/src/app/main/ui/dashboard/import.cljs index 2ac73e421..d207630b9 100644 --- a/frontend/src/app/main/ui/dashboard/import.cljs +++ b/frontend/src/app/main/ui/dashboard/import.cljs @@ -80,12 +80,13 @@ (assoc :deleted? true)))))) (defn set-analyze-error - [files uri] + [files uri error] (->> files (mapv (fn [file] (cond-> file (= uri (:uri file)) - (assoc :status :analyze-error)))))) + (-> (assoc :status :analyze-error) + (assoc :error error))))))) (defn set-analyze-result [files uri type data] (let [existing-files? (into #{} (->> files (map :file-id) (filter some?))) @@ -150,7 +151,6 @@ (mf/defc import-entry [{:keys [state file editing? can-be-deleted?]}] - (let [loading? (or (= :analyzing (:status file)) (= :importing (:status file))) analyze-error? (= :analyze-error (:status file)) @@ -226,7 +226,9 @@ (cond analyze-error? [:div {:class (stl/css :error-message)} - (tr "dashboard.import.analyze-error")] + (if (some? (:error file)) + (tr (:error file)) + (tr "dashboard.import.analyze-error"))] import-error? [:div {:class (stl/css :error-message)} @@ -260,13 +262,14 @@ (fn [files] (->> (uw/ask-many! {:cmd :analyze-import - :files files}) + :files files + :features @features/features-ref}) (rx/mapcat #(rx/delay emit-delay (rx/of %))) (rx/filter some?) (rx/subs! (fn [{:keys [uri data error type] :as msg}] (if (some? error) - (swap! state update :files set-analyze-error uri) + (swap! state update :files set-analyze-error uri error) (swap! state update :files set-analyze-result uri type data))))))) import-files diff --git a/frontend/src/app/worker/import.cljs b/frontend/src/app/worker/import.cljs index ef8abf2d6..b1db05f9d 100644 --- a/frontend/src/app/worker/import.cljs +++ b/frontend/src/app/worker/import.cljs @@ -632,7 +632,7 @@ "other"))) (defmethod impl/handler :analyze-import - [{:keys [files]}] + [{:keys [files features]}] (->> (rx/from files) (rx/merge-map @@ -653,7 +653,16 @@ (rx/merge-map #(zip/loadAsync (:body %))) (rx/merge-map #(get-file {:zip %} :manifest)) (rx/map (comp d/kebab-keys parser/string->uuid)) - (rx/map #(hash-map :uri (:uri file) :data % :type "application/zip"))) + (rx/map + (fn [data] + ;; Checks if the file is exported with components v2 and the current team only + ;; supports components v1 + (let [has-file-v2? + (->> (:files data) + (d/seek (fn [[_ file]] (contains? (set (:features file)) "components/v2"))))] + (if (and has-file-v2? (not (contains? features "components/v2"))) + {:uri (:uri file) :error "dashboard.import.analyze-error.components-v2"} + (hash-map :uri (:uri file) :data data :type "application/zip")))))) (->> st (rx/filter (fn [data] (= "application/octet-stream" (:type data)))) (rx/map (fn [_] diff --git a/frontend/translations/en.po b/frontend/translations/en.po index 1d1addfc4..428cf98f5 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -534,6 +534,9 @@ msgstr "Import Penpot files" msgid "dashboard.import.analyze-error" msgstr "Oops! We couldn't import this file" +msgid "dashboard.import.analyze-error.components-v2" +msgstr "File with components v2 activated but this team doesn't support it yet." + msgid "dashboard.import.import-error" msgstr "There was a problem importing the file. The file wasn't imported." diff --git a/frontend/translations/es.po b/frontend/translations/es.po index 8845dc484..be493d3c2 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -542,6 +542,9 @@ msgstr "Importar archivos Penpot" msgid "dashboard.import.analyze-error" msgstr "¡Vaya! No hemos podido importar el fichero" +msgid "dashboard.import.analyze-error.components-v2" +msgstr "Fichero exportado con componentes-v2 pero el equipo actual no lo soporta aún." + msgid "dashboard.import.import-error" msgstr "Hubo un problema importando el fichero. No ha podido ser importado."