🐛 Fix restore main component on a copy of a component from a library

This commit is contained in:
Pablo Alba 2023-11-17 23:34:44 +01:00 committed by Andrey Antukh
parent 752b26e063
commit cfdf7766e3
2 changed files with 30 additions and 27 deletions

View file

@ -291,7 +291,6 @@
(ptk/reify ::fetch-bundle (ptk/reify ::fetch-bundle
ptk/WatchEvent ptk/WatchEvent
(watch [_ state stream] (watch [_ state stream]
(let [component-id (get-in state [:route :query-params :component-id])]
(->> (rx/merge (->> (rx/merge
(rx/of (fetch-bundle-stage-1 project-id file-id)) (rx/of (fetch-bundle-stage-1 project-id file-id))
@ -307,7 +306,7 @@
(rx/map deref) (rx/map deref)
(rx/map bundle-fetched)) (rx/map bundle-fetched))
(when component-id (when-let [component-id (get-in state [:route :query-params :component-id])]
(->> stream (->> stream
(rx/filter (ptk/type? ::workspace-initialized)) (rx/filter (ptk/type? ::workspace-initialized))
(rx/observe-on :async) (rx/observe-on :async)
@ -315,7 +314,7 @@
(rx/map #(go-to-component (uuid/uuid component-id)))))) (rx/map #(go-to-component (uuid/uuid component-id))))))
(rx/take-until (rx/take-until
(rx/filter (ptk/type? ::fetch-bundle) stream))))))) (rx/filter (ptk/type? ::fetch-bundle) stream))))))
(defn initialize-file (defn initialize-file
[project-id file-id] [project-id file-id]

View file

@ -307,7 +307,9 @@
workspace-libraries (deref refs/workspace-libraries) workspace-libraries (deref refs/workspace-libraries)
current-file {:id current-file-id :data workspace-data} current-file {:id current-file-id :data workspace-data}
find-component #(ctf/resolve-component % current-file workspace-libraries) find-component (fn [shape include-deleted?]
(ctf/resolve-component
shape current-file workspace-libraries {:include-deleted? include-deleted?}))
local-or-exists (fn [shape] local-or-exists (fn [shape]
(let [library-id (:component-file shape)] (let [library-id (:component-file shape)]
@ -315,11 +317,11 @@
(some? (get workspace-libraries library-id))))) (some? (get workspace-libraries library-id)))))
restorable-copies (->> copies restorable-copies (->> copies
(filter #(nil? (find-component %))) (filter #(nil? (find-component % false)))
(filter #(local-or-exists %))) (filter #(local-or-exists %)))
touched-not-dangling (filter #(and (cfh/component-touched? objects (:id %)) touched-not-dangling (filter #(and (cfh/component-touched? objects (:id %))
(find-component %)) copies) (find-component % false)) copies)
can-reset-overrides? (or (not components-v2) (seq touched-not-dangling)) can-reset-overrides? (or (not components-v2) (seq touched-not-dangling))
@ -332,7 +334,7 @@
library-id (:component-file shape) library-id (:component-file shape)
local-component? (= library-id current-file-id) local-component? (= library-id current-file-id)
component (find-component shape) component (find-component shape false)
lacks-annotation? (nil? (:annotation component)) lacks-annotation? (nil? (:annotation component))
is-dangling? (nil? component) is-dangling? (nil? component)
@ -385,7 +387,9 @@
#(st/emit! (dw/go-to-component component-id)) #(st/emit! (dw/go-to-component component-id))
do-show-remote-component do-show-remote-component
#(st/emit! (dwl/nav-to-component-file library-id component)) #(let [comp (find-component shape true)] ;; When the show-remote is after a restore, the component may still be deleted
(when comp
(st/emit! (dwl/nav-to-component-file library-id comp))))
do-show-component do-show-component
#(if local-component? #(if local-component?
@ -401,7 +405,7 @@
(st/emit! (dwl/restore-components comps-to-restore)) (st/emit! (dwl/restore-components comps-to-restore))
(when (= 1 (count comps-to-restore)) (when (= 1 (count comps-to-restore))
do-show-component)) (ts/schedule 1000 do-show-component)))
menu-entries [(when (and (not multi) main-instance?) menu-entries [(when (and (not multi) main-instance?)
{:msg "workspace.shape.menu.show-in-assets" {:msg "workspace.shape.menu.show-in-assets"