From 2124aba21f3b869b34ecfb59de870577109331a8 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 20 Jan 2016 21:45:22 +0200 Subject: [PATCH] Fix group deletion mechanism. --- src/uxbox/data/workspace.cljs | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/uxbox/data/workspace.cljs b/src/uxbox/data/workspace.cljs index 8f4d8dee7a..492c824cbb 100644 --- a/src/uxbox/data/workspace.cljs +++ b/src/uxbox/data/workspace.cljs @@ -156,18 +156,23 @@ (defn delete-shape "Remove the shape using its id." - [sid] - (reify - rs/UpdateEvent - (-apply-update [_ state] - (let [pageid (get-in state [:shapes-by-id sid :page]) - shapes (as-> state $ - (get-in $ [:pages-by-id pageid :shapes]) - (remove #(= % sid) $) - (into [] $))] + [id] + (letfn [(dissoc-shape [state {:keys [id] :as shape}] + (if (= (:type shape) :builtin/group) + (let [state (update-in state [:shapes-by-id] dissoc id)] + (->> (map #(get-in state [:shapes-by-id %]) (:items shape)) + (reduce dissoc-shape state))) + (update-in state [:shapes-by-id] dissoc id)))] + (reify + rs/UpdateEvent + (-apply-update [_ state] + (let [shape (get-in state [:shapes-by-id id]) + pageid (:page shape) + shapes (get-in state [:pages-by-id pageid :shapes]) + shapes (into [] (remove #(= % id) shapes))] (as-> state $ (assoc-in $ [:pages-by-id pageid :shapes] shapes) - (update-in $ [:shapes-by-id] dissoc sid)))))) + (dissoc-shape $ shape))))))) (defn move-shape "Mark a shape selected for drawing in the canvas."