From 294ce7bb1b9e3cb3e1a17198619cfefc37dc6312 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 12 May 2025 15:50:06 +0200 Subject: [PATCH] :bug: Fix variants override for nested components (#6421) --- common/src/app/common/logic/libraries.cljc | 12 ++++++------ common/src/app/common/logic/variants.cljc | 11 +++-------- frontend/src/app/main/data/workspace/libraries.cljs | 2 +- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/common/src/app/common/logic/libraries.cljc b/common/src/app/common/logic/libraries.cljc index 265b8b7515..8bcf3c6196 100644 --- a/common/src/app/common/logic/libraries.cljc +++ b/common/src/app/common/logic/libraries.cljc @@ -1757,18 +1757,18 @@ (let [attr-group (get ctk/sync-attrs attr) [roperations' uoperations'] (if (or - ;; If the attribute is not valid for the destiny, don't copy it + ;; If the attribute is not valid for the destiny, don't copy it (not (cts/is-allowed-attr? attr (:type dest-shape))) - ;; If the values are already equal, don't copy it + ;; If the values are already equal, don't copy it (= (get origin-shape attr) (get dest-shape attr)) - ;; If the referenced shape on the original component doesn't have the same value, don't copy it - ;; Exceptions: :points :selrect and :content can be different + ;; If the referenced shape on the original component doesn't have the same value, don't copy it + ;; Exceptions: :points :selrect and :content can be different (and (not (contains? #{:points :selrect :content} attr)) (not= (get origin-ref-shape attr) (get dest-shape attr))) - ;; The :content attr cant't be copied to elements of different type + ;; The :content attr cant't be copied to elements of different type (and (= attr :content) (not= (:type origin-shape) (:type dest-shape))) - ;; If the attr is not touched in the origin shape, don't copy it + ;; If the attr is not touched in the origin shape, don't copy it (not (touched-origin attr-group))) [roperations uoperations] (add-update-attr-operations attr dest-shape origin-shape roperations uoperations touched))] diff --git a/common/src/app/common/logic/variants.cljc b/common/src/app/common/logic/variants.cljc index 1e76ad0959..032e9588d5 100644 --- a/common/src/app/common/logic/variants.cljc +++ b/common/src/app/common/logic/variants.cljc @@ -5,7 +5,6 @@ [app.common.files.variant :as cfv] [app.common.logic.libraries :as cll] [app.common.logic.variant-properties :as clvp] - [app.common.types.components-list :as ctcl] [app.common.types.container :as ctn] [app.common.types.file :as ctf] [app.common.types.variant :as ctv])) @@ -48,12 +47,8 @@ (pcb/change-parent (:parent-id shape) [new-shape] 0)))) (defn generate-keep-touched - [changes new-shape original-shape original-shapes page] - (let [data (pcb/get-library-data changes) - objects (pcb/get-objects changes) - - orig-comp (ctcl/get-component data (:component-id original-shape) true) - + [changes new-shape original-shape original-shapes page libraries] + (let [objects (pcb/get-objects changes) new-path-map (into {} (map (fn [shape] {(generate-path "" objects (:id new-shape) shape) shape})) (cfh/get-children-with-self objects (:id new-shape))) @@ -65,7 +60,7 @@ (fn [changes touched-shape] (let [path (generate-path "" orig-objects (:id original-shape) touched-shape) related-shape (get new-path-map path) - orig-ref-shape (ctf/get-ref-shape data orig-comp touched-shape)] + orig-ref-shape (ctf/find-ref-shape nil container libraries touched-shape)] (if related-shape (cll/update-attrs-on-switch changes related-shape touched-shape new-shape original-shape orig-ref-shape container) diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 1f5fb2b884..67c9d18715 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -1013,7 +1013,7 @@ (cll/generate-component-swap objects shape ldata page libraries id-new-component index target-cell keep-props-values)) changes (if keep-touched? - (clv/generate-keep-touched changes new-shape shape orig-shapes page) + (clv/generate-keep-touched changes new-shape shape orig-shapes page libraries) changes)] (rx/of