Repository: penpot/penpot
File: frontend/src/app/main/ui/dashboard/sidebar.cljs (ClojureScript)

Code before:
       (get-in team [:permissions :is-owner])
       [:> dropdown-menu-item* {:on-click    on-leave-as-owner-clicked
                                :class       (stl/css :team-options-item)
                                :data-testid  "leave-team"}
        (tr "dashboard.leave-team")]

       (> (count members) 1)
       [:> dropdown-menu-item* {:on-click on-leave-clicked
                                :class    (stl/css :team-options-item)}
        (tr "dashboard.leave-team")])

     (when (get-in team [:permissions :is-owner])
       [:> dropdown-menu-item* {:on-click    on-delete-clicked
                                :class       (stl/css :team-options-item :warning)
                                :data-testid "delete-team"}
        (tr "dashboard.delete-team")])]))


(mf/defc sidebar-org-switch*
  [{:keys [team profile]}]
  (let [orgs (->> (mf/deref refs/teams)
                  vals
                  (group-by :organization-id)
                  (map (fn [[_group entries]] (first entries)))
                  vec
                  (d/index-by :id))

        orgs (update-vals orgs
                          (fn [t]
                            (assoc t :name (str "ORG: " (:organization-name t)))))

        empty? (= (count orgs) 1)


        current-org (assoc team :name (str "ORG: " (:organization-name team)))

        show-teams-menu*
        (mf/use-state false)

        show-teams-menu?
        (deref show-teams-menu*)

        on-show-teams-click
        (mf/use-fn
         (fn [event]
           (dom/stop-propagation event)
           (swap! show-teams-menu* not)))

        on-show-teams-keydown
        (mf/use-fn
         (fn [event]

Review comment (suggestion):
This should be defined in two steps:
1. The deref of teams
2. the orgs as `mf/with-memo [teams]` (this should include the update-vals of the line 511

Code after:
       (get-in team [:permissions :is-owner])
       [:> dropdown-menu-item* {:on-click    on-leave-as-owner-clicked
                                :class       (stl/css :team-options-item)
                                :data-testid  "leave-team"}
        (tr "dashboard.leave-team")]

       (> (count members) 1)
       [:> dropdown-menu-item* {:on-click on-leave-clicked
                                :class    (stl/css :team-options-item)}
        (tr "dashboard.leave-team")])

     (when (get-in team [:permissions :is-owner])
       [:> dropdown-menu-item* {:on-click    on-delete-clicked
                                :class       (stl/css :team-options-item :warning)
                                :data-testid "delete-team"}
        (tr "dashboard.delete-team")])]))


(mf/defc sidebar-org-switch*
  [{:keys [team profile]}]
  (let [teams (mf/deref refs/teams)
        orgs  (mf/with-memo [teams]
                (let [orgs (->> teams
                                vals
                                (group-by :organization-id)
                                (map (fn [[_group entries]] (first entries)))
                                vec
                                (d/index-by :id))]
                  (update-vals orgs
                               (fn [t]
                                 (assoc t :name (str "ORG: " (:organization-name t)))))))

        empty? (= (count orgs) 1)


        current-org (mf/with-memo [team]
                      (assoc team :name (str "ORG: " (:organization-name team))))

        show-teams-menu*
        (mf/use-state false)

        show-teams-menu?
        (deref show-teams-menu*)

        on-show-teams-click
        (mf/use-fn
         (fn [event]
           (dom/stop-propagation event)
           (swap! show-teams-menu* not)))

        on-show-teams-keydown