0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-03 04:49:03 -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

@ -617,16 +617,19 @@
selected (->> state selected (->> state
(wsh/lookup-selected) (wsh/lookup-selected)
(cfh/clean-loops objects)) (cfh/clean-loops objects))
selected-objects (map #(get objects %) selected)
changes (reduce can-detach? (every? #(not (ctn/has-any-copy-parent? objects %)) selected-objects)
changes (when can-detach?
(reduce
(fn [changes id] (fn [changes id]
(dwlh/generate-detach-instance changes libraries container id)) (dwlh/generate-detach-instance changes libraries container id))
(-> (pcb/empty-changes it) (-> (pcb/empty-changes it)
(pcb/with-container container) (pcb/with-container container)
(pcb/with-objects objects)) (pcb/with-objects objects))
selected)] selected))]
(rx/of (dch/commit-changes changes)))))) (rx/of (when can-detach?
(dch/commit-changes changes)))))))
(defn nav-to-component-file (defn nav-to-component-file
[file-id component] [file-id component]

View file

@ -355,6 +355,9 @@
(not (ctn/has-any-copy-parent? objects shape)) (not (ctn/has-any-copy-parent? objects shape))
(cfh/component-touched? objects (:id shape))))) (cfh/component-touched? objects (:id shape)))))
can-detach? (and (seq copies)
(every? #(not (ctn/has-any-copy-parent? objects %)) copies))
do-detach-component do-detach-component
#(st/emit! (dwl/detach-components (map :id copies))) #(st/emit! (dwl/detach-components (map :id copies)))
@ -420,7 +423,7 @@
(when (and (not multi) main-instance? local-component? lacks-annotation? components-v2) (when (and (not multi) main-instance? local-component? lacks-annotation? components-v2)
{:msg "workspace.shape.menu.create-annotation" {:msg "workspace.shape.menu.create-annotation"
:action do-create-annotation}) :action do-create-annotation})
(when (seq copies) (when can-detach?
{:msg (if (> (count copies) 1) {:msg (if (> (count copies) 1)
"workspace.shape.menu.detach-instances-in-bulk" "workspace.shape.menu.detach-instances-in-bulk"
"workspace.shape.menu.detach-instance") "workspace.shape.menu.detach-instance")