diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 0a3d96d43..4fb86995d 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -19,6 +19,7 @@ [app.common.spec :as us] [app.common.text :as txt] [app.common.transit :as t] + [app.common.types.components-list :as ctkl] [app.common.types.container :as ctn] [app.common.types.file :as ctf] [app.common.types.pages-list :as ctpl] @@ -987,28 +988,6 @@ :graphics #{} :colors #{} :typographies #{}})))) -(defn go-to-component - [component-id] - (ptk/reify ::go-to-component - IDeref - (-deref [_] {:layout :assets}) - - ptk/WatchEvent - (watch [_ state _] - (let [project-id (get-in state [:workspace-project :id]) - file-id (get-in state [:workspace-file :id]) - page-id (get state :current-page-id) - pparams {:file-id file-id :project-id project-id} - qparams {:page-id page-id :layout :assets}] - (rx/of (rt/nav :workspace pparams qparams) - (dwl/set-assets-box-open file-id :library true) - (dwl/set-assets-box-open file-id :components true) - (select-single-asset component-id :components)))) - ptk/EffectEvent - (effect [_ _ _] - (let [wrapper-id (str "component-shape-id-" component-id)] - (tm/schedule-on-idle #(dom/scroll-into-view-if-needed! (dom/get-element wrapper-id))))))) - (defn go-to-main-instance [page-id shape-id on-page-selected] (us/verify ::us/uuid page-id) @@ -1024,7 +1003,8 @@ (let [project-id (:current-project-id state) file-id (:current-file-id state) pparams {:file-id file-id :project-id project-id} - qparams {:page-id page-id :layout :assets}] + qparams {:page-id page-id}] + ;; qparams {:page-id page-id :layout :assets}] (rx/merge (rx/of (rt/nav :workspace pparams qparams)) (->> stream @@ -1034,6 +1014,58 @@ (on-page-selected) (rx/of (dws/select-shapes (lks/set shape-id))))))))))))) +(defn go-to-component + [component-id] + (ptk/reify ::go-to-component + IDeref + (-deref [_] {:layout :assets}) + + ptk/WatchEvent + (watch [_ state _] + (let [components-v2 (features/active-feature? state :components-v2)] + (if components-v2 + (let [file-data (wsh/get-local-file state) + component (ctkl/get-component file-data component-id) + main-instance-id (:main-instance-id component) + main-instance-page (:main-instance-page component)] + (rx/of (go-to-main-instance main-instance-page main-instance-id identity))) + (let [project-id (get-in state [:workspace-project :id]) + file-id (get-in state [:workspace-file :id]) + page-id (get state :current-page-id) + pparams {:file-id file-id :project-id project-id} + qparams {:page-id page-id :layout :assets}] + (rx/of (rt/nav :workspace pparams qparams) + (dwl/set-assets-box-open file-id :library true) + (dwl/set-assets-box-open file-id :components true) + (select-single-asset component-id :components)))))) + + ptk/EffectEvent + (effect [_ state _] + (let [components-v2 (features/active-feature? state :components-v2) + wrapper-id (str "component-shape-id-" component-id)] + (when-not components-v2 + (tm/schedule-on-idle #(dom/scroll-into-view-if-needed! (dom/get-element wrapper-id)))))))) + +(defn show-component-in-assets + [component-id] + (ptk/reify ::show-component-in-assets + ptk/WatchEvent + (watch [_ state _] + (let [project-id (get-in state [:workspace-project :id]) + file-id (get-in state [:workspace-file :id]) + page-id (get state :current-page-id) + pparams {:file-id file-id :project-id project-id} + qparams {:page-id page-id :layout :assets}] + (rx/of (rt/nav :workspace pparams qparams) + (dwl/set-assets-box-open file-id :library true) + (dwl/set-assets-box-open file-id :components true) + (select-single-asset component-id :components)))) + + ptk/EffectEvent + (effect [_ _ _] + (let [wrapper-id (str "component-shape-id-" component-id)] + (tm/schedule-on-idle #(dom/scroll-into-view-if-needed! (dom/get-element wrapper-id))))))) + (def go-to-file (ptk/reify ::go-to-file ptk/WatchEvent diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index 81bf006b5..d6f6136b9 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -424,6 +424,9 @@ do-detach-component-in-bulk #(st/emit! dwl/detach-selected-components) do-reset-component #(st/emit! (dwl/reset-component shape-id)) do-show-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-navigate-component-file #(st/emit! (dwl/nav-to-component-file component-file)) do-update-component #(st/emit! (dwl/update-component-sync shape-id component-file)) do-update-component-in-bulk #(st/emit! (dwl/update-component-in-bulk component-shapes component-file)) @@ -474,7 +477,7 @@ [:& menu-separator] (if main-component? [:& menu-entry {:title (tr "workspace.shape.menu.show-in-assets") - :on-click do-show-component}] + :on-click do-show-in-assets}] (if local-component? (if is-dangling? [:* diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs index 91d2ab9c7..db16601de 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/component.cljs @@ -78,6 +78,9 @@ :on-accept do-update-component})) do-show-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-navigate-component-file #(st/emit! (dwl/nav-to-component-file library-id))] (when show? [:div.element-set @@ -99,7 +102,7 @@ :show (:menu-open @local) :options (if main-instance? - [[(tr "workspace.shape.menu.show-in-assets") do-show-component]] + [[(tr "workspace.shape.menu.show-in-assets") do-show-in-assets]] (if local-component? (if is-dangling? [[(tr "workspace.shape.menu.detach-instance") do-detach-component]