diff --git a/CHANGES.md b/CHANGES.md index d45f28d5c..88fb94a9a 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -4,6 +4,9 @@ ### :sparkles: New features ### :bug: Bugs fixed + +- Remove interactions when the destination artboard is deleted [Taiga #1656](https://tree.taiga.io/project/penpot/issue/1656) + ### :arrow_up: Deps updates ### :boom: Breaking changes ### :heart: Community contributions by (Thank you!) diff --git a/common/app/common/pages/common.cljc b/common/app/common/pages/common.cljc index db1e9341c..f439b2cf4 100644 --- a/common/app/common/pages/common.cljc +++ b/common/app/common/pages/common.cljc @@ -8,7 +8,7 @@ (:require [app.common.uuid :as uuid])) -(def file-version 6) +(def file-version 7) (def default-color "#b1b2b5") ;; $color-gray-20 (def root uuid/zero) diff --git a/common/app/common/pages/migrations.cljc b/common/app/common/pages/migrations.cljc index 588da5d95..fd254d87b 100644 --- a/common/app/common/pages/migrations.cljc +++ b/common/app/common/pages/migrations.cljc @@ -163,3 +163,19 @@ (-> data (update :components #(d/mapm update-container %)) (update :pages-index #(d/mapm update-container %))))) + + +;; Remove interactions pointing to deleted frames +(defmethod migrate 7 + [data] + (letfn [(update-object [page _ object] + (d/update-when object :interactions + (fn [interactions] + (filterv #(get-in page [:objects (:destination %)]) + interactions)))) + + (update-page [_ page] + (update page :objects #(d/mapm (partial update-object page) %)))] + + (update data :pages-index #(d/mapm update-page %)))) + diff --git a/frontend/src/app/main/data/workspace/common.cljs b/frontend/src/app/main/data/workspace/common.cljs index c9f8bfcd8..d43229cdd 100644 --- a/frontend/src/app/main/data/workspace/common.cljs +++ b/frontend/src/app/main/data/workspace/common.cljs @@ -331,7 +331,6 @@ :shapes [shape-id]})))] (rx/of (dch/commit-changes rchanges uchanges {:commit-local? true})))))) - (defn delete-shapes [ids] (us/assert (s/coll-of ::us/uuid) ids) @@ -366,6 +365,12 @@ #{} ids) + interacting-shapes + (filter (fn [shape] + (let [interactions (:interactions shape)] + (some ids (map :destination interactions)))) + (vals objects)) + rchanges (d/concat (reduce (fn [res id] @@ -391,7 +396,18 @@ :operations [{:type :set :attr :masked-group? :val false}]) - groups-to-unmask)) + groups-to-unmask) + (map #(array-map + :type :mod-obj + :page-id page-id + :id (:id %) + :operations [{:type :set + :attr :interactions + :val (vec (remove (fn [interaction] + (contains? ids (:destination interaction))) + (:interactions %)))}]) + interacting-shapes)) + uchanges (d/concat @@ -430,7 +446,15 @@ :operations [{:type :set :attr :masked-group? :val true}]) - groups-to-unmask))] + groups-to-unmask) + (map #(array-map + :type :mod-obj + :page-id page-id + :id (:id %) + :operations [{:type :set + :attr :interactions + :val (:interactions %)}]) + interacting-shapes))] ;; (println "================ rchanges") ;; (cljs.pprint/pprint rchanges)