From 0ed582ebc5e5f4ca33b470cf27ec9b4339517c69 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 22 Apr 2024 13:20:52 +0200 Subject: [PATCH] :recycle: Components refactor: generator for detach-component --- common/src/app/common/files/libraries_helpers.cljc | 12 +++++++++++- frontend/src/app/main/data/workspace/libraries.cljs | 9 ++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/common/src/app/common/files/libraries_helpers.cljc b/common/src/app/common/files/libraries_helpers.cljc index bfe78afb07..4813b9711d 100644 --- a/common/src/app/common/files/libraries_helpers.cljc +++ b/common/src/app/common/files/libraries_helpers.cljc @@ -846,7 +846,7 @@ 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." [changes id new-name library-data components-v2] (let [[path name] (cfh/parse-path-name new-name) @@ -1808,4 +1808,14 @@ (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)))) + diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 184d559333..105d0a2136 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -554,13 +554,10 @@ (watch [it state _] (let [file (wsh/get-local-file state) page-id (get state :current-page-id) - container (cfh/get-container file :page page-id) libraries (wsh/get-libraries state) changes (-> (pcb/empty-changes it) - (pcb/with-container container) - (pcb/with-objects (:objects container)) - (cflh/generate-detach-instance container libraries id))] + (cflh/generate-detach-component id file page-id libraries))] (rx/of (dch/commit-changes changes)))))) @@ -597,9 +594,7 @@ (reduce (fn [changes id] (cflh/generate-detach-instance changes container libraries id)) - (-> (pcb/empty-changes it) - (pcb/with-container container) - (pcb/with-objects objects)) + (pcb/empty-changes it) selected))] (rx/of (when can-detach?