From 04be6b13bee577d68f84df112a4f696d111bc4ad Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 29 Jan 2024 14:52:05 +0100 Subject: [PATCH] :bug: Fix invalid colors on file library on comp-v2 migration --- backend/src/app/features/components_v2.clj | 23 +++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/backend/src/app/features/components_v2.clj b/backend/src/app/features/components_v2.clj index ab0ac200d..528518307 100644 --- a/backend/src/app/features/components_v2.clj +++ b/backend/src/app/features/components_v2.clj @@ -105,7 +105,12 @@ ;; FILE PREPARATION BEFORE MIGRATION ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(def valid-color? (sm/lazy-validator ::ctc/recent-color)) +(def valid-recent-color? + (sm/lazy-validator ::ctc/recent-color)) + +(def valid-color? + (sm/lazy-validator ::ctc/color)) + (def valid-fill? (sm/lazy-validator ::cts/fill)) (def valid-stroke? (sm/lazy-validator ::cts/stroke)) (def valid-flow? (sm/lazy-validator ::ctp/flow)) @@ -223,9 +228,17 @@ ;; fix that issues. fix-file-data (fn [file-data] - (-> file-data - (d/update-when :colors dissoc nil) - (d/update-when :typographies dissoc nil))) + (letfn [(fix-colors-library [colors] + (let [colors (dissoc colors nil)] + (reduce-kv (fn [colors id color] + (if (valid-color? color) + colors + (dissoc colors id))) + colors + colors)))] + (-> file-data + (d/update-when :colors fix-colors-library) + (d/update-when :typographies dissoc nil)))) delete-big-geometry-shapes (fn [file-data] @@ -416,7 +429,7 @@ ;; Remove invalid colors in :recent-colors (d/update-when file-data :recent-colors (fn [colors] - (filterv valid-color? colors)))) + (filterv valid-recent-color? colors)))) fix-broken-parents (fn [file-data]