diff --git a/common/src/app/common/files/changes_builder.cljc b/common/src/app/common/files/changes_builder.cljc index 9ea2b0c11a..a42e1dcedb 100644 --- a/common/src/app/common/files/changes_builder.cljc +++ b/common/src/app/common/files/changes_builder.cljc @@ -1293,6 +1293,10 @@ [changes] (contains? (meta changes) ::page)) +(defn has-page-id? + [changes] + (contains? (meta changes) ::page-id)) + (defn set-text-content [changes id content prev-content] (assert-page-id! changes) diff --git a/common/src/app/common/logic/shapes.cljc b/common/src/app/common/logic/shapes.cljc index 552e57c385..56408cc7df 100644 --- a/common/src/app/common/logic/shapes.cljc +++ b/common/src/app/common/logic/shapes.cljc @@ -108,7 +108,9 @@ (not ignore-touched) (generate-unapply-tokens objects changed-sub-attr changed-item-index)) - page-id (pcb/get-page-id changes) + ;; Only validate changes on a page (not on a component container) + page-id (when (pcb/has-page-id? changes) + (pcb/get-page-id changes)) modified-components (ctn/get-all-instance-roots objects ids) changes (if (and page-id (seq modified-components)) diff --git a/common/test/common_tests/files_changes_test.cljc b/common/test/common_tests/files_changes_test.cljc index 89e331089f..ca73e9b020 100644 --- a/common/test/common_tests/files_changes_test.cljc +++ b/common/test/common_tests/files_changes_test.cljc @@ -13,6 +13,7 @@ [app.common.files.helpers :as cfh] [app.common.geom.point :as gpt] [app.common.geom.shapes :as gsh] + [app.common.logic.shapes :as cls] [app.common.math :as mth] [app.common.schema :as sm] [app.common.schema.generators :as sg] @@ -22,6 +23,7 @@ [app.common.test-helpers.files :as thf] [app.common.test-helpers.shapes :as ths] [app.common.time :as ct] + [app.common.types.container :as ctn] [app.common.types.file :as ctf] [app.common.types.page :as ctp] [app.common.types.shape :as cts] @@ -1623,3 +1625,22 @@ (t/is (= 2 (count (:redo-changes changes)))))) +(t/deftest update-shapes-without-page-skips-validation + ;; generate-update-shapes only validates when the changes have a page. For + ;; changes on a component container it must not fail on the page-id getter. + (let [file (-> (thf/sample-file :file1) + (tho/add-simple-component :c01 :m01 :r01)) + page (thf/current-page file) + main (ths/get-shape file :m01) + comp (thc/get-component file :c01) + + changes (cls/generate-update-shapes (-> (pcb/empty-changes nil) + (pcb/with-container (ctn/make-container comp :component))) + [(:id main)] + #(assoc % :name "New name") + (:objects page) + {})] + + (t/is (seq (:redo-changes changes))) + (t/is (not-any? #(= :validate-shapes (:type %)) (:redo-changes changes))))) +