📎 Add minor improvement on notification message validation

This commit is contained in:
Andrey Antukh 2024-07-22 13:11:49 +02:00
parent 9e0fb44b3f
commit 7e50ab52b9

View file

@ -17,39 +17,40 @@
(def default-timeout 7000) (def default-timeout 7000)
(def ^:private (def ^:private schema:message
schema:message [:map {:title "Message"}
(sm/define [:type [::sm/one-of #{:success :error :info :warning}]]
[:map {:title "Message"} [:status {:optional true}
[:type [::sm/one-of #{:success :error :info :warning}]] [::sm/one-of #{:visible :hide}]]
[:status {:optional true} [:position {:optional true}
[::sm/one-of #{:visible :hide}]] [::sm/one-of #{:fixed :floating :inline}]]
[:position {:optional true} [:notification-type {:optional true}
[::sm/one-of #{:fixed :floating :inline}]] [::sm/one-of #{:inline :context :toast}]]
[:notification-type {:optional true} [:controls {:optional true}
[::sm/one-of #{:inline :context :toast}]] [::sm/one-of #{:none :close :inline-actions :bottom-actions}]]
[:controls {:optional true} [:tag {:optional true}
[::sm/one-of #{:none :close :inline-actions :bottom-actions}]] [:or :string :keyword]]
[:tag {:optional true} [:timeout {:optional true}
[:or :string :keyword]] [:maybe :int]]
[:timeout {:optional true} [:actions {:optional true}
[:maybe :int]] [:vector
[:actions {:optional true} [:map
[:vector [:label :string]
[:map [:callback ::sm/fn]]]]
[:label :string] [:links {:optional true}
[:callback ::sm/fn]]]] [:vector
[:links {:optional true} [:map
[:vector [:label :string]
[:map [:callback ::sm/fn]]]]])
[:label :string]
[:callback ::sm/fn]]]]])) (def ^:private valid-message?
(sm/validator schema:message))
(defn show (defn show
[data] [data]
(dm/assert! (dm/assert!
"expected valid message map" "expected valid message map"
(sm/check! schema:message data)) (valid-message? data))
(ptk/reify ::show (ptk/reify ::show
ptk/UpdateEvent ptk/UpdateEvent