From 23e17d7f302bd1debc35ac576e9ba6c3fbba7989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Moya?= Date: Fri, 25 Apr 2025 14:20:01 +0200 Subject: [PATCH] :wrench: Move token update to workspace.data and rename to propagation --- .../data/workspace/tokens/library_edit.cljs | 18 ++++++------ .../workspace/tokens/propagation.cljs} | 29 ++++++++++--------- .../app/main/ui/workspace/tokens/form.cljs | 4 +-- .../logic/components_and_tokens.cljs | 6 ++-- 4 files changed, 29 insertions(+), 28 deletions(-) rename frontend/src/app/main/{ui/workspace/tokens/update.cljs => data/workspace/tokens/propagation.cljs} (90%) diff --git a/frontend/src/app/main/data/workspace/tokens/library_edit.cljs b/frontend/src/app/main/data/workspace/tokens/library_edit.cljs index f5d131a87..cc3a345cf 100644 --- a/frontend/src/app/main/data/workspace/tokens/library_edit.cljs +++ b/frontend/src/app/main/data/workspace/tokens/library_edit.cljs @@ -18,7 +18,7 @@ [app.main.data.helpers :as dsh] [app.main.data.notifications :as ntf] [app.main.data.workspace.shapes :as dwsh] - [app.main.ui.workspace.tokens.update :as wtu] + [app.main.data.workspace.tokens.propagation :as dwtp] [app.util.i18n :refer [tr]] [beicon.v2.core :as rx] [potok.v2.core :as ptk])) @@ -123,7 +123,7 @@ (pcb/update-active-token-themes active-token-themes' prev-active-token-themes))] (rx/of (dch/commit-changes changes) - (wtu/update-workspace-tokens)))))) + (dwtp/propagate-workspace-tokens)))))) (defn delete-token-theme [group theme-name] (ptk/reify ::delete-token-theme @@ -135,7 +135,7 @@ (pcb/set-token-theme group theme-name nil))] (rx/of (dch/commit-changes changes) - (wtu/update-workspace-tokens)))))) + (dwtp/propagate-workspace-tokens)))))) (defn create-token-set [set-name] @@ -221,7 +221,7 @@ (clt/generate-toggle-token-set tlib name))] (rx/of (dch/commit-changes changes) - (wtu/update-workspace-tokens)))))) + (dwtp/propagate-workspace-tokens)))))) (defn toggle-token-set-group [group-path] (ptk/reify ::toggle-token-set-group @@ -233,7 +233,7 @@ (clt/generate-toggle-token-set-group (get-tokens-lib state) group-path))] (rx/of (dch/commit-changes changes) - (wtu/update-workspace-tokens)))))) + (dwtp/propagate-workspace-tokens)))))) (defn import-tokens-lib [lib] (ptk/reify ::import-tokens-lib @@ -244,7 +244,7 @@ (pcb/with-library-data data) (pcb/set-tokens-lib lib))] (rx/of (dch/commit-changes changes) - (wtu/update-workspace-tokens)))))) + (dwtp/propagate-workspace-tokens)))))) (defn delete-token-set-path [group? path] @@ -256,7 +256,7 @@ (pcb/with-library-data data) (pcb/set-token-set (ctob/join-set-path path) group? nil))] (rx/of (dch/commit-changes changes) - (wtu/update-workspace-tokens)))))) + (dwtp/propagate-workspace-tokens)))))) (defn drop-error [{:keys [error to-path]}] (ptk/reify ::drop-error @@ -283,7 +283,7 @@ (when-let [changes (clt/generate-move-token-set-group (pcb/empty-changes it) (get-tokens-lib state) drop-opts)] (rx/of (dch/commit-changes changes) - (wtu/update-workspace-tokens))) + (dwtp/propagate-workspace-tokens))) (catch :default e (rx/of (drop-error (ex-data e)))))))) @@ -300,7 +300,7 @@ changes (-> (pcb/empty-changes it) (clt/generate-move-token-set tokens-lib params))] (rx/of (dch/commit-changes changes) - (wtu/update-workspace-tokens))) + (dwtp/propagate-workspace-tokens))) (catch :default cause (rx/of (drop-error (ex-data cause)))))))) diff --git a/frontend/src/app/main/ui/workspace/tokens/update.cljs b/frontend/src/app/main/data/workspace/tokens/propagation.cljs similarity index 90% rename from frontend/src/app/main/ui/workspace/tokens/update.cljs rename to frontend/src/app/main/data/workspace/tokens/propagation.cljs index 79a8bf7a4..7bef78254 100644 --- a/frontend/src/app/main/ui/workspace/tokens/update.cljs +++ b/frontend/src/app/main/data/workspace/tokens/propagation.cljs @@ -4,7 +4,7 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.main.ui.workspace.tokens.update +(ns app.main.data.workspace.tokens.propagation (:require [app.common.files.helpers :as cfh] [app.common.logging :as l] @@ -24,9 +24,9 @@ ;; Constants ------------------------------------------------------------------- -(def filter-existing-values? false) +(def ^:private filter-existing-values? false) -(def attributes->shape-update +(def ^:private attributes->shape-update {ctt/border-radius-keys dwta/update-shape-radius-for-corners ctt/color-keys dwta/update-fill-stroke ctt/stroke-width-keys dwta/update-stroke-width @@ -48,6 +48,7 @@ ;; Helpers --------------------------------------------------------------------- +;; TODO: see if this can be replaced by more standard functions (defn deep-merge "Like d/deep-merge but unions set values." ([a b] @@ -60,7 +61,7 @@ ;; Data flows ------------------------------------------------------------------ -(defn invert-collect-key-vals +(defn- invert-collect-key-vals [xs resolved-tokens shape] (-> (reduce (fn [acc [k v]] @@ -74,7 +75,7 @@ (update acc resolved-value (fnil conj #{}) k)))) {} xs))) -(defn split-attribute-groups [attrs-values-map] +(defn- split-attribute-groups [attrs-values-map] (reduce (fn [acc [attrs v]] (cond @@ -91,7 +92,7 @@ attrs (assoc acc attrs v))) {} attrs-values-map)) -(defn shape-ids-by-values +(defn- shape-ids-by-values [attrs-values-map object-id] (->> (map (fn [[value attrs]] [attrs {value #{object-id}}]) attrs-values-map) (into {}))) @@ -121,7 +122,6 @@ [tokens frame-ids text-ids]))) -;; FIXME: revisit this (defn- actionize-shapes-update-info [page-id shapes-update-info] (mapcat (fn [[attrs update-infos]] (let [action (some attribute-actions-map attrs)] @@ -131,14 +131,15 @@ update-infos))) shapes-update-info)) -(defn update-tokens +(defn propagate-tokens + "Propagate tokens values to all shapes where they are applied" [state resolved-tokens] (let [file-id (get state :current-file-id) current-page-id (get state :current-page-id) fdata (dsh/lookup-file-data state file-id) tpoint (dt/tpoint-ms)] - (l/inf :status "START" :hint "update-tokens") + (l/inf :status "START" :hint "propagate-tokens") (->> (rx/concat (rx/of current-page-id) (->> (rx/from (:pages fdata)) @@ -155,7 +156,7 @@ (actionize-shapes-update-info page-id attrs)] (l/inf :status "PROGRESS" - :hint "update-tokens" + :hint "propagate-tokens" :page-id (str page-id) :elapsed (tpoint) ::l/sync? true) @@ -175,11 +176,11 @@ (rx/finalize (fn [_] (let [elapsed (tpoint)] - (l/inf :status "END" :hint "update-tokens" :elapsed elapsed))))))) + (l/inf :status "END" :hint "propagate-tokens" :elapsed elapsed))))))) -(defn update-workspace-tokens +(defn propagate-workspace-tokens [] - (ptk/reify ::update-workspace-tokens + (ptk/reify ::propagate-workspace-tokens ptk/WatchEvent (watch [_ state _] (when-let [tokens-lib (-> (dsh/lookup-file-data state) @@ -191,5 +192,5 @@ (let [undo-id (js/Symbol)] (rx/concat (rx/of (dwu/start-undo-transaction undo-id :timeout false)) - (update-tokens state sd-tokens) + (propagate-tokens state sd-tokens) (rx/of (dwu/commit-undo-transaction undo-id)))))))))))) \ No newline at end of file diff --git a/frontend/src/app/main/ui/workspace/tokens/form.cljs b/frontend/src/app/main/ui/workspace/tokens/form.cljs index 8a698ecda..f3f2fa548 100644 --- a/frontend/src/app/main/ui/workspace/tokens/form.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/form.cljs @@ -17,6 +17,7 @@ [app.main.data.tinycolor :as tinycolor] [app.main.data.workspace.tokens.application :as dwta] [app.main.data.workspace.tokens.library-edit :as dwtl] + [app.main.data.workspace.tokens.propagation :as dwtp] [app.main.refs :as refs] [app.main.store :as st] [app.main.ui.ds.buttons.button :refer [button*]] @@ -29,7 +30,6 @@ [app.main.ui.workspace.tokens.components.controls.input-token-color-bullet :refer [input-token-color-bullet*]] [app.main.ui.workspace.tokens.components.controls.input-tokens :refer [input-tokens*]] [app.main.ui.workspace.tokens.errors :as wte] - [app.main.ui.workspace.tokens.update :as wtu] [app.main.ui.workspace.tokens.warnings :as wtw] [app.util.dom :as dom] [app.util.functions :as uf] @@ -461,7 +461,7 @@ :type token-type :value final-value :description final-description})) - (wtu/update-workspace-tokens) + (dwtp/propagate-workspace-tokens) (modal/hide))))))))) on-delete-token diff --git a/frontend/test/frontend_tests/logic/components_and_tokens.cljs b/frontend/test/frontend_tests/logic/components_and_tokens.cljs index 4876e9a74..2add7ecf4 100644 --- a/frontend/test/frontend_tests/logic/components_and_tokens.cljs +++ b/frontend/test/frontend_tests/logic/components_and_tokens.cljs @@ -19,7 +19,7 @@ [app.main.data.workspace.selection :as dws] [app.main.data.workspace.tokens.application :as dwta] [app.main.data.workspace.tokens.library-edit :as dwtl] - [app.main.ui.workspace.tokens.update :as wtu] + [app.main.data.workspace.tokens.propagation :as dwtp] [cljs.test :as t :include-macros true] [frontend-tests.helpers.pages :as thp] [frontend-tests.helpers.state :as ths] @@ -210,7 +210,7 @@ :value 66})] step2 (fn [_] - (let [events2 [(wtu/update-workspace-tokens) + (let [events2 [(dwtp/propagate-workspace-tokens) (dwl/sync-file (:id file) (:id file))]] (tohs/run-store-async store done events2 @@ -380,7 +380,7 @@ :value 200})] step2 (fn [_] - (let [events2 [(wtu/update-workspace-tokens) + (let [events2 [(dwtp/propagate-workspace-tokens) (dwl/sync-file (:id file) (:id file))]] (tohs/run-store-async store done events2