From 76abd6796e57655c76c9154070d55cf0ee935254 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 1 Apr 2022 11:26:47 +0200 Subject: [PATCH] :bug: Fix import problems --- frontend/src/app/util/import/parser.cljs | 6 ++-- frontend/src/app/util/path/parser.cljs | 23 +++++++------- frontend/src/app/worker/import.cljs | 40 ++++++++++++++---------- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/frontend/src/app/util/import/parser.cljs b/frontend/src/app/util/import/parser.cljs index b00485efa..28767b265 100644 --- a/frontend/src/app/util/import/parser.cljs +++ b/frontend/src/app/util/import/parser.cljs @@ -214,11 +214,13 @@ (= type :frame) (let [;; The nodes with the "frame-background" class can have some anidation depending on the strokes they have - g-nodes (find-all-nodes node :g) + g-nodes (find-all-nodes node :g) defs-nodes (flatten (map #(find-all-nodes % :defs) g-nodes)) + gg-nodes (flatten (map #(find-all-nodes % :g) g-nodes)) rect-nodes (flatten [[(find-all-nodes node :rect)] (map #(find-all-nodes % #{:rect :path}) defs-nodes) - (map #(find-all-nodes % #{:rect :path}) g-nodes)]) + (map #(find-all-nodes % #{:rect :path}) g-nodes) + (map #(find-all-nodes % #{:rect :path}) gg-nodes)]) svg-node (d/seek #(= "frame-background" (get-in % [:attrs :class])) rect-nodes)] (merge (add-attrs {} (:attrs svg-node)) node-attrs)) diff --git a/frontend/src/app/util/path/parser.cljs b/frontend/src/app/util/path/parser.cljs index 2057ae05f..172089caa 100644 --- a/frontend/src/app/util/path/parser.cljs +++ b/frontend/src/app/util/path/parser.cljs @@ -302,16 +302,17 @@ (reduce simplify-command [[start] start-pos start-pos start-pos start-pos]) (first)))) - (defn parse-path [path-str] - (let [clean-path-str - (-> path-str - (str/trim) - ;; Change "commas" for spaces - (str/replace #"," " ") - ;; Remove all consecutive spaces - (str/replace #"\s+" " ")) - commands (re-seq commands-regex clean-path-str)] - (-> (mapcat parse-command commands) - (simplify-commands)))) + (if (empty? path-str) + path-str + (let [clean-path-str + (-> path-str + (str/trim) + ;; Change "commas" for spaces + (str/replace #"," " ") + ;; Remove all consecutive spaces + (str/replace #"\s+" " ")) + commands (re-seq commands-regex clean-path-str)] + (-> (mapcat parse-command commands) + (simplify-commands))))) diff --git a/frontend/src/app/worker/import.cljs b/frontend/src/app/worker/import.cljs index cd45b6781..634cc5c7e 100644 --- a/frontend/src/app/worker/import.cljs +++ b/frontend/src/app/worker/import.cljs @@ -31,6 +31,8 @@ ;; Upload changes batches size (def ^:const change-batch-size 100) +(def conjv (fnil conj [])) + (defn get-file "Resolves the file inside the context given its id and the data" ([context type] @@ -261,25 +263,29 @@ (cond-> (some? old-id) (assoc :id (resolve old-id))) (cond-> (< (:version context 1) 2) - (translate-frame type file))) + (translate-frame type file)))] + (try + (let [file (case type + :frame (fb/add-artboard file data) + :group (fb/add-group file data) + :bool (fb/add-bool file data) + :rect (fb/create-rect file data) + :circle (fb/create-circle file data) + :path (fb/create-path file data) + :text (fb/create-text file data) + :image (fb/create-image file data) + :svg-raw (fb/create-svg-raw file data) + #_default file)] - file (case type - :frame (fb/add-artboard file data) - :group (fb/add-group file data) - :bool (fb/add-bool file data) - :rect (fb/create-rect file data) - :circle (fb/create-circle file data) - :path (fb/create-path file data) - :text (fb/create-text file data) - :image (fb/create-image file data) - :svg-raw (fb/create-svg-raw file data) - #_default file)] + ;; We store this data for post-processing after every shape has been + ;; added + (cond-> file + (d/not-empty? interactions) + (assoc-in [:interactions (:id data)] interactions))) - ;; We store this data for post-processing after every shape has been - ;; added - (cond-> file - (d/not-empty? interactions) - (assoc-in [:interactions (:id data)] interactions)))))) + (catch :default err + (log/error :hint (ex-message err) :cause err :js/data data) + (update file :errors conjv data))))))) (defn setup-interactions [file]