mirror of
https://github.com/penpot/penpot.git
synced 2026-09-08 21:19:49 +00:00
🐛 Handle empty variant options (#11499)
* 🐛 Handle empty variant options * 🐛 Disable variant value select when there are no options
This commit is contained in:
parent
7e1139b906
commit
f0680cf5f8
@ -290,14 +290,18 @@
|
|||||||
get-components-with-duplicated-variant-props-and-values
|
get-components-with-duplicated-variant-props-and-values
|
||||||
(map :main-instance-id)))
|
(map :main-instance-id)))
|
||||||
|
|
||||||
|
(defn- get-variant-option
|
||||||
|
[val]
|
||||||
|
{:id val
|
||||||
|
:label (if (str/blank? val) (str "(" (tr "labels.empty") ")") val)})
|
||||||
|
|
||||||
(defn- get-variant-options
|
(defn- get-variant-options
|
||||||
"Get variant options for a given property name"
|
"Get variant options for a given property name"
|
||||||
[prop-name prop-vals]
|
[prop-name prop-vals]
|
||||||
(->> (filter #(= (:name %) prop-name) prop-vals)
|
(->> (filter #(= (:name %) prop-name) prop-vals)
|
||||||
first
|
first
|
||||||
:value
|
:value
|
||||||
(mapv (fn [val] {:id val
|
(mapv get-variant-option)))
|
||||||
:label (if (str/blank? val) (str "(" (tr "labels.empty") ")") val)}))))
|
|
||||||
|
|
||||||
(mf/defc component-variant-property*
|
(mf/defc component-variant-property*
|
||||||
[{:keys [pos prop options on-prop-name-blur on-prop-value-change on-reorder]}]
|
[{:keys [pos prop options on-prop-name-blur on-prop-value-change on-reorder]}]
|
||||||
@ -527,8 +531,12 @@
|
|||||||
(for [[pos prop] (map-indexed vector props-first)]
|
(for [[pos prop] (map-indexed vector props-first)]
|
||||||
(let [mixed-value? (not-every? #(= (:value prop) (:value (get % pos))) properties)
|
(let [mixed-value? (not-every? #(= (:value prop) (:value (get % pos))) properties)
|
||||||
base-options (get options-by-name (:name prop))
|
base-options (get options-by-name (:name prop))
|
||||||
|
no-options? (empty? base-options)
|
||||||
boolean-pair (ctv/find-boolean-pair (mapv :id base-options))
|
boolean-pair (ctv/find-boolean-pair (mapv :id base-options))
|
||||||
options (cond-> base-options
|
options (cond-> base-options
|
||||||
|
no-options?
|
||||||
|
(conj (get-variant-option (:value prop)))
|
||||||
|
|
||||||
mixed-value?
|
mixed-value?
|
||||||
(conj {:id mixed-label :label mixed-label :dimmed true}))]
|
(conj {:id mixed-label :label mixed-label :dimmed true}))]
|
||||||
|
|
||||||
@ -549,6 +557,7 @@
|
|||||||
[:> select* {:default-selected (if mixed-value? mixed-label (:value prop))
|
[:> select* {:default-selected (if mixed-value? mixed-label (:value prop))
|
||||||
:options options
|
:options options
|
||||||
:empty-to-end true
|
:empty-to-end true
|
||||||
|
:disabled no-options?
|
||||||
:on-change (partial switch-component pos)
|
:on-change (partial switch-component pos)
|
||||||
:key (str (:value prop) "-" key)}]])]))]
|
:key (str (:value prop) "-" key)}]])]))]
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user