mirror of
https://github.com/penpot/penpot.git
synced 2026-10-29 05:50:35 +00:00
🐛 Allow creating tokens when the file is its own tokens source (#12182)
Setting the local file back as the tokens source, or unlinking the library that was the source, stored the file's own id in :tokens-source. ensure-tokens-lib only created a tokens-lib when :tokens-source was nil, so a file without a tokens-lib never got one, and every token change was dropped without any error. Now ensure-tokens-lib also creates the tokens-lib when the source is the file itself, which fixes files already in that state, and set-tokens-source removes the attribute instead of storing the file's own id. Closes #12180 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
41efc3558a
commit
31a079a7a2
@ -460,10 +460,13 @@
|
||||
:active-set-ids active-set-ids)))
|
||||
|
||||
(defn ensure-tokens-lib
|
||||
"Ensure file-data has a :tokens-lib or :tokens-source, and also a :tokens-status, creating them if necessary."
|
||||
"Ensure file-data has a :tokens-lib or an external :tokens-source, and also a :tokens-status,
|
||||
creating them if necessary."
|
||||
[file-data]
|
||||
(cond-> file-data
|
||||
(nil? (:tokens-source file-data))
|
||||
(let [tokens-source (:tokens-source file-data)]
|
||||
(or (nil? tokens-source)
|
||||
(= tokens-source (:id file-data))))
|
||||
(update :tokens-lib #(or % (ctob/make-tokens-lib)))
|
||||
|
||||
:always
|
||||
@ -488,9 +491,12 @@
|
||||
(or (:tokens-source file-data) (:id file-data)))
|
||||
|
||||
(defn set-tokens-source
|
||||
"Set the tokens source of the file. Setting it to nil or to the file itself
|
||||
removes the attribute, so the file uses its own tokens-lib."
|
||||
[file-data tokens-source]
|
||||
(assert (or (nil? tokens-source) (uuid? tokens-source)) "expected nil or valid uuid")
|
||||
(if (nil? tokens-source)
|
||||
(if (or (nil? tokens-source)
|
||||
(= tokens-source (:id file-data)))
|
||||
(dissoc file-data :tokens-source)
|
||||
(assoc file-data :tokens-source tokens-source)))
|
||||
|
||||
|
||||
@ -254,6 +254,14 @@
|
||||
(t/is (not (contains? file-data' :tokens-lib)))
|
||||
(t/is (= source-id (:tokens-source file-data')))
|
||||
(t/is (contains? file-data' :tokens-status))
|
||||
(t/is (ctos/tokens-status? (:tokens-status file-data')))))
|
||||
|
||||
(t/testing "ensure-tokens-lib should add a tokens-lib if the tokens-source is the file itself"
|
||||
(let [file (thf/sample-file :file1)
|
||||
file-data (-> (ctf/file-data file)
|
||||
(assoc :tokens-source (:id file)))
|
||||
file-data' (cfo/ensure-tokens-lib file-data)]
|
||||
(t/is (ctob/tokens-lib? (:tokens-lib file-data')))
|
||||
(t/is (ctos/tokens-status? (:tokens-status file-data'))))))
|
||||
|
||||
(t/deftest test-get-tokens-lib
|
||||
@ -293,7 +301,16 @@
|
||||
file (thf/sample-file :file1)
|
||||
file-data (:data file)
|
||||
file-data' (cfo/set-tokens-source file-data source-id)]
|
||||
(t/is (= source-id (:tokens-source file-data'))))))
|
||||
(t/is (= source-id (:tokens-source file-data')))))
|
||||
|
||||
(t/testing "removes tokens-source when set to the file itself"
|
||||
(let [source-id (thi/new-id! :tokens-source)
|
||||
file (thf/sample-file :file1)
|
||||
file-data (-> (ctf/file-data file)
|
||||
(assoc :tokens-source source-id))
|
||||
file-data' (cfo/set-tokens-source file-data (:id file))]
|
||||
(t/is (not (contains? file-data' :tokens-source)))
|
||||
(t/is (= (:id file) (cfo/get-effective-tokens-source file-data'))))))
|
||||
|
||||
(t/deftest test-effective-tokens-source?
|
||||
(t/testing "no tokens, no tokens-source, ask for file id -> true"
|
||||
|
||||
@ -146,7 +146,7 @@
|
||||
(t/is (= (ctos/get-active-set-ids file-tokens-status)
|
||||
(ctos/get-active-set-ids undo-tokens-status)))))
|
||||
|
||||
(t/testing "if the library is the same file, the source is set to self and the status is the same one"
|
||||
(t/testing "if the library is the same file, the source is removed and the status is the same one"
|
||||
(let [set-id (uuid/next)
|
||||
file (tht/sample-file-with-tokens
|
||||
:file-id :file1
|
||||
@ -166,7 +166,7 @@
|
||||
undo-tokens-status (tht/get-tokens-status undo)]
|
||||
|
||||
;; Redo: source and status copied from library, replacing the previous status
|
||||
(t/is (= (:id file) redo-tokens-source))
|
||||
(t/is (nil? redo-tokens-source))
|
||||
(t/is (= (ctos/get-active-theme-ids file-tokens-status)
|
||||
(ctos/get-active-theme-ids redo-tokens-status)))
|
||||
(t/is (= (ctos/get-active-set-ids file-tokens-status)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user