mirror of
https://github.com/penpot/penpot.git
synced 2025-03-28 15:41:25 -05:00
🐛 Fix problems with show in viewer and interactions
This commit is contained in:
parent
f8fad95fef
commit
c236e0765b
4 changed files with 40 additions and 106 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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')))))
|
|
@ -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."
|
||||
|
|
Loading…
Add table
Reference in a new issue