From a097ed29a98b6c0501c55f8f36f3c760e3d6755c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Fri, 1 Sep 2023 13:32:21 +0200 Subject: [PATCH] :sparkles: Fix extensibility and naming of workspace shape fixer --- common/src/app/common/pages/changes.cljc | 15 +++++++++++---- common/src/app/common/types/shape_tree.cljc | 4 ++-- frontend/src/app/main/data/workspace.cljs | 2 +- ...en_shape_links.cljs => fix_broken_shapes.cljs} | 12 ++++++------ 4 files changed, 20 insertions(+), 13 deletions(-) rename frontend/src/app/main/data/workspace/{fix_broken_shape_links.cljs => fix_broken_shapes.cljs} (83%) diff --git a/common/src/app/common/pages/changes.cljc b/common/src/app/common/pages/changes.cljc index 43895ac46..0b0af2fcc 100644 --- a/common/src/app/common/pages/changes.cljc +++ b/common/src/app/common/pages/changes.cljc @@ -97,6 +97,7 @@ [:map {:title "FixObjChange"} [:type [:= :fix-obj]] [:id ::sm/uuid] + [:fix {:optional true} :keyword] [:page-id {:optional true} ::sm/uuid] [:component-id {:optional true} ::sm/uuid]]] @@ -402,10 +403,16 @@ (d/update-in-when data [:components component-id] ctst/delete-shape id ignore-touched))) (defmethod process-change :fix-obj - [data {:keys [page-id component-id] :as params}] - (if page-id - (d/update-in-when data [:pages-index page-id] ctst/fix-shape-children params) - (d/update-in-when data [:components component-id] ctst/fix-shape-children params))) + [data {:keys [page-id component-id id] :as params}] + (letfn [(fix-container [container] + (case (:fix params :broken-children) + :broken-children (ctst/fix-broken-children container id) + (ex/raise :type :internal + :code :fix-not-implemented + :fix (:fix params))))] + (if page-id + (d/update-in-when data [:pages-index page-id] fix-container) + (d/update-in-when data [:components component-id] fix-container)))) ;; FIXME: remove, seems like this method is already unused ;; reg-objects operation "regenerates" the geometry and selrect of the parent groups diff --git a/common/src/app/common/types/shape_tree.cljc b/common/src/app/common/types/shape_tree.cljc index a6455e5d9..2798c9ff8 100644 --- a/common/src/app/common/types/shape_tree.cljc +++ b/common/src/app/common/types/shape_tree.cljc @@ -99,10 +99,10 @@ (update container :objects delete-from-objects)))) -(defn fix-shape-children +(defn fix-broken-children "Checks and fix the children relations of the shape. If a children does not exists on the objects tree, it will be removed from shape." - [{:keys [objects] :as container} {:keys [id] :as params}] + [{:keys [objects] :as container} id] (let [contains? (partial contains? objects)] (d/update-in-when container [:objects id :shapes] (fn [shapes] diff --git a/frontend/src/app/main/data/workspace.cljs b/frontend/src/app/main/data/workspace.cljs index 431c1bfd5..e4e37c3f7 100644 --- a/frontend/src/app/main/data/workspace.cljs +++ b/frontend/src/app/main/data/workspace.cljs @@ -46,7 +46,7 @@ [app.main.data.workspace.drawing.common :as dwdc] [app.main.data.workspace.edition :as dwe] [app.main.data.workspace.fix-bool-contents :as fbc] - [app.main.data.workspace.fix-broken-shape-links :as fbs] + [app.main.data.workspace.fix-broken-shapes :as fbs] [app.main.data.workspace.fix-deleted-fonts :as fdf] [app.main.data.workspace.groups :as dwg] [app.main.data.workspace.guides :as dwgu] diff --git a/frontend/src/app/main/data/workspace/fix_broken_shape_links.cljs b/frontend/src/app/main/data/workspace/fix_broken_shapes.cljs similarity index 83% rename from frontend/src/app/main/data/workspace/fix_broken_shape_links.cljs rename to frontend/src/app/main/data/workspace/fix_broken_shapes.cljs index e547f0c03..9e2e28af3 100644 --- a/frontend/src/app/main/data/workspace/fix_broken_shape_links.cljs +++ b/frontend/src/app/main/data/workspace/fix_broken_shapes.cljs @@ -4,15 +4,15 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.main.data.workspace.fix-broken-shape-links +(ns app.main.data.workspace.fix-broken-shapes (:require [app.main.data.workspace.changes :as dch] [beicon.core :as rx] [potok.core :as ptk])) -(defn- generate-changes +(defn- generate-broken-link-changes [attr {:keys [objects id] :as container}] - (let [base {:type :fix-obj attr id} + (let [base {:type :fix-obj :fix :broken-children attr id} contains? (partial contains? objects) xform (comp ;; FIXME: Ensure all obj have id field (this is needed @@ -36,14 +36,14 @@ (defn fix-broken-shapes [] - (ptk/reify ::fix-broken-shape-links + (ptk/reify ::fix-broken-shapes ptk/WatchEvent (watch [it state _] (let [data (get state :workspace-data) changes (concat - (mapcat (partial generate-changes :page-id) + (mapcat (partial generate-broken-link-changes :page-id) (vals (:pages-index data))) - (mapcat (partial generate-changes :component-id) + (mapcat (partial generate-broken-link-changes :component-id) (vals (:components data))))] (if (seq changes)