This commit is contained in:
Andrés Moya 2026-07-31 13:37:59 +02:00
parent a3feb4ef3b
commit 9c40563e27
2 changed files with 71 additions and 0 deletions

View File

@ -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

View File

@ -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))))))