🐛 Keep variant property order past eight properties (#13014)

This commit is contained in:
Pablo Alba 2026-11-16 09:30:29 +01:00 committed by GitHub
parent fa6af23d75
commit 77c87d16f1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 73 additions and 9 deletions

View File

@ -59,7 +59,7 @@
[data objects variant-id]
(->> (find-variant-components data objects variant-id)
(mapcat :variant-properties)
(group-by :name)
(ctv/group-properties-by-name)
(mapv (fn [[k v]]
(let [mdata (reduce merge {} (map meta v))]
(with-meta {:name k

View File

@ -315,6 +315,16 @@
props2)
:props)))
(defn group-properties-by-name
"Group properties by :name, preserving first-seen name order.
clojure.core/group-by loses order once maps grow past ArrayMap's
8-key threshold."
[props]
(reduce (fn [m p]
(update m (:name p) (fnil conj []) p))
(d/ordered-map)
props))
(defn compare-properties
"Compares vectors of properties keeping the value if it is the same for all
or setting a custom value where their values do not coincide"
@ -322,7 +332,7 @@
(compare-properties props-list nil))
([props-list distinct-mark]
(let [grouped (group-by :name (apply concat props-list))
(let [grouped (group-properties-by-name (apply concat props-list))
check-values (fn [values]
(let [vals (map :value values)]
(if (apply = vals)

View File

@ -7,6 +7,7 @@
(ns common-tests.logic.variants-test
(:require
[app.common.files.changes-builder :as pcb]
[app.common.files.variant :as cfv]
[app.common.geom.point :as gpt]
[app.common.logic.libraries :as cll]
[app.common.logic.shapes :as cls]
@ -722,3 +723,16 @@
(cpn/merge-path-item (:path comp2') (:name comp2'))))
(t/is (some? (:variant-id comp1')))
(t/is (some? (:variant-id comp2')))))
(t/deftest test-extract-properties-values-preserves-order-past-eight
(let [names (mapv #(str "Property " %) (range 1 10))
props1 (mapv (fn [n] {:name n :value (str n "-a")}) names)
props2 (mapv (fn [n] {:name n :value (str n "-b")}) names)
file (-> (thf/sample-file :file1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02)
(thc/update-component :c01 {:variant-properties props1})
(thc/update-component :c02 {:variant-properties props2}))
page (thf/current-page file)
v-id (:id (ths/get-shape file :v01))
result (cfv/extract-properties-values (:data file) (:objects page) v-id)]
(t/is (= names (mapv :name result)))))

View File

@ -119,6 +119,12 @@
(t/is (= (ctv/compare-properties [props-1 props-2 props-3] "&")
[{:name "border" :value "&"} {:name "color" :value "&"}])))))
(t/deftest compare-properties-preserves-order-past-eight
(let [names (mapv #(str "Property " %) (range 1 10))
props1 (mapv (fn [n] {:name n :value "a"}) names)
props2 (mapv (fn [n] {:name n :value "b"}) names)]
(t/is (= names (mapv :name (ctv/compare-properties [props1 props2]))))))
(t/deftest check-belong-same-variant
(let [components-1 [{:variant-id "a variant"} {:variant-id "a variant"}]

View File

@ -235,14 +235,10 @@
(let [data (dsh/lookup-file-data state)]
(with-main-page data {:variant-id variant-id}
(fn [page-id objects]
(let [variant-components (cfv/find-variant-components data objects variant-id)
properties-empty-pos (->> variant-components
(mapcat :variant-properties)
(group-by :name)
(let [properties-empty-pos (->> (cfv/extract-properties-values data objects variant-id)
(map-indexed
(fn [i [_ v]]
[i (->> v
(map :value)
(fn [i {:keys [value]}]
[i (->> value
(remove empty?)
empty?)]))
(reverse))

View File

@ -35,6 +35,26 @@
(thv/add-variant-two-properties :v01 :c01 :m01 :c02 :m02)
(cthf/add-sample-page :page2)))
(defn- nine-property-file-with-empty-middle
"Nine properties; Property 5 is empty on every variant."
[]
(let [names (mapv #(str "Property " %) (range 1 10))
props1 (mapv (fn [n i]
{:name n :value (if (= i 4) "" (str "a" (inc i)))})
names
(range))
props2 (mapv (fn [n i]
{:name n :value (if (= i 4) "" (str "b" (inc i)))})
names
(range))]
(-> (cthf/sample-file :file1 :page-label :page1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02)
(cthc/update-component :c01 {:variant-properties props1})
(cthc/update-component :c02 {:variant-properties props2})
(cths/update-shape :m01 :variant-name (ctv/properties-to-name props1))
(cths/update-shape :m02 :variant-name (ctv/properties-to-name props2))
(cthf/add-sample-page :page2))))
(defn- run
[file events done assert-fn]
(ths/run-store
@ -124,6 +144,24 @@
(t/is (= "crítica" (-> props second :value)))
(t/is (= (ctv/properties-to-name props) (variant-name file :m01)))))))))
(t/deftest remove-empty-properties-preserves-order-past-eight
(t/async
done
(let [file (nine-property-file-with-empty-middle)
variant-id (cthi/id :v01)
expected ["Property 1" "Property 2" "Property 3" "Property 4"
"Property 6" "Property 7" "Property 8" "Property 9"]]
(run file
[(dwv/remove-empty-properties variant-id)]
done
(fn [state]
(let [file (ths/get-file-from-state state)
names1 (mapv :name (:variant-properties (cthc/get-component file :c01)))
names2 (mapv :name (:variant-properties (cthc/get-component file :c02)))]
(t/is (= expected names1))
(t/is (= expected names2))
(t/is (not-any? #(= "Property 5" %) names1))))))))
(t/deftest update-property-name-from-another-page
(t/async
done