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

Code before:
        menu-open?      (:menu-open state)

        shapes          (filter ctk/instance-head? shapes)
        multi           (> (count shapes) 1)
        copies          (filter ctk/in-component-copy? shapes)
        can-swap?       (boolean (seq copies))

        ;; For when it's only one shape
        shape           (first shapes)
        id              (:id shape)
        shape-name      (:name shape)

        component       (ctf/resolve-component shape
                                               current-file
                                               libraries
                                               {:include-deleted? true})
        data            (dm/get-in libraries [(:component-file shape) :data])
        variants?       (features/use-feature "variants/v1")
        is-variant?     (when variants? (ctk/is-variant? component))
        main-instance?  (ctk/main-instance? shape)

        components      (mapv #(ctf/resolve-component %
                                                      current-file
                                                      libraries
                                                      {:include-deleted? true}) shapes)
        same-variant?   (= 1 (count (distinct (map :variant-id components))))

        toggle-content
        (mf/use-fn #(swap! state* update :show-content not))

        on-menu-click
        (mf/use-fn
         (fn [event]
           (dom/prevent-default event)
           (dom/stop-propagation event)
           (swap! state* update :menu-open not)))

        on-menu-close
        (mf/use-fn
         #(swap! state* assoc :menu-open false))

        on-component-back
        (mf/use-fn
         #(st/emit! ::dwsp/interrupt))

        open-component-panel
        (mf/use-fn
         (mf/deps can-swap? shapes)
         (fn []
           (let [search-id "swap-component-search-filter"]
             (when can-swap? (st/emit! (dwsp/open-specialized-panel :component-swap)))

Review comment (suggestion):
The same-variant check is used twice, and may be useful in other places. I would move it to types/variant

Code after:
        menu-open?      (:menu-open state)

        shapes          (filter ctk/instance-head? shapes)
        multi           (> (count shapes) 1)
        copies          (filter ctk/in-component-copy? shapes)
        can-swap?       (boolean (seq copies))

        ;; For when it's only one shape
        shape           (first shapes)
        id              (:id shape)
        shape-name      (:name shape)

        component       (ctf/resolve-component shape
                                               current-file
                                               libraries
                                               {:include-deleted? true})
        data            (dm/get-in libraries [(:component-file shape) :data])
        variants?       (features/use-feature "variants/v1")
        is-variant?     (when variants? (ctk/is-variant? component))
        main-instance?  (ctk/main-instance? shape)

        components      (mapv #(ctf/resolve-component %
                                                      current-file
                                                      libraries
                                                      {:include-deleted? true}) shapes)
        same-variant?   (ctv/same-variant? components)

        toggle-content
        (mf/use-fn #(swap! state* update :show-content not))

        on-menu-click
        (mf/use-fn
         (fn [event]
           (dom/prevent-default event)
           (dom/stop-propagation event)
           (swap! state* update :menu-open not)))

        on-menu-close
        (mf/use-fn
         #(swap! state* assoc :menu-open false))

        on-component-back
        (mf/use-fn
         #(st/emit! ::dwsp/interrupt))

        open-component-panel
        (mf/use-fn
         (mf/deps can-swap? shapes)
         (fn []
           (let [search-id "swap-component-search-filter"]
             (when can-swap? (st/emit! (dwsp/open-specialized-panel :component-swap)))