From 75576c341d2ced8e1921863cf36ea5e1bc9ca078 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 25 Jan 2024 14:39:46 +0100 Subject: [PATCH] :bug: Fix broken bool shapes on comp-v2 migration --- backend/src/app/features/components_v2.clj | 31 +++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index 516db13f8..6c4ea127c 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -16,6 +16,7 @@ [app.common.files.migrations :as fmg] [app.common.files.shapes-helpers :as cfsh] [app.common.files.validate :as cfv] + [app.common.geom.matrix :as gmt] [app.common.geom.point :as gpt] [app.common.geom.rect :as grc] [app.common.geom.shapes :as gsh] @@ -285,9 +286,10 @@ (d/update-when container :objects update-vals fix-shape)) (fix-shape [shape] - (if (and (cfh/path-shape? shape) - (seq (:content shape)) - (not (valid-path-content? (:content shape)))) + (cond + (and (cfh/path-shape? shape) + (seq (:content shape)) + (not (valid-path-content? (:content shape)))) (let [shape (update shape :content fix-path-content) [points selrect] (gshp/content->points+selrect shape (:content shape))] (-> shape @@ -295,6 +297,29 @@ (dissoc :bool-type) (assoc :points points) (assoc :selrect selrect))) + + ;; When we fount a bool shape with no content, + ;; we convert it to a simple rect + (and (cfh/bool-shape? shape) + (not (seq (:bool-content shape)))) + (let [selrect (or (:selrect shape) + (grc/make-rect)) + points (grc/rect->points selrect)] + (-> shape + (assoc :x (:x selrect)) + (assoc :y (:y selrect)) + (assoc :width (:height selrect)) + (assoc :height (:height selrect)) + (assoc :selrect selrect) + (assoc :points points) + (assoc :type :rect) + (assoc :transform (gmt/matrix)) + (assoc :transform-inverse (gmt/matrix)) + (dissoc :bool-content) + (dissoc :shapes) + (dissoc :content))) + + :else shape)) (fix-path-content [content]