From 96a5444357bc0af0d8d56e443931ebd5256fb0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 25 Aug 2023 13:13:00 +0200 Subject: [PATCH] :sparkles: Validate frame-id --- common/src/app/common/types/file.cljc | 18 +++++++++++++++--- frontend/src/debug.cljs | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/common/src/app/common/types/file.cljc b/common/src/app/common/types/file.cljc index 948002009..165611f8b 100644 --- a/common/src/app/common/types/file.cljc +++ b/common/src/app/common/types/file.cljc @@ -882,6 +882,19 @@ (str/format "Child %s not found" child-id) shape file page))))))) +(defn validate-frame + "Validate that the frame-id shape exists and is indeed a frame." + [shape file page report-error] + (let [frame (ctst/get-shape page (:frame-id shape))] + (if (nil? frame) + (report-error :frame-not-found + (str/format "Frame %s not found" (:frame-id shape)) + shape file page) + (when (not= (:type frame) :frame) + (report-error :invalid-frame + (str/format "Frame %s is not actually a frame" (:frame-id shape)) + shape file page))))) + (defn validate-component-main-head "Validate shape is a main instance head, component exists and its main-instance points to this shape." [shape file page libraries report-error] @@ -1077,13 +1090,12 @@ (:id shape))})) (vswap! errors conj {:hint msg :code code - :shape shape - :file file - :page page}))))] + :shape shape}))))] (dm/assert! (str/format "Shape %s not found" shape-id) (some? shape)) (validate-parent-children shape file page report-error) + (validate-frame shape file page report-error) (if (ctk/main-instance? shape) diff --git a/frontend/src/debug.cljs b/frontend/src/debug.cljs index 7af0caa35..016a9fa1b 100644 --- a/frontend/src/debug.cljs +++ b/frontend/src/debug.cljs @@ -438,7 +438,7 @@ file page libraries)] - (clj->js errors)))) + (clj->js errors)))) (defn ^:export fix-orphan-shapes []