From 6b09ebb75d406f8bb27364af17a1cedb153dff20 Mon Sep 17 00:00:00 2001 From: Pablo Alba Date: Mon, 6 Nov 2023 18:23:58 +0100 Subject: [PATCH] :sparkles: Add validate and repair for component instance head is not a frame --- common/src/app/common/files/repair.cljc | 17 ++++++++ common/src/app/common/files/validate.cljc | 51 ++++++++++++----------- 2 files changed, 44 insertions(+), 24 deletions(-) diff --git a/common/src/app/common/files/repair.cljc b/common/src/app/common/files/repair.cljc index 878336145..698ecb354 100644 --- a/common/src/app/common/files/repair.cljc +++ b/common/src/app/common/files/repair.cljc @@ -387,6 +387,23 @@ (pcb/with-file-data file-data) (pcb/update-shapes [(:id shape)] repair-shape)))) +(defmethod repair-error :instance-head-not-frame + [_ {:keys [shape page-id] :as error} file-data _] + (let [repair-shape + (fn [shape] + ; Convert the shape in a frame. + (log/debug :hint " -> Set :type :frame") + (assoc shape :type :frame + :fills [] + :hide-in-viewer true + :rx 0 + :ry 0))] + + (log/info :hint "Repairing shape :instance-head-not-frame" :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 :default [_ error file _] (log/error :hint "Unknown error code, don't know how to repair" :code (:code error)) diff --git a/common/src/app/common/files/validate.cljc b/common/src/app/common/files/validate.cljc index eec7ac026..c690bf713 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -349,34 +349,37 @@ (validate-frame shape file page) (if (ctk/instance-head? shape) - - (if (ctk/instance-root? shape) + (if (not= :frame (:type shape)) + (report-error :instance-head-not-frame + (str/format "Instance head should be a frame") + shape file page) - (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 (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-copy-not-allowed - (str/format "Root copy component not allowed inside other component") - shape file page) - (validate-shape-copy-root-top shape file page libraries))) + (if (not= context :not-component) + (report-error :root-copy-not-allowed + (str/format "Root copy 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)) + (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)) - (if (= context :not-component) - (report-error :nested-copy-not-allowed - (str/format "Nested copy component only allowed inside other component") - shape file page) - (validate-shape-copy-root-nested shape file page libraries)))) + (if (= context :not-component) + (report-error :nested-copy-not-allowed + (str/format "Nested copy component only allowed inside other component") + shape file page) + (validate-shape-copy-root-nested shape file page libraries))))) (if (ctk/in-component-copy? shape) (if-not (#{:copy-top :copy-nested :copy-any} context)