🐛 Fix wrong behavior on shape/canvas hide/show options.

This commit is contained in:
Andrey Antukh 2020-02-20 12:08:06 +01:00
parent 8f77a59a97
commit 6988f0a35e
2 changed files with 33 additions and 15 deletions

View file

@ -1757,6 +1757,7 @@
[id]
(us/verify ::us/uuid id)
(ptk/reify ::hide-shape
IBatchedChange
ptk/UpdateEvent
(update [_ state]
(impl-update-shape-hidden state id true))))
@ -1764,24 +1765,41 @@
(defn show-shape
[id]
(us/verify ::us/uuid id)
(ptk/reify ::hide-shape
(ptk/reify ::show-shape
IBatchedChange
ptk/UpdateEvent
(update [_ state]
(impl-update-shape-hidden state id false))))
(defn hide-canvas
[id]
(us/verify ::us/uuid id)
(ptk/reify ::hide-shape
IBatchedChange
ptk/UpdateEvent
(update [_ state]
(let [hide #(impl-update-shape-hidden %1 %2 true)
ids (->> (vals (get-in state [:workspace-data :shapes-by-id]))
(filter #(= (:canvas %) id))
(map :id))]
(reduce hide state (cons id ids))))))
(defn show-canvas
[id]
(us/verify ::us/uuid id)
(ptk/reify ::hide-shape
IBatchedChange
ptk/UpdateEvent
(update [_ state]
(let [show #(impl-update-shape-hidden %1 %2 false)
ids (->> (vals (get-in state [:workspace-data :shapes-by-id]))
(filter #(= (:canvas %) id))
(map :id))]
(reduce show state (cons id ids))))))
(defn- impl-update-shape-hidden
[state id hidden?]
(let [type (get-in state [:workspace-data :shapes-by-id id :type])
state (update-in state [:workspace-data :shapes-by-id id] assoc :hidden hidden?)]
(cond-> state
(= type :canvas)
(update-in [:workspace-data :shapes-by-id]
(fn [shapes]
(reduce-kv (fn [shapes key {:keys [canvas] :as val}]
(cond-> shapes
(= id canvas) (update key assoc :hidden hidden?)))
shapes
shapes))))))
(assoc-in state [:workspace-data :shapes-by-id id :hidden] hidden?))
;; --- Shape Blocking

View file

@ -173,8 +173,8 @@
(fn [event]
(dom/stop-propagation event)
(if (:hidden canvas)
(st/emit! (dw/show-shape (:id canvas)))
(st/emit! (dw/hide-shape (:id canvas)))))
(st/emit! (dw/show-canvas (:id canvas)))
(st/emit! (dw/hide-canvas (:id canvas)))))
select-shape
(fn [event]
@ -274,7 +274,7 @@
data (mf/deref refs/workspace-data)
shapes-map (:shapes-by-id data)
strip #(select-keys % [:id :canvas :name :type])
strip #(select-keys % [:id :canvas :name :type :hidden :blocked])
canvas (->> (:canvas data)
(map #(get shapes-map %))