From b700a926c227f0d93675315c735ab9c5310ada97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 31 May 2024 17:13:40 +0200 Subject: [PATCH] :bug: Add validate and repair for :misplaced-slot --- common/src/app/common/files/repair.cljc | 13 +++++++++++++ common/src/app/common/files/validate.cljc | 15 +++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/common/src/app/common/files/repair.cljc b/common/src/app/common/files/repair.cljc index 98e1642a9..cd2a656d2 100644 --- a/common/src/app/common/files/repair.cljc +++ b/common/src/app/common/files/repair.cljc @@ -460,6 +460,19 @@ (pcb/with-library-data file-data) (pcb/update-component (:id shape) repair-component)))) +(defmethod repair-error :misplaced-slot + [_ {:keys [shape page-id] :as error} file-data _] + (let [repair-shape + (fn [shape] + ;; Remove the swap slot + (log/debug :hint (str " -> remove swap-slot")) + (ctk/remove-swap-slot shape))] + + (log/dbg :hint "repairing shape :misplaced-slot" :id (:id shape) :name (:name shape) :page-id page-id) + (-> (pcb/empty-changes nil page-id) + (pcb/with-file-data file-data) + (pcb/update-shapes [(:id shape)] repair-shape)))) + (defmethod repair-error :missing-slot [_ {:keys [shape page-id args] :as error} file-data _] (let [repair-shape diff --git a/common/src/app/common/files/validate.cljc b/common/src/app/common/files/validate.cljc index 7959c5f31..7caceed49 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -52,6 +52,7 @@ :not-component-not-allowed :component-nil-objects-not-allowed :instance-head-not-frame + :misplaced-slot :missing-slot}) (def ^:private @@ -287,6 +288,14 @@ "Shape inside main instance should not have shape-ref" shape file page))) +(defn- check-empty-swap-slot + "Validate that this shape does not have any swap slot." + [shape file page] + (when (some? (ctk/get-swap-slot shape)) + (report-error :misplaced-slot + "This shape should not have swap slot" + shape file page))) + (defn- check-shape-main-root-top "Root shape of a top main instance: @@ -298,6 +307,7 @@ (check-component-main-head shape file page libraries) (check-component-root shape file page) (check-component-not-ref shape file page) + (check-empty-swap-slot shape file page) (run! #(check-shape % file page libraries :context :main-top) (:shapes shape))) (defn- check-shape-main-root-nested @@ -309,6 +319,7 @@ (check-component-main-head shape file page libraries) (check-component-not-root shape file page) (check-component-not-ref shape file page) + (check-empty-swap-slot shape file page) (run! #(check-shape % file page libraries :context :main-nested) (:shapes shape))) (defn- check-shape-copy-root-top @@ -323,6 +334,7 @@ (check-component-not-main-head shape file page libraries) (check-component-root shape file page) (check-component-ref shape file page libraries) + (check-empty-swap-slot shape file page) (run! #(check-shape % file page libraries :context :copy-top :library-exists library-exists) (:shapes shape)))) (defn- check-shape-copy-root-nested @@ -345,6 +357,7 @@ (check-component-not-main-not-head shape file page) (check-component-not-root shape file page) (check-component-not-ref shape file page) + (check-empty-swap-slot shape file page) (run! #(check-shape % file page libraries :context :main-any) (:shapes shape))) (defn- check-shape-copy-not-root @@ -353,6 +366,7 @@ (check-component-not-main-not-head shape file page) (check-component-not-root shape file page) (check-component-ref shape file page libraries) + (check-empty-swap-slot shape file page) (run! #(check-shape % file page libraries :context :copy-any) (:shapes shape))) (defn- check-shape-not-component @@ -362,6 +376,7 @@ (check-component-not-main-not-head shape file page) (check-component-not-root shape file page) (check-component-not-ref shape file page) + (check-empty-swap-slot shape file page) (run! #(check-shape % file page libraries :context :not-component) (:shapes shape))) (defn- check-shape