diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index caad391b8..eea620e33 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -202,7 +202,7 @@ (when (some? head-component) (get-ref-shape (:data head-file) head-component shape))))] - (d/seek find-ref-shape-in-head parent-heads))) + (some find-ref-shape-in-head parent-heads))) (defn find-remote-shape "Recursively go back by the :shape-ref of the shape until find the correct shape of the original component" 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") diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs index b3739681f..5327e45c1 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs @@ -522,7 +522,8 @@ (when open? [:div {:class (stl/css :element-content)} [:div {:class (stl/css-case :component-wrapper true - :with-actions show-menu?)} + :with-actions show-menu? + :without-actions (not show-menu?))} [:button {:class (stl/css-case :component-name-wrapper true :with-main (and can-swap? (not multi)) :swappeable (and can-swap? (not swap-opened?))) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.scss b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.scss index 16145e413..cda5dfe26 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.scss +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.scss @@ -51,6 +51,15 @@ grid-template-columns: 1fr $s-28; gap: $s-2; } + + &.without-actions { + padding-right: 0.5rem; + .component-name-wrapper { + width: 100%; + + border-radius: $br-8; + } + } } .component-name-wrapper {