diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 23e69b8f5..e43d75b23 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -609,24 +609,27 @@ (ptk/reify ::detach-selected-components ptk/WatchEvent (watch [it state _] - (let [page-id (:current-page-id state) - objects (wsh/lookup-page-objects state page-id) - file (wsh/get-local-file state) - container (cfh/get-container file :page page-id) - libraries (wsh/get-libraries state) - selected (->> state - (wsh/lookup-selected) - (cfh/clean-loops objects)) + (let [page-id (:current-page-id state) + objects (wsh/lookup-page-objects state page-id) + file (wsh/get-local-file state) + container (cfh/get-container file :page page-id) + libraries (wsh/get-libraries state) + selected (->> state + (wsh/lookup-selected) + (cfh/clean-loops objects)) + selected-objects (map #(get objects %) selected) + can-detach? (every? #(not (ctn/has-any-copy-parent? objects %)) selected-objects) + changes (when can-detach? + (reduce + (fn [changes id] + (dwlh/generate-detach-instance changes libraries container id)) + (-> (pcb/empty-changes it) + (pcb/with-container container) + (pcb/with-objects objects)) + selected))] - changes (reduce - (fn [changes id] - (dwlh/generate-detach-instance changes libraries container id)) - (-> (pcb/empty-changes it) - (pcb/with-container container) - (pcb/with-objects objects)) - selected)] - - (rx/of (dch/commit-changes changes)))))) + (rx/of (when can-detach? + (dch/commit-changes changes))))))) (defn nav-to-component-file [file-id component] diff --git a/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs b/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs index 3ef6fb6ad..f8f7bb6c5 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/assets/common.cljs @@ -355,6 +355,9 @@ (not (ctn/has-any-copy-parent? objects shape)) (cfh/component-touched? objects (:id shape))))) + can-detach? (and (seq copies) + (every? #(not (ctn/has-any-copy-parent? objects %)) copies)) + do-detach-component #(st/emit! (dwl/detach-components (map :id copies))) @@ -420,7 +423,7 @@ (when (and (not multi) main-instance? local-component? lacks-annotation? components-v2) {:msg "workspace.shape.menu.create-annotation" :action do-create-annotation}) - (when (seq copies) + (when can-detach? {:msg (if (> (count copies) 1) "workspace.shape.menu.detach-instances-in-bulk" "workspace.shape.menu.detach-instance")