🔧 Move token update to workspace.data and rename to propagation

This commit is contained in:
Andrés Moya 2025-04-25 14:20:01 +02:00 committed by Andrés Moya
parent 37cf829188
commit 23e17d7f30
4 changed files with 29 additions and 28 deletions

View file

@ -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))))))))

View file

@ -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))))))))))))

View file

@ -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

View file

@ -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