Repository: penpot/penpot
File: frontend/src/app/main/data/workspace/libraries.cljs (ClojureScript)

Code before:
        (rx/of (rt/nav :workspace params ::rt/new-window true))))))

(defn go-to-local-component
  ;; id is the id of the component to go
  ;; additional-ids are ids of additional components on the same page
  ;; that will be selected and zoomed along the main one
  ;; update-layout? indicates if it should send a :layout/update event
  ;; for the parents of the component
  [& {:keys [id additional-ids update-layout? retries] :or {retries 0} :as options}]
  (ptk/reify ::go-to-local-component
    ptk/WatchEvent
    (watch [_ state stream]
      (let [current-page-id (:current-page-id state)
            data            (dsh/lookup-file-data state)
            objects         (dsh/lookup-page-objects state current-page-id)

            select-and-zoom
            (fn [ids]
              (let [parent-ids (when update-layout?
                                 (keep #(-> (get objects %) :parent-id) ids))]

                (if (and update-layout? (empty? parent-ids) (< retries 3))
                  ;; The objects are not loaded yet, wait and try again
                  (->> (rx/of (go-to-local-component (assoc options :retries (inc retries))))
                       (rx/delay 250))
                  (rx/concat
                   (rx/of
                    (dws/select-shapes ids)
                    dwz/zoom-to-selected-shape
                    (when update-layout?
                      (ptk/data-event :layout/update {:ids parent-ids})))))))

            redirect-to-page
            (fn [page-id ids]
              (rx/merge
               (->> stream
                    (rx/filter (ptk/type? ::dwpg/initialize-page))
                    (rx/take 1)
                    (rx/observe-on :async)
                    (rx/mapcat (fn [_] (select-and-zoom ids))))
               (rx/of (dcm/go-to-workspace :page-id page-id))))

            get-main-instance-id
            (fn [id page-id]
              (let [component (dm/get-in data [:components id])]
                (when (= (:main-instance-page component) page-id)
                  (:main-instance-id component))))]

        (when-let [component (dm/get-in data [:components id])]
          (let [page-id  (:main-instance-page component)
                shape-id (:main-instance-id component)

Review comment (refactor):
I think we can remove this concat. Or more correctly, put the last `when`  on its own rx/of. 

Removing concat will work, but it will emit a `nil` into the stream, that in our case is prefectly OK and will do nothing. But the correct way to implement this is:

```clojure
(rx/concat
 (rx/of (dws/select-shapes ids)
        dwz/zoom-to-selected-shape)
 (when update-layout?
   (rx/of (ptk/data-event :layout/update {:ids parent-ids}))))
```

Code after:
        (rx/of (rt/nav :workspace params ::rt/new-window true))))))

(defn go-to-local-component
  ;; id is the id of the component to go
  ;; additional-ids are ids of additional components on the same page
  ;; that will be selected and zoomed along the main one
  ;; update-layout? indicates if it should send a :layout/update event
  ;; for the parents of the component
  [& {:keys [id additional-ids update-layout? retries] :or {retries 0} :as options}]
  (ptk/reify ::go-to-local-component
    ptk/WatchEvent
    (watch [_ state stream]
      (let [current-page-id (:current-page-id state)
            data            (dsh/lookup-file-data state)
            objects         (dsh/lookup-page-objects state current-page-id)

            select-and-zoom
            (fn [ids]
              (let [parent-ids (when update-layout?
                                 (keep #(-> (get objects %) :parent-id) ids))]

                (if (and update-layout? (empty? parent-ids) (< retries 8))
                  ;; The objects are not loaded yet, wait and try again
                  (->> (rx/of (go-to-local-component (assoc options :retries (inc retries))))
                       (rx/delay 250))
                  (rx/concat
                   (rx/of (dws/select-shapes ids)
                          dwz/zoom-to-selected-shape)
                   (when update-layout?
                     (rx/of (ptk/data-event :layout/update {:ids parent-ids})))))))

            redirect-to-page
            (fn [page-id ids]
              (rx/merge
               (->> stream
                    (rx/filter (ptk/type? ::dwpg/initialize-page))
                    (rx/take 1)
                    (rx/observe-on :async)
                    (rx/mapcat (fn [_] (select-and-zoom ids))))
               (rx/of (dcm/go-to-workspace :page-id page-id))))

            get-main-instance-id
            (fn [id page-id]
              (let [component (dm/get-in data [:components id])]
                (when (= (:main-instance-page component) page-id)
                  (:main-instance-id component))))]

        (when-let [component (dm/get-in data [:components id])]
          (let [page-id  (:main-instance-page component)
                shape-id (:main-instance-id component)
                additional-shape-ids (keep #(get-main-instance-id % page-id)