From b3e73b9abc227083d7280898681af772858690e9 Mon Sep 17 00:00:00 2001 From: Florian Schroedl Date: Thu, 3 Oct 2024 15:18:41 +0200 Subject: [PATCH] Move over helper --- common/src/app/common/types/tokens_lib.cljc | 8 ++++++++ frontend/src/app/main/ui/workspace/tokens/form.cljs | 8 +------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/common/src/app/common/types/tokens_lib.cljc b/common/src/app/common/types/tokens_lib.cljc index e48c02fd8..0cf38a80a 100644 --- a/common/src/app/common/types/tokens_lib.cljc +++ b/common/src/app/common/types/tokens_lib.cljc @@ -143,6 +143,14 @@ (map second) (into #{}))) +(defn token-value-self-reference? + "Check if the token is self referencing with its `token-name` in `token-value`. + Simple 1 level check, doesn't account for circular self refernces across multiple tokens." + [token-name token-value] + (let [token-references (find-token-value-references token-value) + self-reference? (get token-references token-name)] + self-reference?)) + (defn group-by-type [tokens] (let [tokens' (if (or (map? tokens) (d/ordered-map? tokens)) diff --git a/frontend/src/app/main/ui/workspace/tokens/form.cljs b/frontend/src/app/main/ui/workspace/tokens/form.cljs index 26522e2db..188cc88a8 100644 --- a/frontend/src/app/main/ui/workspace/tokens/form.cljs +++ b/frontend/src/app/main/ui/workspace/tokens/form.cljs @@ -91,12 +91,6 @@ Token names should only contain letters and digits separated by . characters.")} ;; Component ------------------------------------------------------------------- -(defn token-self-reference? - [token-name input] - (let [token-references (ctob/find-token-value-references input) - self-reference? (get token-references token-name)] - self-reference?)) - (defn validate-token-value+ "Validates token value by resolving the value `input` using `StyleDictionary`. Returns a promise of either resolved tokens or rejects with an error state." @@ -108,7 +102,7 @@ Token names should only contain letters and digits separated by . characters.")} (empty? (str/trim value)) (p/rejected {:errors [{:error/code :error/empty-input}]}) - (token-self-reference? token-name value) + (ctob/token-value-self-reference? token-name value) (p/rejected {:errors [(wte/get-error-code :error.token/direct-self-reference)]}) :else