diff --git a/common/src/app/common/files/tokens.cljc b/common/src/app/common/files/tokens.cljc index fd6d870b60..1e72897aed 100644 --- a/common/src/app/common/files/tokens.cljc +++ b/common/src/app/common/files/tokens.cljc @@ -479,6 +479,18 @@ (:id file-data))] (= source id))) +(defn editable-tokens? + "Returns true if the file-data owns its tokens (no external source or source is itself)." + [file-data] + (let [source (:tokens-source file-data)] + (or (nil? source) (= source (:id file-data))))) + +(defn has-tokens-lib? + "Returns true if the file-data has its own tokens-lib (not an external source)." + [file-data] + (and (some? (:tokens-lib file-data)) + (:nil? (:tokens-source file-data)))) + (defn get-tokens-lib [file-data] (:tokens-lib file-data)) diff --git a/common/test/common_tests/files/tokens_test.cljc b/common/test/common_tests/files/tokens_test.cljc index 074ef8b326..913c13b596 100644 --- a/common/test/common_tests/files/tokens_test.cljc +++ b/common/test/common_tests/files/tokens_test.cljc @@ -322,6 +322,23 @@ file-data (cfo/set-tokens-source (:data file) source-id)] (t/is (false? (cfo/tokens-source? file-data (uuid/next))))))) +(t/deftest test-editable-tokens? + (t/testing "returns true when file-data has no tokens-source" + (let [file (thf/sample-file :file1) + file-data (:data file)] + (t/is (true? (cfo/editable-tokens? file-data))))) + + (t/testing "returns true when tokens-source is the file's own id" + (let [file (thf/sample-file :file1) + file-data (cfo/set-tokens-source (:data file) (:id (:data file)))] + (t/is (true? (cfo/editable-tokens? file-data))))) + + (t/testing "returns false when tokens-source is a different uuid" + (let [source-id (thi/new-id! :tokens-source) + file (thf/sample-file :file1) + file-data (cfo/set-tokens-source (:data file) source-id)] + (t/is (false? (cfo/editable-tokens? file-data)))))) + (t/deftest test-get-tokens-status (t/testing "returns tokens-status from file data" (let [tokens-status (ctos/make-tokens-status) diff --git a/frontend/src/app/main/ui/workspace/libraries.cljs b/frontend/src/app/main/ui/workspace/libraries.cljs index 0a2f5908f2..c21eec5d14 100644 --- a/frontend/src/app/main/ui/workspace/libraries.cljs +++ b/frontend/src/app/main/ui/workspace/libraries.cljs @@ -9,6 +9,7 @@ (:require [app.common.data :as d] [app.common.data.macros :as dm] + [app.common.files.tokens :as cfo] [app.common.files.variant :as cfv] [app.common.types.components-list :as ctkl] [app.common.types.file :as ctf] @@ -335,7 +336,10 @@ [:div {:class (stl/css :item-content)} [:div {:class (stl/css :item-title)} (tr "workspace.libraries.file-library")] [:ul {:class (stl/css :item-contents)} - [:> library-description* {:summary summary}]]] + [:> library-description* {:summary summary}]] + (when (contains? cf/flags :token-lib-sync) + (when (cfo/tokens-source? local-library (:id local-library)) + [:div (tr "workspace.libraries.tokens-source")]))] (if ^boolean is-shared [:> button* {:variant "secondary" @@ -366,7 +370,11 @@ [:div {:class (stl/css :connected-to-wrapper)} [:span "(" (tr "workspace.libraries.connected-to") " "] [:span {:class (stl/css :connected-to-values)} (str/join ", " connected-to-names)] - [:span ")"]])])]] + [:span ")"]])])] + (when (contains? cf/flags :token-lib-sync) + (when (cfo/tokens-source? local-library id) + [:div (tr "workspace.libraries.tokens-source")]))] + [:div {:class (stl/css :library-actions)} (when ^boolean has-tokens? [:> icon-button* diff --git a/frontend/translations/en.po b/frontend/translations/en.po index 82e3f9a11d..7f7174706e 100644 --- a/frontend/translations/en.po +++ b/frontend/translations/en.po @@ -7117,6 +7117,10 @@ msgstr "some templates in here" msgid "workspace.libraries.file-library" msgstr "File library" +#: src/app/main/ui/workspace/libraries.cljs:336 +msgid "workspace.libraries.tokens-source" +msgstr "Tokens source" + #: src/app/main/ui/workspace/libraries.cljs:100, src/app/main/ui/workspace/libraries.cljs:124 msgid "workspace.libraries.graphics" msgid_plural "workspace.libraries.graphics" diff --git a/frontend/translations/es.po b/frontend/translations/es.po index ca27370228..3c1b22d9e3 100644 --- a/frontend/translations/es.po +++ b/frontend/translations/es.po @@ -6944,6 +6944,10 @@ msgstr "algunas plantillas aquĆ­" msgid "workspace.libraries.file-library" msgstr "Biblioteca del archivo" +#: src/app/main/ui/workspace/libraries.cljs:336 +msgid "workspace.libraries.tokens-source" +msgstr "Fuente de tokens" + #: src/app/main/ui/workspace/libraries.cljs:100, src/app/main/ui/workspace/libraries.cljs:124 msgid "workspace.libraries.graphics" msgid_plural "workspace.libraries.graphics"