From 9c40563e278ec2858a3745c0a1887de7f6ad75fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 31 Jul 2026 13:37:59 +0200 Subject: [PATCH] wip --- common/src/app/common/files/changes.cljc | 14 +++++ .../test/common_tests/files/changes_test.cljc | 57 +++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 common/test/common_tests/files/changes_test.cljc diff --git a/common/src/app/common/files/changes.cljc b/common/src/app/common/files/changes.cljc index 34148aa0b2..66f27a37f1 100644 --- a/common/src/app/common/files/changes.cljc +++ b/common/src/app/common/files/changes.cljc @@ -1167,6 +1167,20 @@ (check-shape parent-id [parent-id]) shapes)))) +(defmethod components-changed :reorder-children + [file-data {:keys [page-id component-id parent-id]}] + (when (or page-id component-id) + (let [container (if page-id + (ctpl/get-page file-data page-id) + (get-in file-data [:components component-id])) + objects (:objects container) + xform (comp (filter :main-instance) + (map :component-id))] + (when (some? container) + (into #{} xform + (map #(ctn/get-shape container %) + (cons parent-id (cfh/get-parent-ids objects parent-id)))))))) + (defmethod components-changed :add-obj [file-data {:keys [parent-id page-id _component-id] :as change}] (when page-id diff --git a/common/test/common_tests/files/changes_test.cljc b/common/test/common_tests/files/changes_test.cljc new file mode 100644 index 0000000000..b06891cc0a --- /dev/null +++ b/common/test/common_tests/files/changes_test.cljc @@ -0,0 +1,57 @@ +;; This Source Code Form is subject to the terms of the Mozilla Public +;; License, v. 2.0. If a copy of the MPL was not distributed with this +;; file, You can obtain one at http://mozilla.org/MPL/2.0/. +;; +;; Copyright (c) KALEIDOS INC Sucursal en EspaƱa SL + +(ns common-tests.files.changes-test + (:require + [app.common.files.changes :as ch] + [app.common.uuid :as uuid] + [clojure.test :as t])) + +(defn- make-file + [page-id main-id copy-id] + (let [comp-id (uuid/next) + child1 (uuid/next) + child2 (uuid/next)] + {:pages-index {page-id {:id page-id + :objects {main-id {:id main-id + :type :frame + :main-instance true + :component-id comp-id + :shapes [child1 child2]} + child1 {:id child1 :parent-id main-id} + child2 {:id child2 :parent-id main-id} + copy-id {:id copy-id + :type :frame + :component-root true + :component-id comp-id + :shapes [(uuid/next) (uuid/next)]}}}} + :components {comp-id {:id comp-id + :main-instance-id main-id + :main-instance-page page-id}}})) + +(t/deftest components-changed-reorder-children + (t/testing "reorder-children in a main instance triggers component sync" + (let [page-id (uuid/next) + main-id (uuid/next) + copy-id (uuid/next) + file-data (make-file page-id main-id copy-id) + comp-id (-> file-data :components first key) + change {:type :reorder-children + :page-id page-id + :parent-id main-id + :shapes [(uuid/next) (uuid/next)]}] + (t/is (= #{comp-id} (ch/components-changed file-data change))))) + + (t/testing "reorder-children inside a plain copy does not trigger component sync" + (let [page-id (uuid/next) + main-id (uuid/next) + copy-id (uuid/next) + file-data (make-file page-id main-id copy-id) + change {:type :reorder-children + :page-id page-id + :parent-id copy-id + :shapes [(uuid/next) (uuid/next)]}] + (t/is (= #{} (ch/components-changed file-data change))))))