♻️ Components refactor: generator for detach-component

This commit is contained in:
Pablo Alba 2024-04-22 13:20:52 +02:00 committed by Andrés Moya
parent 7d44eef4ab
commit 0ed582ebc5
2 changed files with 13 additions and 8 deletions

View file

@ -846,7 +846,7 @@
components-v2)))) components-v2))))
(defn- generate-rename-component (defn generate-rename-component
"Generate the changes for rename the component with the given id, in the current file library." "Generate the changes for rename the component with the given id, in the current file library."
[changes id new-name library-data components-v2] [changes id new-name library-data components-v2]
(let [[path name] (cfh/parse-path-name new-name) (let [[path name] (cfh/parse-path-name new-name)
@ -1808,4 +1808,14 @@
(assoc changes :file-id library-id))) (assoc changes :file-id library-id)))
(defn generate-detach-component
"Generate changes for remove all references to components in the shape,
with the given id and all its children, at the current page."
[changes id file page-id libraries]
(let [container (cfh/get-container file :page page-id)]
(-> changes
(pcb/with-container container)
(pcb/with-objects (:objects container))
(generate-detach-instance container libraries id))))

View file

@ -554,13 +554,10 @@
(watch [it state _] (watch [it state _]
(let [file (wsh/get-local-file state) (let [file (wsh/get-local-file state)
page-id (get state :current-page-id) page-id (get state :current-page-id)
container (cfh/get-container file :page page-id)
libraries (wsh/get-libraries state) libraries (wsh/get-libraries state)
changes (-> (pcb/empty-changes it) changes (-> (pcb/empty-changes it)
(pcb/with-container container) (cflh/generate-detach-component id file page-id libraries))]
(pcb/with-objects (:objects container))
(cflh/generate-detach-instance container libraries id))]
(rx/of (dch/commit-changes changes)))))) (rx/of (dch/commit-changes changes))))))
@ -597,9 +594,7 @@
(reduce (reduce
(fn [changes id] (fn [changes id]
(cflh/generate-detach-instance changes container libraries id)) (cflh/generate-detach-instance changes container libraries id))
(-> (pcb/empty-changes it) (pcb/empty-changes it)
(pcb/with-container container)
(pcb/with-objects objects))
selected))] selected))]
(rx/of (when can-detach? (rx/of (when can-detach?