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

Code before:
       first
       :value
       (map (fn [val] {:id val
                       :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-message malformed-map)

        duplicated-ids  (->> (cfv/find-variant-components data objects variant-id)
                             get-component-ids-with-duplicated-variant-props-and-values)
        duplicated-map  (->> components
                             (mapv :main-instance-id)
                             (mapv (set duplicated-ids)))
        duplicated-msg  (get-variant-duplicated-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 nil))))))

        update-property-name
        (mf/use-fn

Review comment (performance):
Small performance improvement: 
Add here the `set` to avoid transform it in set for each component on line 318

Code after:
  [prop-name prop-vals]
  (->> (filter #(= (:name %) prop-name) prop-vals)
       first
       :value
       (map (fn [val] {:id val
                       :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-component-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 nil))))))