From c236e0765b27c6cb3d49b4f625686ac32bdb8220 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Fri, 11 Oct 2024 15:27:34 +0200 Subject: [PATCH] :bug: Fix problems with show in viewer and interactions --- CHANGES.md | 1 + common/src/app/common/logic/shapes.cljc | 15 ++-- .../logic/hide_in_viewer_test.cljc | 75 ------------------- .../app/main/data/workspace/interactions.cljs | 55 ++++++++------ 4 files changed, 40 insertions(+), 106 deletions(-) delete mode 100644 common/test/common_tests/logic/hide_in_viewer_test.cljc diff --git a/CHANGES.md b/CHANGES.md index 7b50269b0..8fb55004d 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -41,6 +41,7 @@ - Fix problem updating layout when toggle visibility in component copy [Github #5143](https://github.com/penpot/penpot/issues/5143) - Fix "Done" button on toolbar on inspect mode should go to design mode [Taiga #8933](https://tree.taiga.io/project/penpot/issue/8933) - Fix problem with shortcuts in text editor [Github #5078](https://github.com/penpot/penpot/issues/5078) +- Fix problems with show in viewer and interactions [Github #4868](https://github.com/penpot/penpot/issues/4868) ## 2.2.1 diff --git a/common/src/app/common/logic/shapes.cljc b/common/src/app/common/logic/shapes.cljc index 1bb1b109a..0e292847f 100644 --- a/common/src/app/common/logic/shapes.cljc +++ b/common/src/app/common/logic/shapes.cljc @@ -408,17 +408,12 @@ ;; Resize parent containers that need to (pcb/resize-parents parents)))) - - - (defn change-show-in-viewer [shape hide?] - (cond-> (assoc shape :hide-in-viewer hide?) - ;; When a frame is no longer shown in view mode, it cannot have interactions - hide? - (dissoc :interactions))) + (assoc shape :hide-in-viewer hide?)) (defn add-new-interaction [shape interaction] (-> shape - (update :interactions ctsi/add-interaction interaction) - ;; When a interaction is created, the frame must be shown in view mode - (dissoc :hide-in-viewer))) + (update :interactions ctsi/add-interaction interaction))) + +(defn show-in-viewer [shape] + (dissoc shape :hide-in-viewer)) diff --git a/common/test/common_tests/logic/hide_in_viewer_test.cljc b/common/test/common_tests/logic/hide_in_viewer_test.cljc deleted file mode 100644 index 051a4732e..000000000 --- a/common/test/common_tests/logic/hide_in_viewer_test.cljc +++ /dev/null @@ -1,75 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) KALEIDOS INC - -(ns common-tests.logic.hide-in-viewer-test - (:require - [app.common.files.changes-builder :as pcb] - [app.common.logic.shapes :as cls] - [app.common.test-helpers.compositions :as tho] - [app.common.test-helpers.files :as thf] - [app.common.test-helpers.ids-map :as thi] - [app.common.test-helpers.shapes :as ths] - [app.common.types.shape.interactions :as ctsi] - [clojure.test :as t])) - -(t/use-fixtures :each thi/test-fixture) - - -(t/deftest test-remove-show-in-view-mode-delete-interactions - (let [;; ==== Setup - - file (-> (thf/sample-file :file1) - (tho/add-frame :frame-dest) - (tho/add-frame :frame-origin) - (ths/add-interaction :frame-origin :frame-dest)) - - frame-origin (ths/get-shape file :frame-origin) - - page (thf/current-page file) - - - ;; ==== Action - changes (-> (pcb/empty-changes nil (:id page)) - (pcb/with-objects (:objects page)) - (pcb/update-shapes [(:id frame-origin)] #(cls/change-show-in-viewer % true))) - file' (thf/apply-changes file changes) - - ;; ==== Get - frame-origin' (ths/get-shape file' :frame-origin)] - - ;; ==== Check - (t/is (some? (:interactions frame-origin))) - (t/is (nil? (:interactions frame-origin'))))) - - - -(t/deftest test-add-new-interaction-updates-show-in-view-mode - (let [;; ==== Setup - - file (-> (thf/sample-file :file1) - (tho/add-frame :frame-dest :hide-in-viewer true) - (tho/add-frame :frame-origin :hide-in-viewer true)) - frame-dest (ths/get-shape file :frame-dest) - frame-origin (ths/get-shape file :frame-origin) - - page (thf/current-page file) - - ;; ==== Action - new-interaction (-> ctsi/default-interaction - (ctsi/set-destination (:id frame-dest)) - (assoc :position-relative-to (:id frame-dest))) - - changes (-> (pcb/empty-changes nil (:id page)) - (pcb/with-objects (:objects page)) - (pcb/update-shapes [(:id frame-origin)] #(cls/add-new-interaction % new-interaction))) - file' (thf/apply-changes file changes) - - ;; ==== Get - frame-origin' (ths/get-shape file' :frame-origin)] - - ;; ==== Check - (t/is (true? (:hide-in-viewer frame-origin))) - (t/is (nil? (:hide-in-viewer frame-origin'))))) diff --git a/frontend/src/app/main/data/workspace/interactions.cljs b/frontend/src/app/main/data/workspace/interactions.cljs index b2387e270..e8dfd1253 100644 --- a/frontend/src/app/main/data/workspace/interactions.cljs +++ b/frontend/src/app/main/data/workspace/interactions.cljs @@ -147,11 +147,15 @@ ptk/WatchEvent (watch [_ state _] (let [page-id (or page-id (:current-page-id state))] - (rx/of (dwsh/update-shapes - [shape-id] - (fn [shape] - (cls/add-new-interaction shape interaction)) - {:page-id page-id})))))) + (rx/of (dwsh/update-shapes [shape-id] + (fn [shape] + (cls/add-new-interaction shape interaction)) + {:page-id page-id}) + + (when (:destination interaction) + (dwsh/update-shapes [(:destination interaction)] + cls/show-in-viewer + {:page-id page-id}))))))) (defn add-new-interaction ([shape] (add-new-interaction shape nil)) @@ -167,15 +171,20 @@ flows (get page :objects) flow (ctp/get-frame-flow flows (:id frame))] (rx/concat - (rx/of (dwsh/update-shapes [(:id shape)] - (fn [shape] - (let [new-interaction (-> ctsi/default-interaction - (ctsi/set-destination destination) - (assoc :position-relative-to (:id shape)))] - (cls/add-new-interaction shape new-interaction))))) - (when (and (not (connected-frame? objects (:id frame))) - (nil? flow)) - (rx/of (add-flow (:id frame)))))))))) + (rx/of (dwsh/update-shapes + [(:id shape)] + (fn [shape] + (let [new-interaction (-> ctsi/default-interaction + (ctsi/set-destination destination) + (assoc :position-relative-to (:id shape)))] + (cls/add-new-interaction shape new-interaction)))) + + (when destination + (dwsh/update-shapes [destination] cls/show-in-viewer)) + + (when (and (not (connected-frame? objects (:id frame))) + (nil? flow)) + (add-flow (:id frame)))))))))) (defn remove-interaction ([shape index] @@ -186,8 +195,7 @@ (watch [_ _ _] (rx/of (dwsh/update-shapes [(:id shape)] (fn [shape] - (update shape :interactions - ctsi/remove-interaction index)) + (update shape :interactions ctsi/remove-interaction index)) {:page-id page-id})))))) (defn update-interaction ([shape index update-fn] @@ -196,11 +204,16 @@ (ptk/reify ::update-interaction ptk/WatchEvent (watch [_ _ _] - (rx/of (dwsh/update-shapes [(:id shape)] - (fn [shape] - (update shape :interactions - ctsi/update-interaction index update-fn)) - options)))))) + (let [interactions (ctsi/update-interaction (:interactions shape) index update-fn) + interaction (nth interactions index)] + (rx/of (dwsh/update-shapes + [(:id shape)] + (fn [shape] + (assoc shape :interactions interactions)) + options) + + (when (some? (:destination interaction)) + (dwsh/update-shapes [(:destination interaction)] cls/show-in-viewer options)))))))) (defn remove-all-interactions-nav-to "Remove all interactions that navigate to the given frame."