forked from Odinodin/data-frisk-reagent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec.cljs
29 lines (25 loc) · 1.14 KB
/
spec.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
(ns datafrisk.spec
(:require [datafrisk.view :refer [Root]]
[rum.core :as rum]))
(defn spec-problem->metadata-path [{:keys [in path pred val via]}]
[in {:error (str "(not "
(clojure.string/replace (str pred) "cljs.core/" "")
")")}])
(defn frisk-errors [id errors]
{:data (:cljs.spec.alpha/value errors)
:state (atom {:data-frisk {id {:metadata-paths (-> (into {} (map spec-problem->metadata-path (:cljs.spec.alpha/problems errors)))
(update [] assoc :expanded? true))}}})})
(rum/defc SpecView < rum/static
[{:keys [errors]}]
(let [mangled (frisk-errors "spec-errors" errors)]
(Root (:data mangled) "spec-errors" (:state mangled))))
(rum/defc SpecTitleView < rum/static
[{:keys [errors title] :as args}]
[:div {:style {:background-color "white"
:padding "10px"}}
(if title
[:div {:style (:style title {})} (:text title)]
[:div {}
[:span {:style {:font-weight "700" :color "red"}} "Did not comply with spec "]
[:span {:style {}} (str (:cljs.spec.alpha/spec errors))]])
(SpecView args)])