From f91d60eeb6e060fe1d9958ab3473424d39b2a2af Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 22 Apr 2024 13:09:56 +0200 Subject: [PATCH] :recycle: Components refactor: generator for rename-component --- .../app/common/files/libraries_helpers.cljc | 6 ++++++ .../app/main/data/workspace/libraries.cljs | 21 +++---------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/common/src/app/common/files/libraries_helpers.cljc b/common/src/app/common/files/libraries_helpers.cljc index a31aa948f..0bb7d0e3a 100644 --- a/common/src/app/common/files/libraries_helpers.cljc +++ b/common/src/app/common/files/libraries_helpers.cljc @@ -847,6 +847,7 @@ (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) update-fn @@ -864,6 +865,9 @@ (pcb/with-library-data library-data) (pcb/update-component id update-fn)))) + + + (defn generate-sync-shape-inverse "Generate changes to update the component a shape is linked to, from the values in the shape and all its children." @@ -1785,3 +1789,5 @@ [:component-root])] [root (:id root-shape) changes])) + + diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index c88a6b8e9..fcee4d366 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -414,25 +414,10 @@ (let [new-name (str/trim new-name)] (if (str/empty? new-name) (rx/empty) - (let [data (get state :workspace-data) - [path name] (cfh/parse-path-name new-name) + (let [library-data (get state :workspace-data) components-v2 (features/active-feature? state "components/v2") - - update-fn - (fn [component] - (cond-> component - :always - (assoc :path path - :name name) - - (not components-v2) - (update :objects - ;; Give the same name to the root shape - #(assoc-in % [id :name] name)))) - - changes (-> (pcb/empty-changes it) - (pcb/with-library-data data) - (pcb/update-component id update-fn))] + changes (-> (pcb/empty-changes it) + (cflh/generate-rename-component id new-name library-data components-v2))] (rx/of (dch/commit-changes changes))))))))