better warning behavior.A
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
(ns auto-ap.forms
|
(ns auto-ap.forms
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
|
[re-frame.interceptor :as i]
|
||||||
[auto-ap.views.utils :refer [dispatch-event bind-field]]))
|
[auto-ap.views.utils :refer [dispatch-event bind-field]]))
|
||||||
|
|
||||||
|
|
||||||
@@ -89,6 +90,17 @@
|
|||||||
(assoc-in [::forms id :status] :loading)
|
(assoc-in [::forms id :status] :loading)
|
||||||
(assoc-in [::forms id :error] nil)))
|
(assoc-in [::forms id :error] nil)))
|
||||||
|
|
||||||
|
(defn settles [{:keys [event time key]}]
|
||||||
|
(i/->interceptor
|
||||||
|
:id :settles
|
||||||
|
:befor (fn [context]
|
||||||
|
(println "here2")
|
||||||
|
context)
|
||||||
|
:after (fn [context]
|
||||||
|
(i/assoc-effect context :dispatch-debounce {:event event
|
||||||
|
:time time
|
||||||
|
:key key}))))
|
||||||
|
|
||||||
(defn triggers-loading [form]
|
(defn triggers-loading [form]
|
||||||
(re-frame/enrich
|
(re-frame/enrich
|
||||||
(fn [db event]
|
(fn [db event]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
[reagent.core :as r]
|
[reagent.core :as r]
|
||||||
[auto-ap.events :as events]
|
[auto-ap.events :as events]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
[auto-ap.views.utils :refer [with-keys]]))
|
[auto-ap.views.utils :refer [with-keys appearing]]))
|
||||||
|
|
||||||
(defn modal [{:keys [title foot hide-event class]} & body]
|
(defn modal [{:keys [title foot hide-event class]} & body]
|
||||||
[:div.modal.is-active (cond-> {}
|
[:div.modal.is-active (cond-> {}
|
||||||
@@ -43,9 +43,15 @@
|
|||||||
]
|
]
|
||||||
:id id
|
:id id
|
||||||
:hide-event [::events/modal-status id {:visible? false}]}
|
:hide-event [::events/modal-status id {:visible? false}]}
|
||||||
(when error-message
|
[appearing {:visible? error-message
|
||||||
[:div.notification.is-warning error-message])
|
:timeout 200
|
||||||
(when warning
|
:enter-class "appear"
|
||||||
[:div.notification.is-info warning])]
|
:exit-class "disappear"}
|
||||||
|
[:div.notification.is-warning error-message]]
|
||||||
|
[appearing {:visible? warning
|
||||||
|
:timeout 200
|
||||||
|
:enter-class "appear"
|
||||||
|
:exit-class "disappear"}
|
||||||
|
[:div.notification.is-info warning]]]
|
||||||
(into (r/children (r/current-component)))
|
(into (r/children (r/current-component)))
|
||||||
(into [(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]))])))
|
(into [(when saving? [:div.is-overlay {:style {"backgroundColor" "rgba(150,150,150, 0.5)"}}])]))])))
|
||||||
|
|||||||
@@ -18,20 +18,27 @@
|
|||||||
(mapv #(.toLowerCase (str/join "" %))
|
(mapv #(.toLowerCase (str/join "" %))
|
||||||
(partition len 1 text)))
|
(partition len 1 text)))
|
||||||
|
|
||||||
(defn partial-matches-vendor? [vendor vendors]
|
(re-frame/reg-event-db
|
||||||
(when (> (count (:name vendor)) 5)
|
::settled
|
||||||
(let [text (.toLowerCase (:name vendor))]
|
[(forms/in-form ::vendor-form)]
|
||||||
(->> vendors
|
(fn [{:keys [data] :as form} _]
|
||||||
(filter #(not= (:id %) (:id vendor)))
|
(let [vendors @(re-frame/subscribe [::subs/vendors])
|
||||||
(map :name)
|
text (.toLowerCase (:name data))
|
||||||
(mapcat
|
matching-vendor (when (> (count text) 5)
|
||||||
(fn [v] (mapv
|
(->> vendors
|
||||||
(fn [n] [v (jaro-winkler text n ) n text])
|
(filter #(not= (:id %) (:id data)))
|
||||||
(ngrams v (count text)))))
|
(map :name)
|
||||||
(filter #(> (second %) 0.9))
|
(mapcat
|
||||||
#_(map (fn [x] (doto x println)))
|
(fn [v] (mapv
|
||||||
(map first)
|
(fn [n] [v (jaro-winkler text n ) n text])
|
||||||
first))))
|
(ngrams v (count text)))))
|
||||||
|
(filter #(> (second %) 0.9))
|
||||||
|
#_(map (fn [x] (doto x println)))
|
||||||
|
(map first)
|
||||||
|
first))]
|
||||||
|
(if matching-vendor
|
||||||
|
(assoc form :warning (str "Are you sure you don't mean " matching-vendor "?"))
|
||||||
|
(dissoc form :warning)))))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::removed-override
|
::removed-override
|
||||||
@@ -76,6 +83,9 @@
|
|||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::changed
|
::changed
|
||||||
|
[(forms/settles {:key ::vendor-form
|
||||||
|
:time 500
|
||||||
|
:event [::settled]})]
|
||||||
(forms/change-handler
|
(forms/change-handler
|
||||||
::vendor-form
|
::vendor-form
|
||||||
(fn [data field value]
|
(fn [data field value]
|
||||||
@@ -308,7 +318,7 @@
|
|||||||
(defn vendor-dialog [{:keys [save-event] }]
|
(defn vendor-dialog [{:keys [save-event] }]
|
||||||
(let [clients @(re-frame/subscribe [::subs/clients])
|
(let [clients @(re-frame/subscribe [::subs/clients])
|
||||||
all-vendors @(re-frame/subscribe [::subs/vendors])
|
all-vendors @(re-frame/subscribe [::subs/vendors])
|
||||||
{:keys [data error ] :as f} @(re-frame/subscribe [::forms/form ::vendor-form])
|
{:keys [data error warning] :as f} @(re-frame/subscribe [::forms/form ::vendor-form])
|
||||||
change-event [::changed]]
|
change-event [::changed]]
|
||||||
[action-modal {:id ::dialog
|
[action-modal {:id ::dialog
|
||||||
:class ["wide"]
|
:class ["wide"]
|
||||||
@@ -319,9 +329,7 @@
|
|||||||
[:span.icon.has-text-danger
|
[:span.icon.has-text-danger
|
||||||
[:i.fa.fa-exclamation-triangle]])]
|
[:i.fa.fa-exclamation-triangle]])]
|
||||||
:status-from ::vendor-form
|
:status-from ::vendor-form
|
||||||
#_#_:warning
|
:warning warning
|
||||||
(when-let [vendor (partial-matches-vendor? data all-vendors)]
|
|
||||||
(str "Are you sure you don't mean " vendor "?"))
|
|
||||||
:action-text "Save"
|
:action-text "Save"
|
||||||
:save-event [::save]
|
:save-event [::save]
|
||||||
:can-submit? (s/valid? ::entity/vendor data)}
|
:can-submit? (s/valid? ::entity/vendor data)}
|
||||||
|
|||||||
Reference in New Issue
Block a user