mirror of
https://github.com/penpot/penpot.git
synced 2026-11-16 15:11:17 +00:00
✨ Track library token usage in analytics events (#12958)
Add a from-library property to the apply-tokens event, true when the file takes its tokens from a linked library. Emit a link-file-to-library-tokens event with tokens-count when the linked library has tokens, mirroring link-file-to-library-variants. Both events share one get-library-usage call. Closes #12915 AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
64a51e86fd
commit
1eccb3b4bb
@ -1753,6 +1753,7 @@
|
||||
(let [libraries (:shared-files state)
|
||||
library (get libraries library-id)
|
||||
variants-count (-> library :library-summary :variants count)
|
||||
tokens-count (or (-> library :library-summary :tokens-count) 0)
|
||||
|
||||
loaded-libraries (->> (dsh/lookup-libraries state)
|
||||
(remove (fn [[_ lib]]
|
||||
@ -1773,14 +1774,25 @@
|
||||
(rx/of (ntf/error (tr "errors.circular-library-reference")))
|
||||
(rx/throw cause))))))
|
||||
(rx/of (ptk/reify ::link-file-to-library-finished))
|
||||
(when (pos? variants-count)
|
||||
(when (or (pos? variants-count) (pos? tokens-count))
|
||||
(->> (rp/cmd! :get-library-usage {:file-id library-id})
|
||||
(rx/map (fn [library-usage]
|
||||
(ev/event {::ev/name "link-file-to-library-variants"
|
||||
:file-id file-id
|
||||
:library-id library-id
|
||||
:variants-count variants-count
|
||||
:library-used-in (:used-in library-usage)}))))))))))
|
||||
(rx/mapcat (fn [library-usage]
|
||||
(let [used-in (:used-in library-usage)]
|
||||
(rx/from
|
||||
(cond-> []
|
||||
(pos? variants-count)
|
||||
(conj (ev/event {::ev/name "link-file-to-library-variants"
|
||||
:file-id file-id
|
||||
:library-id library-id
|
||||
:variants-count variants-count
|
||||
:library-used-in used-in}))
|
||||
|
||||
(pos? tokens-count)
|
||||
(conj (ev/event {::ev/name "link-file-to-library-tokens"
|
||||
:file-id file-id
|
||||
:library-id library-id
|
||||
:tokens-count tokens-count
|
||||
:library-used-in used-in}))))))))))))))
|
||||
|
||||
(defn cleanup-unlinked-libraries
|
||||
"Remove libraries from state that are no longer linked to the given file.
|
||||
|
||||
@ -733,6 +733,8 @@
|
||||
(all-attrs-appliable-for-token? attributes (:type token)))))))
|
||||
shape-ids (d/nilv (keys shapes) [])
|
||||
any-variant? (->> shapes vals (some ctk/is-variant?) boolean)
|
||||
file-data (dsh/lookup-file-data state)
|
||||
from-library (not (cfo/effective-tokens-source? file-data (:id file-data)))
|
||||
|
||||
resolved-value (get-in resolved-tokens [(:name token) :resolved-value])
|
||||
resolved-value (if (contains? cf/flags :tokenscript)
|
||||
@ -746,7 +748,8 @@
|
||||
(-> {::ev/name "apply-tokens"
|
||||
:type type
|
||||
:applied-to attributes
|
||||
:applied-to-variant any-variant?}
|
||||
:applied-to-variant any-variant?
|
||||
:from-library from-library}
|
||||
(merge (meta it)))))
|
||||
(dwu/start-undo-transaction undo-id)
|
||||
(dwsh/update-shapes shape-ids (fn [shape]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user