From ccbf17106d470085b49978cbcc5228c9bef852aa Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 22 Apr 2025 15:04:22 +0200 Subject: [PATCH] :bug: Add migration for decoding and cleaning shape interactions --- common/src/app/common/files/migrations.cljc | 27 ++++++++++++++++++++- common/src/app/common/schema.cljc | 2 +- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index b0c806103c..47426305fc 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -28,6 +28,7 @@ [app.common.types.container :as ctn] [app.common.types.file :as ctf] [app.common.types.shape :as cts] + [app.common.types.shape.interactions :as ctsi] [app.common.types.shape.shadow :as ctss] [app.common.uuid :as uuid] [clojure.set :as set] @@ -1241,6 +1242,29 @@ (update data :pages-index d/update-vals update-page))) +(defmethod migrate-data "0002-clean-shape-interactions" + [data _] + (let [decode-fn (sm/decoder ctsi/schema:interaction sm/json-transformer) + validate-fn (sm/validator ctsi/schema:interaction) + + xform + (comp + (map decode-fn) + (filter validate-fn)) + + update-object + (fn [object] + (d/update-when object :interactions + (fn [interactions] + (into [] xform interactions)))) + + update-container + (fn [container] + (d/update-when container :objects d/update-vals update-object))] + + (-> data + (update :pages-index d/update-vals update-container) + (update :components d/update-vals update-container)))) (def available-migrations (into (d/ordered-set) @@ -1296,4 +1320,5 @@ "legacy-65" "legacy-66" "legacy-67" - "0001-remove-tokens-from-groups"])) + "0001-remove-tokens-from-groups" + "0002-clean-shape-interactions"])) diff --git a/common/src/app/common/schema.cljc b/common/src/app/common/schema.cljc index 23d32e3e73..64eaa1f9b9 100644 --- a/common/src/app/common/schema.cljc +++ b/common/src/app/common/schema.cljc @@ -864,7 +864,7 @@ choices))] {:pred pred :type-properties - {:title "contains" + {:title "contains any" :description "contains predicate"}}))}) (register!