From b5296613de613f659f91ff167a69743c3a45161d Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Wed, 13 Dec 2023 16:49:32 +0100 Subject: [PATCH] :bug: Validate and repair also orphan shapes --- common/src/app/common/files/validate.cljc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/files/validate.cljc b/common/src/app/common/files/validate.cljc index 69651085d5..0db17aaf6e 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -186,7 +186,7 @@ (when-not (= (:main-instance-page component) (:id page)) (let [component-page (ctf/get-component-page (:data file) component) main-component (ctst/get-shape component-page (:main-instance-id component))] - ;; We must check if the same component has main instances in different pages. + ;; We must check if the same component has main instances in different pages. ;; In that case one of those instances shouldn't be main (if (:main-instance main-component) (report-error! :component-main @@ -474,7 +474,14 @@ [{:keys [data features] :as file} libraries] (when (contains? features "components/v2") (doseq [page (filter :id (ctpl/pages-seq data))] - (validate-shape! uuid/zero file page libraries)) + (let [orphans (->> page + :objects + vals + (filter #(not (contains? (:objects page) (:parent-id %)))) + (map :id))] + (validate-shape! uuid/zero file page libraries) + (doseq [shape-id orphans] + (validate-shape! shape-id file page libraries)))) (doseq [component (vals (:components data))] (validate-component! component file)))