From 86b68aeca48b115ede0ba59992a05724238a044b Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 27 Jan 2023 14:43:55 +0100 Subject: [PATCH] :bug: Add migration to fix problem with frame-id --- common/src/app/common/pages/common.cljc | 2 +- common/src/app/common/pages/migrations.cljc | 33 +++++++++++++++++-- common/src/app/common/types/shape_tree.cljc | 30 ++++++++--------- .../app/main/ui/workspace/sidebar/layers.cljs | 3 +- .../app/main/ui/workspace/viewport/hooks.cljs | 1 + 5 files changed, 49 insertions(+), 20 deletions(-) diff --git a/common/src/app/common/pages/common.cljc b/common/src/app/common/pages/common.cljc index ab5379504..c738b22d4 100644 --- a/common/src/app/common/pages/common.cljc +++ b/common/src/app/common/pages/common.cljc @@ -9,7 +9,7 @@ [app.common.colors :as clr] [app.common.uuid :as uuid])) -(def file-version 19) +(def file-version 20) (def default-color clr/gray-20) (def root uuid/zero) diff --git a/common/src/app/common/pages/migrations.cljc b/common/src/app/common/pages/migrations.cljc index effbee310..a8c05724a 100644 --- a/common/src/app/common/pages/migrations.cljc +++ b/common/src/app/common/pages/migrations.cljc @@ -7,11 +7,12 @@ (ns app.common.pages.migrations (:require [app.common.data :as d] + [app.common.data.macros :as dm] [app.common.geom.matrix :as gmt] [app.common.geom.shapes :as gsh] [app.common.geom.shapes.path :as gsp] [app.common.geom.shapes.text :as gsht] - [app.common.logging :as l] + [app.common.logging :as log] [app.common.math :as mth] [app.common.pages :as cp] [app.common.pages.helpers :as cph] @@ -23,13 +24,15 @@ (defmulti migrate :version) +(log/set-level! :info) + (defn migrate-data ([data] (migrate-data data cp/file-version)) ([data to-version] (if (= (:version data) to-version) data (let [migrate-fn #(do - (l/trace :hint "migrate file" :id (:id %) :version-from %2 :version-to (inc %2)) + (log/trace :hint "migrate file" :id (:id %) :version-from %2 :version-to (inc %2)) (migrate (assoc %1 :version (inc %2))))] (reduce migrate-fn data (range (:version data 0) to-version)))))) @@ -427,5 +430,31 @@ (update :pages-index update-vals update-container) (update :components update-vals update-container)))) +(defmethod migrate 20 + [data] + (letfn [(update-object [objects object] + (let [frame-id (:frame-id object) + calculated-frame-id + (or (->> (cph/get-parent-ids objects (:id object)) + (map (d/getf objects)) + (d/seek cph/frame-shape?) + :id) + ;; If we cannot find any we let the frame-id as it was before + frame-id)] + (when (not= frame-id calculated-frame-id) + (log/info :hint "Fix wrong frame-id" + :shape (:name object) + :id (:id object) + :current (dm/get-in objects [frame-id :name]) + :calculated (get-in objects [calculated-frame-id :name]))) + (assoc object :frame-id calculated-frame-id))) + + (update-container [container] + (update container :objects #(update-vals % (partial update-object %))))] + + (-> data + (update :pages-index update-vals update-container) + (update :components update-vals update-container)))) + ;; TODO: pending to do a migration for delete already not used fill ;; and stroke props. This should be done for >1.14.x version. diff --git a/common/src/app/common/types/shape_tree.cljc b/common/src/app/common/types/shape_tree.cljc index 470d8b68d..aebcb9d1c 100644 --- a/common/src/app/common/types/shape_tree.cljc +++ b/common/src/app/common/types/shape_tree.cljc @@ -155,21 +155,19 @@ [base index-base-a index-base-b])) (defn is-shape-over-shape? - [objects base-shape-id over-shape-id {:keys [top-frames?]}] + [objects base-shape-id over-shape-id] (let [[base index-a index-b] (get-base objects base-shape-id over-shape-id)] (cond (= base base-shape-id) - (and (not top-frames?) - (let [object (get objects base-shape-id)] - (or (cph/frame-shape? object) - (cph/root-frame? object)))) + (let [object (get objects base-shape-id)] + (or (cph/frame-shape? object) + (cph/root-frame? object))) (= base over-shape-id) - (or top-frames? - (let [object (get objects over-shape-id)] - (or (not (cph/frame-shape? object)) - (not (cph/root-frame? object))))) + (let [object (get objects over-shape-id)] + (or (not (cph/frame-shape? object)) + (not (cph/root-frame? object)))) :else (< index-a index-b)))) @@ -183,20 +181,20 @@ (let [type-a (dm/get-in objects [id-a :type]) type-b (dm/get-in objects [id-b :type])] (cond - (and (= :frame type-a) (not= :frame type-b)) - (if bottom-frames? 1 -1) - (and (not= :frame type-a) (= :frame type-b)) (if bottom-frames? -1 1) + (and (= :frame type-a) (not= :frame type-b)) + (if bottom-frames? 1 -1) + (= id-a id-b) 0 - (is-shape-over-shape? objects id-a id-b options) - 1 + (is-shape-over-shape? objects id-b id-a) + -1 :else - -1)))] + 1)))] (sort comp ids)))) (defn frame-id-by-position @@ -268,7 +266,7 @@ (if all-frames? identity (remove :hide-in-viewer))) - (sort-z-index objects (get-frames-ids objects) {:top-frames? true})))) + (sort-z-index objects (get-frames-ids objects))))) (defn start-page-index [objects] diff --git a/frontend/src/app/main/ui/workspace/sidebar/layers.cljs b/frontend/src/app/main/ui/workspace/sidebar/layers.cljs index 81f5a8970..d7f61a31d 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/layers.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/layers.cljs @@ -432,7 +432,8 @@ (or (= uuid/zero id) (and - (str/includes? (str/lower (:name shape)) (str/lower search)) + (or (str/includes? (str/lower (:name shape)) (str/lower search)) + (str/includes? (dm/str (:id shape)) (str/lower search))) (or (empty? filters) (and diff --git a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs index 1c5d08709..d4dd8c624 100644 --- a/frontend/src/app/main/ui/workspace/viewport/hooks.cljs +++ b/frontend/src/app/main/ui/workspace/viewport/hooks.cljs @@ -243,6 +243,7 @@ (filter #(or (empty? focus) (cp/is-in-focus? objects focus %))) (first) (get objects))] + (reset! hover hover-shape) (reset! hover-ids ids) (reset! hover-top-frame-id (ctt/top-nested-frame objects (deref last-point-ref))))))))