0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-23 23:18:48 -05:00

🐛 Fix user can detach a copy inside a copy

This commit is contained in:
Pablo Alba 2024-02-21 18:15:49 +01:00 committed by Alejandro Alonso
parent 418ec34880
commit 4390df4b48
2 changed files with 24 additions and 18 deletions

View file

@ -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]

View file

@ -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")