⚡ Validate only the variant container in variant generators

Validating a variant container already checks each of its main
instances, so listing the mains next to it repeated the work. Each id
costs a pass over the whole page, so a variant with N components cost
N+1 passes per call, and each error was reported twice.

The generators in variant_properties now validate only the container.
generate-update-property-value and generate-set-variant-error fall back
to the main instance when the component is not a variant. Before, they
emitted a nil id, which fails the :validate-shapes schema.

Add a test that generate-set-variant-error on a component that is not a
variant produces valid changes.

AI-assisted-by: claude-opus-5-5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Eva Marco 2026-09-29 16:45:39 +02:00
parent 26102fb412
commit 42da392e47
2 changed files with 26 additions and 7 deletions

View File

@ -42,7 +42,7 @@
changes
related-components)
ids-to-validate (conj (mapv :main-instance-id related-components) variant-id)
ids-to-validate [variant-id]
changes (pcb/validate-shapes changes
(pcb/get-page-id changes)
@ -74,7 +74,7 @@
changes
related-components)
ids-to-validate (conj (mapv :main-instance-id related-components) variant-id)
ids-to-validate [variant-id]
changes (pcb/validate-shapes changes
(pcb/get-page-id changes)
@ -97,7 +97,9 @@
(update pos assoc :value value)
ctv/properties-to-name)
ids-to-validate [main-id (:variant-id component)]]
ids-to-validate (if-let [variant-id (:variant-id component)]
[variant-id]
[main-id])]
(-> changes
(pcb/update-component component-id #(assoc-in % [:variant-properties pos :value] value)
{:apply-changes-local-library? true})
@ -118,7 +120,9 @@
component (ctcl/get-component data component-id true)]
(if component
(let [main-id (:main-instance-id component)
ids-to-validate [main-id (:variant-id component)]]
ids-to-validate (if-let [variant-id (:variant-id component)]
[variant-id]
[main-id])]
(-> changes
(pcb/update-shapes [main-id] (if (nil? value)
#(dissoc % :variant-error)
@ -157,7 +161,7 @@
related-components)]
(if (identical? changes changes')
changes
(let [ids-to-validate (conj (mapv :main-instance-id related-components) variant-id)]
(let [ids-to-validate [variant-id]]
(pcb/validate-shapes changes'
(pcb/get-page-id changes')
ids-to-validate
@ -220,7 +224,7 @@
(if (or skip-validation? (empty? related-components))
changes
(let [ids-to-validate (conj (mapv :main-instance-id related-components) variant-id)]
(let [ids-to-validate [variant-id]]
(pcb/validate-shapes changes
(pcb/get-page-id changes)
ids-to-validate
@ -360,7 +364,7 @@
(if (or skip-validation? (zero? num-shapes) (empty? shapes))
changes
(let [ids-to-validate (conj (mapv :id shapes) variant-id)]
(let [ids-to-validate [variant-id]]
(pcb/validate-shapes changes
(pcb/get-page-id changes)
ids-to-validate

View File

@ -6,6 +6,7 @@
(ns common-tests.logic.variant-properties-test
(:require
[app.common.files.changes :as cfc]
[app.common.files.changes-builder :as pcb]
[app.common.logic.shapes :as cls]
[app.common.logic.variant-properties :as clvp]
@ -359,6 +360,20 @@
(t/is (nil? (:variant-error main01')))))
(t/deftest test-set-variant-error-non-variant-component
(let [file (-> (thf/sample-file :file1)
(tho/add-simple-component :c01 :m01 :sh01))
page (thf/current-page file)
c01-id (:id (thc/get-component file :c01))
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clvp/generate-set-variant-error c01-id "bad=value"))]
(t/is (cfc/check-changes (:redo-changes changes)))))
;; =============================================================================
;; generate-reorder-variant-poperties tests
;; =============================================================================