0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-09 08:38:15 -05:00

Merge pull request #2855 from penpot/alotor-migration-fix-frame-id

🐛 Add migration to fix problem with frame-id
This commit is contained in:
Alejandro 2023-01-30 09:39:18 +01:00 committed by GitHub
commit f85a731969
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 49 additions and 20 deletions

View file

@ -9,7 +9,7 @@
[app.common.colors :as clr] [app.common.colors :as clr]
[app.common.uuid :as uuid])) [app.common.uuid :as uuid]))
(def file-version 19) (def file-version 20)
(def default-color clr/gray-20) (def default-color clr/gray-20)
(def root uuid/zero) (def root uuid/zero)

View file

@ -7,11 +7,12 @@
(ns app.common.pages.migrations (ns app.common.pages.migrations
(:require (:require
[app.common.data :as d] [app.common.data :as d]
[app.common.data.macros :as dm]
[app.common.geom.matrix :as gmt] [app.common.geom.matrix :as gmt]
[app.common.geom.shapes :as gsh] [app.common.geom.shapes :as gsh]
[app.common.geom.shapes.path :as gsp] [app.common.geom.shapes.path :as gsp]
[app.common.geom.shapes.text :as gsht] [app.common.geom.shapes.text :as gsht]
[app.common.logging :as l] [app.common.logging :as log]
[app.common.math :as mth] [app.common.math :as mth]
[app.common.pages :as cp] [app.common.pages :as cp]
[app.common.pages.helpers :as cph] [app.common.pages.helpers :as cph]
@ -23,13 +24,15 @@
(defmulti migrate :version) (defmulti migrate :version)
(log/set-level! :info)
(defn migrate-data (defn migrate-data
([data] (migrate-data data cp/file-version)) ([data] (migrate-data data cp/file-version))
([data to-version] ([data to-version]
(if (= (:version data) to-version) (if (= (:version data) to-version)
data data
(let [migrate-fn #(do (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))))] (migrate (assoc %1 :version (inc %2))))]
(reduce migrate-fn data (range (:version data 0) to-version)))))) (reduce migrate-fn data (range (:version data 0) to-version))))))
@ -427,5 +430,31 @@
(update :pages-index update-vals update-container) (update :pages-index update-vals update-container)
(update :components 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 ;; TODO: pending to do a migration for delete already not used fill
;; and stroke props. This should be done for >1.14.x version. ;; and stroke props. This should be done for >1.14.x version.

View file

@ -155,21 +155,19 @@
[base index-base-a index-base-b])) [base index-base-a index-base-b]))
(defn is-shape-over-shape? (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)] (let [[base index-a index-b] (get-base objects base-shape-id over-shape-id)]
(cond (cond
(= base base-shape-id) (= base base-shape-id)
(and (not top-frames?)
(let [object (get objects base-shape-id)] (let [object (get objects base-shape-id)]
(or (cph/frame-shape? object) (or (cph/frame-shape? object)
(cph/root-frame? object)))) (cph/root-frame? object)))
(= base over-shape-id) (= base over-shape-id)
(or top-frames?
(let [object (get objects over-shape-id)] (let [object (get objects over-shape-id)]
(or (not (cph/frame-shape? object)) (or (not (cph/frame-shape? object))
(not (cph/root-frame? object))))) (not (cph/root-frame? object))))
:else :else
(< index-a index-b)))) (< index-a index-b))))
@ -183,20 +181,20 @@
(let [type-a (dm/get-in objects [id-a :type]) (let [type-a (dm/get-in objects [id-a :type])
type-b (dm/get-in objects [id-b :type])] type-b (dm/get-in objects [id-b :type])]
(cond (cond
(and (= :frame type-a) (not= :frame type-b))
(if bottom-frames? 1 -1)
(and (not= :frame type-a) (= :frame type-b)) (and (not= :frame type-a) (= :frame type-b))
(if bottom-frames? -1 1) (if bottom-frames? -1 1)
(and (= :frame type-a) (not= :frame type-b))
(if bottom-frames? 1 -1)
(= id-a id-b) (= id-a id-b)
0 0
(is-shape-over-shape? objects id-a id-b options) (is-shape-over-shape? objects id-b id-a)
1 -1
:else :else
-1)))] 1)))]
(sort comp ids)))) (sort comp ids))))
(defn frame-id-by-position (defn frame-id-by-position
@ -268,7 +266,7 @@
(if all-frames? (if all-frames?
identity identity
(remove :hide-in-viewer))) (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 (defn start-page-index
[objects] [objects]

View file

@ -432,7 +432,8 @@
(or (or
(= uuid/zero id) (= uuid/zero id)
(and (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 (or
(empty? filters) (empty? filters)
(and (and

View file

@ -243,6 +243,7 @@
(filter #(or (empty? focus) (cp/is-in-focus? objects focus %))) (filter #(or (empty? focus) (cp/is-in-focus? objects focus %)))
(first) (first)
(get objects))] (get objects))]
(reset! hover hover-shape) (reset! hover hover-shape)
(reset! hover-ids ids) (reset! hover-ids ids)
(reset! hover-top-frame-id (ctt/top-nested-frame objects (deref last-point-ref)))))))) (reset! hover-top-frame-id (ctt/top-nested-frame objects (deref last-point-ref))))))))