0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 17:00:36 -05:00

🐛 Fix go to main component in another file should open it on a new tab

This commit is contained in:
Pablo Alba 2023-11-17 16:06:33 +01:00 committed by Andrey Antukh
parent 29677d8085
commit 752b26e063
3 changed files with 50 additions and 38 deletions

View file

@ -283,29 +283,39 @@
(rx/take-until
(rx/filter (ptk/type? ::fetch-bundle) stream)))))))
(declare go-to-component)
(defn- fetch-bundle
"Multi-stage file bundle fetch coordinator"
[project-id file-id]
(ptk/reify ::fetch-bundle
ptk/WatchEvent
(watch [_ _ stream]
(->> (rx/merge
(rx/of (fetch-bundle-stage-1 project-id file-id))
(watch [_ state stream]
(let [component-id (get-in state [:route :query-params :component-id])]
(->> (rx/merge
(rx/of (fetch-bundle-stage-1 project-id file-id))
(->> stream
(rx/filter (ptk/type? ::bundle-stage-1))
(rx/observe-on :async)
(rx/map deref)
(rx/map fetch-bundle-stage-2))
(->> stream
(rx/filter (ptk/type? ::bundle-stage-1))
(rx/observe-on :async)
(rx/map deref)
(rx/map fetch-bundle-stage-2))
(->> stream
(rx/filter (ptk/type? ::bundle-stage-2))
(rx/observe-on :async)
(rx/map deref)
(rx/map bundle-fetched)))
(->> stream
(rx/filter (ptk/type? ::bundle-stage-2))
(rx/observe-on :async)
(rx/map deref)
(rx/map bundle-fetched))
(rx/take-until
(rx/filter (ptk/type? ::fetch-bundle) stream))))))
(when component-id
(->> stream
(rx/filter (ptk/type? ::workspace-initialized))
(rx/observe-on :async)
(rx/take 1)
(rx/map #(go-to-component (uuid/uuid component-id))))))
(rx/take-until
(rx/filter (ptk/type? ::fetch-bundle) stream)))))))
(defn initialize-file
[project-id file-id]

View file

@ -589,16 +589,17 @@
(rx/of (dch/commit-changes changes))))))
(defn nav-to-component-file
[file-id]
[file-id component]
(dm/assert! (uuid? file-id))
(dm/assert! (some? component))
(ptk/reify ::nav-to-component-file
ptk/WatchEvent
(watch [_ state _]
(let [file (get-in state [:workspace-libraries file-id])
path-params {:project-id (:project-id file)
:file-id (:id file)}
query-params {:page-id (first (get-in file [:data :pages]))
:layout :assets}]
(let [project-id (get-in state [:workspace-libraries file-id :project-id])
path-params {:project-id project-id
:file-id file-id}
query-params {:page-id (:main-instance-page component)
:component-id (:id component)}]
(rx/of (rt/nav-new-window* {:rname :workspace
:path-params path-params
:query-params query-params}))))))

View file

@ -353,17 +353,6 @@
do-reset-component
#(st/emit! (dwl/reset-components (map :id touched-not-dangling)))
do-restore-component
#(let [;; Extract a map of component-id -> component-file in order to avoid duplicates
comps-to-restore (reduce (fn [id-file-map {:keys [component-id component-file]}]
(assoc id-file-map component-id component-file))
{}
restorable-copies)]
(st/emit! (dwl/restore-components comps-to-restore)
(when (= 1 (count comps-to-restore))
(dw/go-to-main-instance (val (first comps-to-restore)) (key (first comps-to-restore))))))
do-update-component-sync
#(st/emit! (dwl/update-component-sync id library-id))
@ -384,23 +373,35 @@
(do-update-component-sync)
(do-update-remote-component))
do-show-local-component
#(st/emit! (dw/go-to-component component-id))
do-show-in-assets
#(st/emit! (if components-v2
(dw/show-component-in-assets component-id)
(dw/go-to-component component-id)))
do-create-annotation
#(st/emit! (dw/set-annotations-id-for-create id))
do-navigate-component-file
#(st/emit! (dw/go-to-main-instance library-id component-id))
do-show-local-component
#(st/emit! (dw/go-to-component component-id))
do-show-remote-component
#(st/emit! (dwl/nav-to-component-file library-id component))
do-show-component
#(if local-component?
(do-show-local-component)
(do-navigate-component-file))
(do-show-remote-component))
do-restore-component
#(let [;; Extract a map of component-id -> component-file in order to avoid duplicates
comps-to-restore (reduce (fn [id-file-map {:keys [component-id component-file]}]
(assoc id-file-map component-id component-file))
{}
restorable-copies)]
(st/emit! (dwl/restore-components comps-to-restore))
(when (= 1 (count comps-to-restore))
do-show-component))
menu-entries [(when (and (not multi) main-instance?)
{:msg "workspace.shape.menu.show-in-assets"