mirror of
https://github.com/penpot/penpot.git
synced 2026-11-02 08:00:36 +00:00
🐛 Skip update-shapes validation when changes have no page
generate-update-shapes only validates changes made on a page, and it checked that with (and page-id ...) after pcb/get-page-id. The getter now asserts that a page-id was given, so the check could never be false and changes on a component container would fail on the assert instead of skipping the validation. Add pcb/has-page-id? and check it before calling the getter. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
c16b439af9
commit
5ad391eafa
@ -1279,6 +1279,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)
|
||||
|
||||
@ -107,7 +107,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))
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
[app.common.files.changes-builder :as pcb]
|
||||
[app.common.geom.point :as gpt]
|
||||
[app.common.geom.shapes :as gsh]
|
||||
[app.common.logic.shapes :as cls]
|
||||
[app.common.schema :as sm]
|
||||
[app.common.schema.generators :as sg]
|
||||
[app.common.schema.test :as smt]
|
||||
@ -19,6 +20,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.shape :as cts]
|
||||
[app.common.types.tokens-lib :as ctob]
|
||||
@ -1189,3 +1191,22 @@
|
||||
{:apply-changes-local-library? true}))]
|
||||
|
||||
(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)))))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user