From 0d1af260a4bbadabf919b9b5fac764beb56d7b3e Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Thu, 7 Mar 2024 13:34:22 +0100 Subject: [PATCH] :bug: Remove incorrect find-component function --- common/src/app/common/types/file.cljc | 6 ------ .../test/common_tests/helpers/components.cljc | 18 ++++-------------- .../test/frontend_tests/helpers/libraries.cljs | 8 ++++---- .../frontend_tests/state_components_test.cljs | 7 ++++--- 4 files changed, 12 insertions(+), 27 deletions(-) diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index 58b579f2e..42a0a7789 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -117,12 +117,6 @@ (ctkl/update-component file-data (:id container) f))) ;; Asset helpers - -(defn find-component - "Retrieve a component from libraries, iterating over all of them." - [libraries component-id & {:keys [include-deleted?] :or {include-deleted? false}}] - (some #(ctkl/get-component (:data %) component-id include-deleted?) (vals libraries))) - (defn find-component-file [file libraries component-file] (if (and (some? file) (= component-file (:id file))) diff --git a/common/test/common_tests/helpers/components.cljc b/common/test/common_tests/helpers/components.cljc index f842d2dc2..523438c44 100644 --- a/common/test/common_tests/helpers/components.cljc +++ b/common/test/common_tests/helpers/components.cljc @@ -82,7 +82,7 @@ [page root-inst-id libraries] (let [root-inst (ctn/get-shape page root-inst-id) - component (ctf/find-component libraries (:component-id root-inst)) + component (ctf/get-component libraries (:component-file root-inst) (:component-id root-inst)) shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id) shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst)) @@ -94,7 +94,7 @@ (ctn/get-component-shape (:objects page) shape) component - (ctf/find-component libraries (:component-id component-shape)) + (ctf/get-component libraries (:component-file component-shape) (:component-id component-shape)) main-shape (ctn/get-shape component (:shape-ref shape))] @@ -118,7 +118,7 @@ [page root-inst-id libraries] (let [root-inst (ctn/get-shape page root-inst-id) - component (ctf/find-component libraries (:component-id root-inst)) + component (ctf/get-component libraries (:component-file root-inst) (:component-id root-inst)) shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id) shapes-main (cfh/get-children-with-self (:objects component) (:shape-ref root-inst)) @@ -130,7 +130,7 @@ (ctn/get-component-shape (:objects page) shape) component - (ctf/find-component libraries (:component-id component-shape)) + (ctf/get-component libraries (:component-file component-shape) (:component-id component-shape)) main-shape (ctn/get-shape component (:shape-ref shape))] @@ -142,15 +142,5 @@ [shapes-inst shapes-main component])) -(defn resolve-component - "Get the component with the given id and all its shapes." - [page component-id libraries] - (let [component (ctf/find-component libraries component-id) - root-main (ctk/get-component-root component) - shapes-main (cfh/get-children-with-self (:objects component) (:id root-main))] - ;; Validate that the component tree is well constructed - (run! check-noninstance shapes-main) - - [shapes-main component])) diff --git a/frontend/test/frontend_tests/helpers/libraries.cljs b/frontend/test/frontend_tests/helpers/libraries.cljs index 8519ec81c..1d9137f56 100644 --- a/frontend/test/frontend_tests/helpers/libraries.cljs +++ b/frontend/test/frontend_tests/helpers/libraries.cljs @@ -112,7 +112,7 @@ main-instance? (:main-instance root-inst) libs (wsh/get-libraries state) - component (ctf/find-component libs (:component-id root-inst)) + component (ctf/get-component libs (:component-file root-inst) (:component-id root-inst)) library (ctf/get-component-library libs root-inst) shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id) @@ -152,7 +152,7 @@ root-inst (ctn/get-shape page root-inst-id) libs (wsh/get-libraries state) - component (ctf/find-component libs (:component-id root-inst)) + component (ctf/get-component libs (:component-file root-inst) (:component-id root-inst)) library (ctf/get-component-library libs root-inst) shapes-inst (cfh/get-children-with-self (:objects page) root-inst-id) @@ -165,9 +165,9 @@ (defn resolve-component "Get the component with the given id and all its shapes." - [state component-id] + [state component-file component-id] (let [libs (wsh/get-libraries state) - component (ctf/find-component libs component-id) + component (ctf/get-component libs component-file component-id) library (ctf/get-component-library libs component) shapes-main (ctf/get-component-shapes (:data library) component)] diff --git a/frontend/test/frontend_tests/state_components_test.cljs b/frontend/test/frontend_tests/state_components_test.cljs index 7cb62b212..3a8751019 100644 --- a/frontend/test/frontend_tests/state_components_test.cljs +++ b/frontend/test/frontend_tests/state_components_test.cljs @@ -186,9 +186,9 @@ ;; Expected shape tree: ;; ;; [Page: Page] - ;; Root Frame + ;; Root Frame ;; Rect 1 # - ;; Rect 1 + ;; Rect 1 ;; Rect 1 # ;; Rect 1* @--> Rect 1 ;; Rect 1 ---> Rect 1 @@ -362,6 +362,7 @@ component2] (thl/resolve-component new-state + (:current-file-id new-state) new-component-id)] (t/is (= (:name component2) "Rect 1")))))] @@ -657,7 +658,7 @@ ;; ;; [Board] ;; page1 / Board - ;; + ;; (let [instance1 (thp/get-shape new-state :instance1) [[group shape1 shape2]