diff --git a/common/src/app/common/files/repair.cljc b/common/src/app/common/files/repair.cljc index 4cc8454fe..f682a4a0f 100644 --- a/common/src/app/common/files/repair.cljc +++ b/common/src/app/common/files/repair.cljc @@ -126,9 +126,12 @@ repair-shape (fn [shape] - ; Detach the shape and convert it to non instance. - (log/debug :hint " -> Detach shape" :shape-id (:id shape)) - (ctk/detach-shape shape))] + ;; ; Detach the shape and convert it to non instance. + ;; (log/debug :hint " -> Detach shape" :shape-id (:id shape)) + ;; (ctk/detach-shape shape))] + ; There is no solution that may recover it with confidence + (log/warn :hint " -> CANNOT REPAIR THIS AUTOMATICALLY.") + shape)] (log/info :hint "Repairing shape :component-not-found" :id (:id shape) :name (:name shape) :page-id page-id) (-> (pcb/empty-changes nil page-id) @@ -315,9 +318,12 @@ [_ {:keys [shape page-id] :as error} file-data _] (let [repair-shape (fn [shape] - ; Detach the shape and convert it to non instance. - (log/debug :hint " -> Detach shape" :shape-id (:id shape)) - (ctk/detach-shape shape))] + ;; ; Detach the shape and convert it to non instance. + ;; (log/debug :hint " -> Detach shape" :shape-id (:id shape)) + ;; (ctk/detach-shape shape))] + ; There is no solution that may recover it with confidence + (log/warn :hint " -> CANNOT REPAIR THIS AUTOMATICALLY.") + shape)] (log/info :hint "Repairing shape :not-head-main-not-allowed" :id (:id shape) :name (:name shape) :page-id page-id) (-> (pcb/empty-changes nil page-id) diff --git a/common/src/app/common/files/validate.cljc b/common/src/app/common/files/validate.cljc index 9991fae50..b0156f942 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -140,7 +140,7 @@ shape file page) (do (when-not (= (:main-instance-id component) (:id shape)) - (report-error :nvalid-main-instance-id + (report-error :invalid-main-instance-id (str/format "Main instance id of component %s is not valid" (:component-id shape)) shape file page)) (when-not (= (:main-instance-page component) (:id page)) @@ -317,57 +317,60 @@ (validate-parent-children shape file page) (validate-frame shape file page) - (if (ctk/main-instance? shape) + (validate-parent-children shape file page) + (validate-frame shape file page) - (if (ctk/instance-root? shape) + (if (ctk/instance-head? shape) + + (if (ctk/instance-root? shape) + + (if (ctk/main-instance? shape) (if (not= context :not-component) (report-error :root-main-not-allowed (str/format "Root main component not allowed inside other component") shape file page) (validate-shape-main-root-top shape file page libraries)) + (if (not= context :not-component) + (report-error :root-main-not-allowed + (str/format "Root main component not allowed inside other component") + shape file page) + (validate-shape-copy-root-top shape file page libraries))) + + (if (ctk/main-instance? shape) (if (= context :not-component) (report-error :nested-main-not-allowed (str/format "Nested main component only allowed inside other component") shape file page) - (validate-shape-main-root-nested shape file page libraries))) + (validate-shape-main-root-nested shape file page libraries)) - (if (ctk/instance-head? shape) + (if (= context :not-component) + (report-error :nested-main-not-allowed + (str/format "Nested main component only allowed inside other component") + shape file page) + (validate-shape-copy-root-nested shape file page libraries)))) - (if (ctk/instance-root? shape) - (if (not= context :not-component) - (report-error :root-copy-not-allowed - (str/format "Root copy not allowed inside other component") - shape file page) - (validate-shape-copy-root-top shape file page libraries)) + (if (ctk/in-component-copy? shape) + (if-not (#{:copy-top :copy-nested :copy-any} context) + (report-error :not-head-copy-not-allowed + (str/format "Non-root copy only allowed inside a copy") + shape file page) + (validate-shape-copy-not-root shape file page libraries)) - (if (= context :not-component) - (report-error :nested-copy-not-allowed - (str/format "Nested copy only allowed inside other component") - shape file page) - (validate-shape-copy-root-nested shape file page libraries))) + (if (ctn/inside-component-main? (:objects page) shape) + (if-not (#{:main-top :main-nested :main-any} context) + (report-error :not-head-main-not-allowed + (str/format "Non-root main only allowed inside a main component") + shape file page) + (validate-shape-main-not-root shape file page libraries)) - (if (ctn/component-main? (:objects page) shape) - (if-not (#{:main-top :main-nested :main-any} context) - (report-error :not-head-main-not-allowed - (str/format "Non-root main only allowed inside a main component") - shape file page) - (validate-shape-main-not-root shape file page libraries)) + (if (#{:main-top :main-nested :main-any} context) + (report-error :not-component-not-allowed + (str/format "Not compoments are not allowed inside a main") + shape file page) + (validate-shape-not-component shape file page libraries))))) - (if (ctk/in-component-copy? shape) - (if-not (#{:copy-top :copy-nested :copy-any} context) - (report-error :not-head-copy-not-allowed - (str/format "Non-root copy only allowed inside a copy") - shape file page) - (validate-shape-copy-not-root shape file page libraries)) - - (if (#{:main-top :main-nested :main-any} context) - (report-error :not-component-not-allowed - (str/format "Not compoments are not allowed inside a main") - shape file page) - (validate-shape-not-component shape file page libraries)))))) - - (deref *errors*)))) + (deref *errors*)))) (defn validate-file "Validate referencial integrity and semantic coherence of all contents of a file." diff --git a/common/src/app/common/types/container.cljc b/common/src/app/common/types/container.cljc index edd216db0..fdd7b100d 100644 --- a/common/src/app/common/types/container.cljc +++ b/common/src/app/common/types/container.cljc @@ -156,7 +156,7 @@ (let [parent (cph/get-parent objects (:id shape))] (or (get-copy-root objects parent) shape)))) -(defn component-main? +(defn inside-component-main? "Check if the shape is a component main instance or is inside one." [objects shape] (cond @@ -167,7 +167,7 @@ (ctk/instance-head? shape) false :else - (component-main? objects (get objects (:parent-id shape))))) + (inside-component-main? objects (get objects (:parent-id shape))))) (defn in-any-component? "Check if the shape is part of any component (main or copy), wether it's @@ -175,7 +175,7 @@ [objects shape] (or (ctk/in-component-copy? shape) (ctk/instance-head? shape) - (component-main? objects shape))) + (inside-component-main? objects shape))) (defn make-component-shape "Clone the shape and all children. Generate new ids and detach