🐛 Fix create properties with a default value instead of an empty one (#7033)

This commit is contained in:
luisδμ
2025-07-31 15:01:51 +02:00
committed by GitHub
parent 63bfbbb3c6
commit ff1d26294a
3 changed files with 51 additions and 9 deletions

View File

@@ -77,7 +77,7 @@
(defn generate-add-new-property
[changes variant-id & {:keys [fill-values? property-name]}]
[changes variant-id & {:keys [fill-values? property-name property-value]}]
(let [data (pcb/get-library-data changes)
objects (pcb/get-objects changes)
related-components (cfv/find-variant-components data objects variant-id)
@@ -95,13 +95,17 @@
update-props #(-> (d/nilv % [])
(conj {:name property-name
:value (if fill-values? (str ctv/value-prefix num) "")}))
:value (cond fill-values? (str ctv/value-prefix num)
property-value property-value
:else "")}))
update-name #(if fill-values?
(if (str/empty? %)
(str ctv/value-prefix num)
(str % ", " ctv/value-prefix num))
%)]
update-name #(cond fill-values? (if (str/empty? %)
(str ctv/value-prefix num)
(str % ", " ctv/value-prefix num))
property-value (if (str/empty? %)
property-value
(str % ", " property-value))
:else %)]
[(inc num)
(-> changes
(pcb/update-component (:id component)

View File

@@ -120,7 +120,45 @@
(t/is (= (count (:variant-properties comp01')) 2))
(t/is (= (count (:variant-properties comp02)) 1))
(t/is (= (count (:variant-properties comp02')) 2))
(t/is (= (-> comp01' :variant-properties last :value) "Value 1"))))
(t/is (= (-> comp01' :variant-properties last :value) "Value 1"))
(t/is (= (-> comp02' :variant-properties last :value) "Value 2"))))
(t/deftest test-add-new-property-with-the-same-value
(let [;; ==== Setup
file (-> (thf/sample-file :file1)
(thv/add-variant :v01 :c01 :m01 :c02 :m02))
v-id (-> (ths/get-shape file :v01) :id)
page (thf/current-page file)
comp01 (thc/get-component file :c01)
comp02 (thc/get-component file :c02)
;; ==== Action
changes (-> (pcb/empty-changes nil)
(pcb/with-page-id (:id page))
(pcb/with-library-data (:data file))
(pcb/with-objects (:objects page))
(clvp/generate-add-new-property v-id {:property-value "Value 1"}))
file' (thf/apply-changes file changes)
;; ==== Get
comp01' (thc/get-component file' :c01)
comp02' (thc/get-component file' :c02)]
;; ==== Check
(t/is (= (count (:variant-properties comp01)) 1))
(t/is (= (count (:variant-properties comp01')) 2))
(t/is (= (count (:variant-properties comp02)) 1))
(t/is (= (count (:variant-properties comp02')) 2))
(t/is (= (-> comp01' :variant-properties last :value) "Value 1"))
(t/is (= (-> comp02' :variant-properties last :value) "Value 1"))))

View File

@@ -983,7 +983,7 @@
menu-open? (deref menu-open*)
menu-entries [{:title (tr "workspace.shape.menu.add-variant-property")
:action #(st/emit! (dwv/add-new-property variant-id))}
:action #(st/emit! (dwv/add-new-property variant-id {:property-value "Value 1"}))}
{:title (tr "workspace.shape.menu.add-variant")
:action #(st/emit! (dwv/add-new-variant (:id shape)))}]