Repository: penpot/penpot
File: frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs (ClojureScript)

Code before:
                        :label (if (str/blank? val) (str "(" (tr "labels.empty") ")") val)}))))


(mf/defc component-variant-main-instance*
  [{:keys [components shapes data]}]
  (let [component      (first components)

        variant-id     (:variant-id component)

        objects        (-> (dsh/get-page data (:main-instance-page component))
                           (get :objects))

        properties-map (mapv :variant-properties components)
        component-ids  (mapv :id components)
        properties     (if (> (count component-ids) 1)
                         (ctv/compare-properties properties-map false)
                         (first properties-map))

        malformed-map   (mapv :variant-error shapes)
        malformed-msg   (get-variant-malformed-warning-message malformed-map)

        duplicated-ids  (->> (cfv/find-variant-components data objects variant-id)
                             get-main-ids-with-duplicated-variant-props-and-values
                             set)
        duplicated-map  (->> components
                             (mapv :main-instance-id)
                             (mapv duplicated-ids))
        duplicated-msg  (get-variant-duplicated-warning-message duplicated-map)

        prop-vals       (mf/with-memo [data objects variant-id]
                          (cfv/extract-properties-values data objects variant-id))

        get-options
        (mf/use-fn
         (mf/deps prop-vals)
         (fn [prop-name]
           (get-variant-options prop-name prop-vals)))

        update-property-value
        (mf/use-fn
         (mf/deps component-ids)
         (fn [pos value]
           (let [value (d/nilv (str/trim value) "")]
             (doseq [id component-ids]
               (st/emit! (dwv/update-property-value id pos value))
               (st/emit! (dwv/update-error id))))))

        update-property-name
        (mf/use-fn
         (mf/deps variant-id)
         (fn [event]

Review comment (refactor):
Not related to changes on this PR, but this mapv + mapv looks strange, I suggest using map + map + vec.
Additionally, the code is not clearly evident for me, the name `duplicated-map` indicates it like a map, but in reality is a vector...
In summary I recommend revisit this code and make it a bit more evident

Code after:
                        :label (if (str/blank? val) (str "(" (tr "labels.empty") ")") val)}))))


(mf/defc component-variant-main-instance*
  [{:keys [components shapes data]}]
  (let [component      (first components)

        variant-id     (:variant-id component)

        objects        (-> (dsh/get-page data (:main-instance-page component))
                           (get :objects))

        props-list     (map :variant-properties components)
        component-ids  (map :id components)
        properties     (if (> (count component-ids) 1)
                         (ctv/compare-properties props-list false)
                         (first props-list))

        malformed-list  (map :variant-error shapes)
        malformed-msg   (get-variant-malformed-warning-message malformed-list)

        duplicated-ids  (->> (cfv/find-variant-components data objects variant-id)
                             get-main-ids-with-duplicated-variant-props-and-values
                             set)
        duplicated-list (->> components
                             (map :main-instance-id)
                             (map duplicated-ids))
        duplicated-msg  (get-variant-duplicated-warning-message duplicated-list)

        prop-vals       (mf/with-memo [data objects variant-id]
                          (cfv/extract-properties-values data objects variant-id))

        get-options
        (mf/use-fn
         (mf/deps prop-vals)
         (fn [prop-name]
           (get-variant-options prop-name prop-vals)))

        update-property-value
        (mf/use-fn
         (mf/deps component-ids)
         (fn [pos value]
           (let [value (d/nilv (str/trim value) "")]
             (doseq [id component-ids]
               (st/emit! (dwv/update-property-value id pos value))
               (st/emit! (dwv/update-error id))))))

        update-property-name
        (mf/use-fn
         (mf/deps variant-id)
         (fn [event]