From db215254852410349f28f2e69961829c98b8a2b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Tue, 23 Jan 2024 16:35:54 +0100 Subject: [PATCH] :bug: Add validation check for duplicated children --- common/src/app/common/files/repair.cljc | 13 +++++++++++++ common/src/app/common/files/validate.cljc | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/common/src/app/common/files/repair.cljc b/common/src/app/common/files/repair.cljc index 8aead05bc..4a824682e 100644 --- a/common/src/app/common/files/repair.cljc +++ b/common/src/app/common/files/repair.cljc @@ -66,6 +66,19 @@ (pcb/with-file-data file-data) (pcb/update-shapes [(:parent-id shape)] repair-shape)))) +(defmethod repair-error :duplicated-children + [_ {:keys [shape page-id] :as error} file-data _] + (let [repair-shape + (fn [shape] + ; Remove duplicated + (log/debug :hint " -> remove duplicated children") + (update shape :shapes distinct))] + + (log/dbg :hint "repairing shape :duplicated-children" :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 :child-not-found [_ {: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 ca4d471cb..01373f93c 100644 --- a/common/src/app/common/files/validate.cljc +++ b/common/src/app/common/files/validate.cljc @@ -26,6 +26,7 @@ #{:invalid-geometry :parent-not-found :child-not-in-parent + :duplicated-children :child-not-found :frame-not-found :invalid-frame @@ -123,6 +124,11 @@ (str/ffmt "Shape % not in parent's children list" (:id shape)) shape file page))) + (when-not (= (count (:shapes shape)) (count (distinct (:shapes shape)))) + (report-error :duplicated-children + (str/ffmt "Shape % has duplicated children" (:id shape)) + shape file page)) + (doseq [child-id (:shapes shape)] (let [child (ctst/get-shape page child-id)] (if (nil? child)