diff --git a/frontend/src/app/main/data/workspace/libraries.cljs b/frontend/src/app/main/data/workspace/libraries.cljs index 79b0ad4cf..c5d01ebe0 100644 --- a/frontend/src/app/main/data/workspace/libraries.cljs +++ b/frontend/src/app/main/data/workspace/libraries.cljs @@ -416,28 +416,29 @@ (rx/of (dch/commit-changes changes)))))))) (defn restore-component - "Restore a deleted component, with the given id, on the current file library." - [id] - (us/assert ::us/uuid id) + "Restore a deleted component, with the given id, in the given file library." + [library-id component-id] + (us/assert ::us/uuid library-id) + (us/assert ::us/uuid component-id) (ptk/reify ::restore-component ptk/WatchEvent (watch [it state _] - (let [data (get state :workspace-data) - component (ctf/get-deleted-component data id) - page (ctpl/get-page data (:main-instance-page component)) + (let [file-data (wsh/get-file state library-id) + component (ctf/get-deleted-component file-data component-id) + page (ctpl/get-page file-data (:main-instance-page component)) ; Make a new main instance, with the same id of the original [_main-instance shapes] (ctn/make-component-instance page component - (:id data) + (:id file-data) (gpt/point (:main-instance-x component) (:main-instance-y component)) {:main-instance? true :force-id (:main-instance-id component)}) changes (-> (pcb/empty-changes it) - (pcb/with-library-data data) + (pcb/with-library-data file-data) (pcb/with-page page)) changes (reduce #(pcb/add-object %1 %2 {:ignore-touched true}) @@ -446,9 +447,9 @@ ; restore-component change needs to be done after add main instance ; because when undo changes, the orden is inverse - changes (pcb/restore-component changes id)] + changes (pcb/restore-component changes component-id)] - (rx/of (dch/commit-changes changes)))))) + (rx/of (dch/commit-changes (assoc changes :file-id library-id))))))) (defn instantiate-component diff --git a/frontend/src/app/main/ui/workspace/context_menu.cljs b/frontend/src/app/main/ui/workspace/context_menu.cljs index a21ac8451..3e2f48771 100644 --- a/frontend/src/app/main/ui/workspace/context_menu.cljs +++ b/frontend/src/app/main/ui/workspace/context_menu.cljs @@ -372,10 +372,10 @@ has-component? (some true? (map #(contains? % :component-id) shapes)) is-component? (and single? (-> shapes first :component-id some?)) - shape-id (->> shapes first :id) - component-id (->> shapes first :component-id) + shape-id (-> shapes first :id) + component-id (-> shapes first :component-id) component-file (-> shapes first :component-file) - main-component? (->> shapes first :main-instance?) + main-component? (-> shapes first :main-instance?) component-shapes (filter #(contains? % :component-id) shapes) components-v2 (features/use-feature :components-v2) @@ -397,7 +397,7 @@ 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)) - do-restore-component #(st/emit! (dwl/restore-component component-id)) + do-restore-component #(st/emit! (dwl/restore-component component-file component-id)) _do-update-remote-component #(st/emit! (modal/show 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 49ccd6301..91d2ab9c7 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 @@ -64,7 +64,7 @@ #(st/emit! (dwl/update-component-sync id library-id)) do-restore-component - #(st/emit! (dwl/restore-component component-id)) + #(st/emit! (dwl/restore-component library-id component-id)) _do-update-remote-component #(st/emit! (modal/show