reverted.

This commit is contained in:
2021-05-27 08:25:58 -07:00
parent c7055d7a70
commit 33b45373c2
34 changed files with 443 additions and 2504 deletions

2157
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,6 @@
"test": "test"
},
"dependencies": {
"downshift": "^6.1.3",
"dropzone": "^4.3.0",
"prop-types": "^15.7.2",
"react": "^17.0.1",

View File

@@ -86,9 +86,7 @@
;; needed for java 11
[javax.xml.bind/jaxb-api "2.4.0-b180830.0359"]
[coderafting/memsearch "0.1.0"]]
[javax.xml.bind/jaxb-api "2.4.0-b180830.0359"]]
:managed-dependencies [;; explicit dependencies to get to latest versions for above
[com.fasterxml.jackson.core/jackson-core "2.12.0"]
[com.fasterxml.jackson.core/jackson-databind "2.12.0"]

View File

@@ -130,6 +130,7 @@
(re-frame/enrich
(fn [db event]
(loading db form))))
(defn triggers-stop [form]
(re-frame/enrich
(fn [db event]

View File

@@ -2,8 +2,7 @@
(:require [re-frame.core :as re-frame]
[auto-ap.utils :refer [by]]
[clojure.string :as str]
[goog.crypt.base64 :as base64]
[memsearch.core :as ms]))
[goog.crypt.base64 :as base64]))
(re-frame/reg-sub
::client
@@ -61,17 +60,6 @@
[]
accounts)))
(re-frame/reg-sub
::accounts-index
:<- [::accounts]
(fn [accounts]
(ms/text-index (map (fn [v] {:id (:id v)
:content (str (:numeric-code v) " " (:name v))})
accounts)
{:maintain-actual? true})))
(re-frame/reg-sub
::account
@@ -213,15 +201,6 @@
(filter #(not (:hidden %)) all-vendors))))
(re-frame/reg-sub
::searchable-vendors-index
:<- [::searchable-vendors]
(fn [searchable-vendors]
(ms/text-index (map (fn [v] {:id (:id v)
:content (:name v)})
searchable-vendors)
{:maintain-actual? true})))
(re-frame/reg-sub
::all-vendors
(fn [db]

View File

@@ -2,6 +2,7 @@
(:require
[clojure.spec.alpha :as s]
[auto-ap.entities.invoice :as invoice]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field ->$]]
[auto-ap.subs :as subs]
[re-frame.core :as re-frame]))

View File

@@ -2,6 +2,7 @@
(:require
[clojure.spec.alpha :as s]
[auto-ap.entities.invoice :as invoice]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field date-picker date->str local-now standard]]
[cljs-time.core :as t]
[re-frame.core :as re-frame]))

View File

@@ -4,7 +4,7 @@
[auto-ap.subs :as subs]
[auto-ap.utils :refer [by]]
[auto-ap.views.components.modal :as modal]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
[auto-ap.views.utils :refer [dispatch-event with-user]]
[clojure.string :as str]
@@ -124,10 +124,10 @@
[:tr
[:td.expandable [:div.control
(raw-field
[typeahead-v3 {:entities chooseable-expense-accounts
:type "typeahead-v3"
:entity->text (fn [x] (str (:numeric-code x) " - " (:name x)))
:field [:expense-accounts id :account]}])]]
[typeahead-entity {:matches chooseable-expense-accounts
:type "typeahead-entity"
:match->text (fn [x] (str (:numeric-code x) " - " (:name x)))
:field [:expense-accounts id :account]}])]]
(when multi-location?
[:td

View File

@@ -1,7 +1,7 @@
(ns auto-ap.views.components.expense-accounts-field
(:require [auto-ap.forms :as forms]
[auto-ap.subs :as subs]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead typeahead-entity]]
[auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.utils :refer [bind-field dispatch-event ->$]]
[goog.string :as gstring]
@@ -162,14 +162,14 @@
[:div.control.is-fullwidth
[bind-field
^{:key (:id client)}
[typeahead-v3 {:entities chooseable-expense-accounts
:entity->text (fn [x ]
(str (:numeric-code x) " - " (:name x)))
:disabled disabled
:type "typeahead-v3"
:field [index :account]
:event [::expense-account-changed event expense-accounts max-value]
:subscription expense-accounts}]]]]
[typeahead-entity {:matches chooseable-expense-accounts
:match->text (fn [x ]
(str (:numeric-code x) " - " (:name x)))
:disabled disabled
:type "typeahead-entity"
:field [index :account]
:event [::expense-account-changed event expense-accounts max-value]
:subscription expense-accounts}]]]]
[:div.column.is-narrow
[:p.help "Location"]
[:div.control

View File

@@ -4,7 +4,7 @@
[auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.components.switch-field :refer [switch-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils :refer [active-when dispatch-event dispatch-value-change]]
[bidi.bidi :as bidi]
@@ -59,12 +59,12 @@
[:div
[:p.menu-label "Vendor"]
[:div
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))])
:entity->text :name
:type "typeahead-v3"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]
[typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
:match->text :name
:type "typeahead-entity"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])
:include-keys [:name :id]}]]
[:p.menu-label "Date Range"]
[:div
[date-range-filter

View File

@@ -2,6 +2,7 @@
(:require
[clojure.spec.alpha :as s]
[auto-ap.entities.invoice :as invoice]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field date-picker date->str local-now standard]]
[cljs-time.core :as t]
[re-frame.core :as re-frame]))

View File

@@ -3,106 +3,238 @@
[reagent.ratom :as ra]
[clojure.string :as str]
[clojure.set :as set]
[memsearch.core :as ms]
#_[memsearch.core :as ms]
[downshift :as ds :refer [useCombobox]]
[react]))
(defn typeahead-v3-internal [{:keys [class style disabled entities entity->text entities-by-id entity-index on-change disabled value name auto-focus] :or {disabled false} :as i}]
(println "hello")
(let [[items set-items] (react/useState (map clj->js entities))
state-reducer (fn [state actions-and-changes]
(cond
(= (.-type actions-and-changes) (.-InputChange (.-stateChangeTypes useCombobox)))
(doto (.-changes actions-and-changes) (aset
"selectedItem"
nil))
(and (= (.-type actions-and-changes) (.-InputBlur (.-stateChangeTypes useCombobox)))
(not (.-selectedItem state)))
(doto (.-changes actions-and-changes) (aset
"inputValue"
nil))
:else
(.-changes actions-and-changes)))
[getLabelProps getMenuProps getComboboxProps getToggleButtonProps getInputProps getItemProps isOpen highlightedIndex selectItem selectedItem setInputValue]
(as-> (useCombobox (clj->js {:items items
:defaultHighlightedIndex 0
:defaultSelectedItem value
:onInputValueChange (fn [input]
(if entities-by-id
(->> (ms/text-search (.-inputValue input) entity-index)
(sort-by (fn [[k v]]
(- (:score v))))
(map (fn [[x]]
(entities-by-id x)
))
(take 5)
clj->js
set-items)
(defn get-valid-matches [matches not-found-description not-found-value text]
(let [valid-matches (take 15 (for [[[id t :as match] i] (map vector matches (range))
:when (str/includes? (or (some-> t .toLowerCase) "") (or (some-> text .toLowerCase) ""))]
match))
valid-matches (if (and not-found-description text)
(concat valid-matches [[:not-found (not-found-description text) (not-found-value text)]])
valid-matches)]
valid-matches))
(set-items (map clj->js (take 5 (filter (fn [x] (str/includes? (or (some-> (entity->text x) .toLowerCase) "")
(or (some-> (.-inputValue input) .toLowerCase) "")))
entities))))))
:stateReducer state-reducer
:onSelectedItemChange (fn [z]
(when on-change
(on-change (js->clj (.-selectedItem z) :keywordize-keys true))))})) $
[(.-getLabelProps $)
(.-getMenuProps $)
(.-getComboboxProps $)
(.-getToggleButtonProps $)
(.-getInputProps $)
(.-getItemProps $)
(.-isOpen $)
(.-highlightedIndex $)
(.-selectItem $)
(.-selectedItem $)
(.-setInputValue $)])]
[:<>
[:div.typeahead (assoc (js->clj (getComboboxProps))
:style style)
(if selectedItem
^{:key "typeahead"} [:div.input (assoc (js->clj (getInputProps #js {:disabled (if disabled
"disabled"
"")}))
:on-key-up (fn [e]
(when (= 8 (.-keyCode e))
(selectItem nil)
(setInputValue nil)
(when on-change
(on-change nil))))
:class class
:tab-index "0")
[:div.control
[:div.tags.has-addons
[:span.tag (entity->text (js->clj selectedItem :keywordize-keys true))]
(when name
[:input {:type "hidden" :name name :value (:id (js->clj selectedItem :keywordize-keys true))}])
(when-not disabled
[:a.tag.is-delete {:on-click (fn []
(setInputValue nil)
(selectItem nil)
(when on-change
(on-change nil)))}])]]]
^{:key "typeahead"} [:input.input (js->clj
(getInputProps #js {:disabled (if disabled
"disabled"
"")
:autoFocus (if auto-focus
"autoFocus"
"")}))])
[:div {:class (if (and isOpen (seq items)) "typeahead-menu")}
[:ul (js->clj (getMenuProps))
(if (and isOpen (seq items))
(for [[index item] (map vector (range) (js->clj items :keywordize-keys true))]
^{:key item}
[:li.typeahead-suggestion (assoc (js->clj (getItemProps #js {:item item :index index}))
:class (if (= index highlightedIndex)
"typeahead-highlighted"))
(entity->text item)]))]]]]))
(defn typeahead [{:keys [matches on-change field text-field value class not-found-description
disabled not-found-value auto-focus]}]
(let [text (r/atom (or (second (first (filter #(= (first %) value) matches))) ""))
highlighted (r/atom nil)
selected (r/atom (first (first (filter #(= (first %) value) matches))))
]
(r/create-class
{:reagent-render (fn [{:keys [matches on-change disabled field text-field value class not-found-description]}]
(let [ select (fn [[id text-description text-value]]
(reset! selected id)
(reset! text text-description)
(when on-change
(if (= :not-found id)
(on-change nil text-description text-value)
(on-change id text-description (or text-value text-description)))))
text @text
valid-matches (get-valid-matches matches not-found-description not-found-value text)]
[:div.typeahead
(if disabled
^{:key (str "typeahead" text) } [:input.input {:disabled "disabled" :value text} ]
(if @selected
^{:key "typeahead"} [:div.input {:class class
:tab-index "0"
:on-key-up (fn [e]
(if (= 8 (.-keyCode e))
(do
(select [nil "" nil])
true)
false))}
[:div.control
[:div.tags.has-addons
[:span.tag text]
[:a.tag.is-delete {:on-click (fn []
(select [nil "" nil]))}]]]]
^{:key "typeahead"}
[:input.input {:type "text"
:class class
:value text
:auto-focus auto-focus
:on-blur (fn [e]
(cond @selected
nil
(#{"" nil} text)
nil
@highlighted
(do (select @highlighted)
true)
:else
(do (select [nil ""])
true)))
:on-key-down (fn [e]
(condp = (.-keyCode e)
; up
38 (do
(when-let [new-match (->> valid-matches
(take-while #(not= % @highlighted))
(last))]
(reset! highlighted new-match))
true)
;; dwon
40 (do
(when-let [new-match (->> valid-matches
(drop-while #(not= % @highlighted))
(drop 1)
(first))]
(reset! highlighted new-match))
true)
13 (do (.preventDefault e)
(when @highlighted
(select @highlighted)
false))
true))
:on-change (fn [e]
(let [new-matches (get-valid-matches matches not-found-description not-found-value (.. e -target -value))]
(reset! highlighted (first new-matches)))
(select [nil (.. e -target -value)]))}]))
(cond
(and (seq text)
(not @selected)
(seq valid-matches))
(let [[h] @highlighted]
[:div.typeahead-menu
[:ul
(for [[id t :as match] valid-matches]
^{:key id} [:li.typeahead-suggestion {:class (if (= id h)
"typeahead-highlighted")
:on-mouse-down #(do (select match))} t])]])
:else
nil)]))})))
(defn get-valid-entity-matches [matches not-found-description not-found-value text match->text]
(let [valid-matches (->> (for [[match i] (map vector matches (range))
:let [t (match->text match)
match-index (str/index-of (or (some-> t .toLowerCase) "") (or (some-> text .toLowerCase) ""))]
:when match-index]
[match match-index ])
(sort-by second)
(map first)
(take 10))
valid-matches (if (and not-found-description text)
(concat valid-matches [[:not-found (not-found-description text) (not-found-value text)]])
valid-matches)]
valid-matches))
(defn typeahead-entity [{:keys [matches on-change field value class not-found-description
disabled not-found-value auto-focus name include-keys]}]
(let [text (r/atom (or (second (first (filter #(= (first %) value) matches))) ""))
highlighted (r/atom nil)
]
(r/create-class
{:reagent-render (fn [{:keys [matches on-change disabled match->text field value class not-found-description include-keys style]}]
(let [select (fn [entity]
(when on-change
(if (= :not-found entity)
(on-change nil)
(on-change (cond-> entity
(and include-keys entity) (select-keys include-keys))))))
text-atom text
text (or (when value (match->text value)) @text)
valid-matches (get-valid-entity-matches matches not-found-description not-found-value text match->text)]
[:div.typeahead {:style style}
(if disabled
^{:key (str "typeahead" text) } [:input.input {:disabled "disabled" :value text} ]
(if value
^{:key "typeahead"} [:div.input {:class class
:tab-index "0"
:on-key-up (fn [e]
(if (= 8 (.-keyCode e))
(do
(select nil)
(reset! text-atom nil)
true)
false))}
[:div.control
[:div.tags.has-addons
[:span.tag text]
(when name
[:input {:type "hidden" :name name :value (:id @highlighted)}])
[:a.tag.is-delete {:on-click (fn []
(select nil)
(reset! text-atom nil)
(reset! highlighted nil))}]]]]
^{:key "typeahead"} [:input.input {:type "text"
:class class
:value text
:auto-focus auto-focus
:on-blur (fn [e]
(cond value
nil
(#{"" nil} text)
nil
@highlighted
(do (select @highlighted)
true)
:else
(do (select nil)
(reset! highlighted nil)
(reset! text-atom nil)
true)))
:on-key-down (fn [e]
(condp = (.-keyCode e)
; up
38 (do
(when-let [new-match (->> valid-matches
(take-while #(not= % @highlighted))
(last))]
(reset! highlighted new-match))
true)
;; dwon
40 (do
(when-let [new-match (->> valid-matches
(drop-while #(not= % @highlighted))
(drop 1)
(first))]
(reset! highlighted new-match))
true)
13 (do (.preventDefault e)
(when @highlighted
(select @highlighted)
false))
true))
:on-change (fn [e]
(let [new-matches (get-valid-entity-matches matches not-found-description not-found-value (.. e -target -value) match->text)]
(reset! highlighted (first new-matches)))
(reset! text-atom (.. e -target -value)))}]))
(cond
(and (seq text)
(not value)
(seq valid-matches))
(let [h @highlighted]
[:div.typeahead-menu
[:ul
(for [entity valid-matches]
(let [t (match->text entity)]
^{:key entity} [:li.typeahead-suggestion {:class (if (= entity h)
"typeahead-highlighted")
:on-mouse-over (fn [] (reset! highlighted entity))
:on-mouse-down #(do (select entity))} t]))]])
:else
nil)]))})))
(defn typeahead-v3 [{:keys [class disabled entities entity->text entities-by-id entity-index on-change value ] :as props}]
(println typeahead-v3-internal)
[:div
[:f> typeahead-v3-internal props]])

View File

@@ -2,7 +2,7 @@
(:require [re-frame.core :as re-frame]
[auto-ap.views.utils :refer [dispatch-event horizontal-field bind-field with-user with-is-admin? active-when account->match-text]]
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.components.dropdown :refer [drop-down drop-down-contents]]
[auto-ap.events :as events]
[clj-fuzzy.metrics :refer [jaccard jaro-winkler]]
@@ -154,12 +154,12 @@
[:div.columns
[:div.column
[bind-field
[typeahead-v3 {:entities clients
:entity->text :name
:type "typeahead-v3"
:field [override-key i]
:event change-event
:subscription data}]]]
[typeahead-entity {:matches clients
:match->text :name
:type "typeahead-entity"
:field [override-key i]
:event change-event
:subscription data}]]]
[:div.column.is-1
[:a.button {:on-click (dispatch-event [::removed-override override-key i])} [:span.icon [:span.icon-remove]]]]]))])))
@@ -186,12 +186,12 @@
[:div.columns
[:div.column
[bind-field
[typeahead-v3 {:entities clients
:entity->text :name
:type "typeahead-v3"
:field [override-key i :client]
:event change-event
:subscription data}]]]
[typeahead-entity {:matches clients
:match->text :name
:type "typeahead-entity"
:field [override-key i :client]
:event change-event
:subscription data}]]]
[:div.column
[bind-field
(template
@@ -215,12 +215,12 @@
[:div.columns
[:div.column
[bind-field
[typeahead-v3 {:entities clients
:entity->text :name
:type "typeahead-v3"
:field [override-key i :client]
:event change-event
:subscription data}]]]
[typeahead-entity {:matches clients
:match->text :name
:type "typeahead-entity"
:field [override-key i :client]
:event change-event
:subscription data}]]]
[:div.column
[bind-field
(template
@@ -306,12 +306,12 @@
:override-key :account-overrides}
(fn [field client]
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/accounts client])
:entity->text account->match-text
:field field
:type "typeahead-v3"
:event change-event
:subscription data}])]
[typeahead-entity {:matches @(re-frame/subscribe [::subs/accounts client])
:match->text account->match-text
:field field
:type "typeahead-entity"
:event change-event
:subscription data}])]
[:h2.subtitle "Address"]
[address-field {:field [:address]

View File

@@ -2,6 +2,18 @@
(:require
[clojure.spec.alpha :as s]
[auto-ap.entities.invoice :as invoice]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field]]))
(defn vendor-filter [{:keys [value on-change-event vendors]}]
[:div.field
[:div.control
[bind-field
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) vendors)
:type "typeahead"
:auto-focus true
:field [:vendor-id]
:text-field [:vendor-name]
:event on-change-event
:spec (s/nilable ::invoice/vendor-id)
:subscription value}]]]])

View File

@@ -3,7 +3,7 @@
[auto-ap.forms :as forms]
[auto-ap.subs :as subs]
[auto-ap.views.components.layouts :refer [side-bar]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.utils :refer [dispatch-event multi-field]]
[clojure.spec.alpha :as s]
[clojure.string :as str]
@@ -138,11 +138,11 @@
(field "Customizations"
[multi-field {:type "multi-field"
:field [:client-overrides]
:template [[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
:style {:width "20em"}
:entity->text :name
:type "typeahead-v3"
:field [:client]}]
:template [[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
:style {:width "20em"}
:match->text :name
:type "typeahead"
:field [:client]}]
[:input.input {:type "text"
:style {:width "20em"}
:placeholder "Bubblegum"

View File

@@ -2,7 +2,8 @@
(:require
[re-frame.core :as re-frame]
[auto-ap.subs :as subs]
[auto-ap.views.utils :refer [active-when dispatch-value-change]]))
[auto-ap.views.utils :refer [active-when dispatch-value-change]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]))
(re-frame/reg-sub

View File

@@ -4,7 +4,7 @@
[auto-ap.subs :as subs]
[auto-ap.events :as events]
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.components.layouts :refer [side-bar]]
[auto-ap.views.utils
:refer
@@ -377,10 +377,10 @@
:type "text"
:field [:bank-accounts sort-order :yodlee-account-id]}]]
[field "Yodlee Account (new)"
[typeahead-v3 {:entities @(re-frame/subscribe [::yodlee-accounts (:id new-client)])
:entity->text (fn [m] (str (:name m) " - " (:number m)))
:type "typeahead-v3"
:field [:bank-accounts sort-order :yodlee-account]}]]])
[typeahead-entity {:matches @(re-frame/subscribe [::yodlee-accounts (:id new-client)])
:match->text (fn [m] (str (:name m) " - " (:number m)))
:type "typeahead"
:field [:bank-accounts sort-order :yodlee-account]}]]])
(when (#{:credit ":credit"} type )
[:div
@@ -405,10 +405,10 @@
:type "text"
:field [:bank-accounts sort-order :yodlee-account-id]}]]
[field "Yodlee Account (new)"
[typeahead-v3 {:entities @(re-frame/subscribe [::yodlee-accounts (:id new-client)])
:entity->text (fn [m] (str (:name m) " - " (:number m)))
:type "typeahead-v3"
:field [:bank-accounts sort-order :yodlee-account]}]]])
[typeahead-entity {:matches @(re-frame/subscribe [::yodlee-accounts (:id new-client)])
:match->text (fn [m] (str (:name m) " - " (:number m)))
:type "typeahead"
:field [:bank-accounts sort-order :yodlee-account]}]]])
[:div.field
[:label.label "Locations"]
[:div.control

View File

@@ -4,7 +4,7 @@
[auto-ap.subs :as subs]
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
[auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.utils :refer [bind-field dispatch-event]]
[re-frame.core :as re-frame]))
@@ -77,7 +77,7 @@
:venia/queries (map (fn [v ]
{:query/data [:upsert-vendor
{:vendor {:name v :default-account-id (-> db ::expense-accounts (get v) :default-account-id :id)}}
{:vendor {:name v :default-account-id (-> db ::expense-accounts (get v) :default-account-id)}}
[:id :name]]})
(get-in db [::excel-import :create-vendors]))}
@@ -138,12 +138,11 @@
[:p.control
[bind-field
[typeahead-v3 {:entities chooseable-expense-accounts
:entity->text (fn [x ] (str (:numeric-code x) " - " (:name x)))
:type "typeahead-v3"
:field [v :default-account-id]
:event change-event
:subscription data}]]]])])]
[typeahead {:matches (map (fn [x] [(:id x) (:name x)]) chooseable-expense-accounts)
:type "typeahead"
:field [v :default-account-id]
:event change-event
:subscription data}]]]])])]
[:div
[:button.button.is-pulled-right
{:on-click (dispatch-event [::create-vendors])

View File

@@ -8,7 +8,7 @@
[auto-ap.views.components.dropdown :refer [drop-down]]
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]]
[auto-ap.views.components.layouts :as layouts]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.admin.rules.common :refer [default-read]]
[auto-ap.views.pages.admin.rules.results-modal :as results-modal]
[auto-ap.views.utils :refer [date->str date-picker dispatch-event standard with-user]]
@@ -180,8 +180,7 @@
[[:accounts] (expense-accounts-field/default-account (:accounts data)
@(re-frame/subscribe [::subs/vendor-default-account (:vendor data) value])
(:total data)
[])
[:bank-account] nil]
[])]
:else
[]))))
@@ -246,29 +245,25 @@
(field "Client"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
:auto-focus true
:entity->text :name
:type "typeahead-v3"
:field [:client]
:spec ::entity/client}])
[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
:auto-focus true
:match->text :name
:type "typeahead-entity"
:field [:client]
:spec ::entity/client}])
(with-meta
(field "Bank account"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/real-bank-accounts-for-client (:client data)])
:entity->text :name
:type "typeahead-v3"
:field [:bank-account]
:spec ::entity/bank-account}])
;; TODO this forces unmounting when client changes, since it is an "uncontorlled" input
{:key (str "client-" (:id (:client data)))})
(field "Bank account"
[typeahead-entity {:matches @(re-frame/subscribe [::subs/real-bank-accounts-for-client (:client data)])
:match->text :name
:type "typeahead-entity"
:field [:bank-account]
:spec ::entity/bank-account}])
(field "Yodlee Merchant"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/yodlee-merchants])
:entity->text #(str (:name %) " - " (:yodlee-id %))
:type "typeahead-v3"
:field [:yodlee-merchant]}])
[typeahead-entity {:matches @(re-frame/subscribe [::subs/yodlee-merchants])
:match->text #(str (:name %) " - " (:yodlee-id %))
:type "typeahead-entity"
:field [:yodlee-merchant]}])
(field [:span "Description (" [:a {:href "https://regex101.com" :target "_new"} "regex tester"] ")" ]
[:input.input {:type "text"
@@ -320,12 +315,11 @@
[:h2.title.is-4 "Outcomes"]
(field "Assign Vendor"
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:entity->text :name
:type "typeahead-v3"
:field [:vendor]
:spec ::entity/vendor}])
[typeahead-entity {:matches @(re-frame/subscribe [::subs/all-vendors])
:match->text :name
:type "typeahead-entity"
:field [:vendor]
:spec ::entity/vendor}])
(field nil
[expense-accounts-field {:type "expense-accounts"

View File

@@ -2,7 +2,7 @@
(:require
[re-frame.core :as re-frame]
[auto-ap.subs :as subs]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.data-page :as data-page]))
@@ -10,10 +10,10 @@
[:div
[:p.menu-label "Vendor"]
[:div
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))])
:entity->text :name
:type "typeahead-v3"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]])
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
:match->text :name
:include-keys [:name :id]
:type "typeahead-entity"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]])

View File

@@ -17,6 +17,8 @@
[auto-ap.views.utils :refer [login-url dispatch-value-change dispatch-event bind-field horizontal-field action-cell-width]]
[auto-ap.views.pages.admin.vendors.table :as table]
[auto-ap.views.pages.admin.vendors.merge-dialog :as merge-dialog]
[auto-ap.views.components.typeahead :refer [typeahead]]
[cljs.reader :as edn]
[auto-ap.routes :as routes]
[bidi.bidi :as bidi]

View File

@@ -3,7 +3,7 @@
[auto-ap.status :as status]
[auto-ap.subs :as subs]
[auto-ap.views.components.modal :as modal]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.utils :refer [dispatch-event]]
[re-frame.core :as re-frame]))
@@ -28,22 +28,20 @@
(form-inline {}
[:<>
(field "Form Vendor (will be deleted)"
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:type "typeahead-v3"
:auto-focus true
:entity->text (fn [x]
(str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") )
:field [:from]}])
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:type "typeahead-entity"
:auto-focus true
:match->text (fn [x]
(str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") )
:field [:from]}])
(field "To Vendor"
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:type "typeahead-v3"
:entity->text (fn [x]
(str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") )
:field [:to]}])])))
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:type "typeahead-entity"
:match->text (fn [x]
(str (:name x) " (" (reduce + 0 (map :count (:usage x))) " usages)") )
:field [:to]}])])))
(re-frame/reg-event-fx
::show

View File

@@ -2,7 +2,8 @@
(:require
[re-frame.core :as re-frame]
[auto-ap.subs :as subs]
[auto-ap.views.utils :refer [active-when dispatch-value-change]]))
[auto-ap.views.utils :refer [active-when dispatch-value-change]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]))
(re-frame/reg-sub
::specific-filters

View File

@@ -3,20 +3,16 @@
[auto-ap.subs :as subs]
[auto-ap.views.components.grid :as grid]
[auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.utils
:refer
[->$ date->str days-until dispatch-event local-now standard]]
[bidi.bidi :as bidi]
[cljs-time.coerce :as coerce]
[cljs-time.core :as t]
[clojure.string :as str]
[pushy.core :as pushy]
[re-frame.core :as re-frame]
[recharts]
[downshift :as ds :refer [useCombobox]]
[reagent.core :as r]
[react]))
[reagent.core :as r]))
(def pie-chart (r/adapt-react-class recharts/PieChart))
(def pie (r/adapt-react-class recharts/Pie))
@@ -300,16 +296,9 @@
(defn home-content []
(let [client-id (-> @(re-frame/subscribe [::subs/client]) :id)
vendors-by-id @(re-frame/subscribe [::subs/vendors-by-id])
vendors-index @(re-frame/subscribe [::subs/searchable-vendors-index])
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id])
accounts-index @(re-frame/subscribe [::subs/accounts-index])
chart-options @(re-frame/subscribe [::chart-options])]
^{:key client-id}
[side-bar-layout {:side-bar [:div
]
[side-bar-layout {:side-bar [:div]
:main [:div [:h1.title "Home"]
[:h1.title.is-4 "Top expense categories"]
(let [expense-categories @(re-frame/subscribe [::top-expense-categories])]

View File

@@ -10,7 +10,7 @@
[auto-ap.views.utils :refer [dispatch-event bind-field with-user]]
[auto-ap.utils :refer [by]]
[auto-ap.entities.vendors :as vendor]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
[cljs.reader :as edn]
[clojure.string :as str]
@@ -60,14 +60,13 @@
[:p.control
[:a.button.is-static "Force vendor"]]
[:div.control {:style {:width "400px"}}
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:entity->text :name
:name "vendor"
:type "typeahead-v3"
:on-change (fn [v]
(reset! vendor v))
:value @vendor}]]
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:match->text :name
:name "vendor"
:type "typeahead"
:on-change (fn [v]
(reset! vendor v))
:value @vendor}]]
]
[:div.tile.notification
[:div.has-text-centered {:style {:padding "80px 0px" :width "100%"}}

View File

@@ -16,7 +16,7 @@
[auto-ap.views.components.modal :as modal]
[auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.components.switch-field :refer [switch-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
[auto-ap.views.utils
:refer
@@ -348,22 +348,22 @@
(when-not @(re-frame/subscribe [::subs/client])
(field [:span "Client"
[:span.has-text-danger " *"]]
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
:entity->text :name
:type "typeahead-v3"
[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
:match->text :name
:type "typeahead"
:auto-focus (if @(re-frame/subscribe [::subs/client]) false true)
:field [:client]
:disabled exists?
:spec ::invoice/client}]))
(field [:span "Vendor"
[:span.has-text-danger " *"]]
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:entity->text :name
:type "typeahead-v3"
:disabled exists?
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
:field [:vendor]}])
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:match->text :name
:type "typeahead"
:disabled exists?
:auto-focus (if @(re-frame/subscribe [::subs/client]) true false)
:field [:vendor]}])
(field [:span "Date"
[:span.has-text-danger " *"]]

View File

@@ -4,7 +4,7 @@
[auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.components.bank-account-filter :refer [bank-account-filter]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils :refer [active-when dispatch-value-change]]
[bidi.bidi :as bidi]
@@ -13,8 +13,7 @@
(defn ledger-side-bar [{:keys [data-page]}]
(let [ap @(re-frame/subscribe [::subs/active-page])
user @(re-frame/subscribe [::subs/user])
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id])
accounts-index @(re-frame/subscribe [::subs/accounts-index])]
accounts @(re-frame/subscribe [::subs/accounts])]
[:div
[:ul.menu-list
[:li.menu-item
@@ -57,21 +56,21 @@
[:p.menu-label "Financial Account"]
[:div
[typeahead-v3 {:entities-by-id accounts-by-id
:entity-index accounts-index
:entity->text (fn [x ] (str (:numeric-code x) " - " (:name x)))
:type "typeahead-v3"
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :account (some-> % (select-keys [:name :id :numeric-code]))])
:value @(re-frame/subscribe [::data-page/filter data-page :account])}]]
[typeahead-entity {:matches accounts
:match->text (fn [x ] (str (:numeric-code x) " - " (:name x)))
:include-keys [:name :id :numeric-code]
:type "typeahead-entity"
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :account %])
:value @(re-frame/subscribe [::data-page/filter data-page :account])}]]
[:p.menu-label "Vendor"]
[:div
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))])
:entity->text :name
:type "typeahead-v3"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]
[typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
:include-keys [:name :id]
:match->text :name
:type "typeahead-entity"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]

View File

@@ -9,6 +9,7 @@
[auto-ap.views.components.sorter :refer [sorted-column]]
[auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.typeahead :refer [typeahead]]
[auto-ap.views.components.paginator :refer [paginator]]
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
[auto-ap.events :as events]

View File

@@ -2,7 +2,7 @@
(:require [auto-ap.subs :as subs]
[auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils :refer [dispatch-event dispatch-value-change]]
[re-frame.core :as re-frame]))
@@ -14,13 +14,12 @@
[:div
[:p.menu-label "Vendor"]
[:div
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))])
:include-keys [:name :id]
:entity->text :name
:type "typeahead-v3"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]
[typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
:include-keys [:name :id]
:match->text :name
:type "typeahead-entity"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]
[:p.menu-label "Date Range"]
[:div

View File

@@ -8,7 +8,7 @@
[auto-ap.views.components.expense-accounts-field :as expense-accounts-field :refer [expense-accounts-field recalculate-amounts]]
[auto-ap.views.components.layouts :as layouts]
[auto-ap.views.components.money-field :refer [money-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.status :as status]
[auto-ap.views.utils :refer [date->str date-picker dispatch-event standard with-user]]
[cljs-time.core :as c]
@@ -42,11 +42,11 @@
(when-not @(re-frame/subscribe [::subs/client])
(field [:span "Client"
[:span.has-text-danger " *"]]
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/clients])
:entity->text :name
:type "typeahead-v3"
:field [:client]
:disabled true}]))
[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
:match->text :name
:type "typeahead"
:field [:client]
:disabled true}]))
(field "Date"

View File

@@ -2,9 +2,11 @@
(:require [auto-ap.routes :as routes]
[auto-ap.subs :as subs]
[auto-ap.views.utils :refer [active-when dispatch-value-change]]
[auto-ap.views.components.vendor-filter :refer [vendor-filter]]
[auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.components.bank-account-filter :refer [bank-account-filter]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[bidi.bidi :as bidi]
[re-frame.core :as re-frame]
[auto-ap.views.pages.data-page :as data-page]))

View File

@@ -9,7 +9,7 @@
:refer
[expense-accounts-field]]
[auto-ap.views.components.layouts :as layouts]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.transactions.common :refer [transaction-read]]
[auto-ap.views.utils
:refer
@@ -406,14 +406,13 @@
[tab {:title "Details" :key :details}
[:div
(field "Vendor"
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:entity->text :name
:type "typeahead-v3"
:auto-focus true
:field [:vendor]
:disabled (or (boolean (:payment data))
should-disable-for-client?)}])
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:match->text :name
:type "typeahead-entity"
:auto-focus true
:field [:vendor]
:disabled (or (boolean (:payment data))
should-disable-for-client?)}])
(field nil
[expense-accounts-field
{:type "expense-accounts"
@@ -438,10 +437,10 @@
:disabled should-disable-for-client?}])
(field "Forecasted-transaction"
[typeahead-v3 {:entities @(re-frame/subscribe [::subs/forecasted-transactions-for-client (:id (:client data))])
:entity->text :identifier
:type "typeahead-v3"
:field [:forecast-match]}])
[typeahead-entity {:matches @(re-frame/subscribe [::subs/forecasted-transactions-for-client (:id (:client data))])
:match->text :identifier
:type "typeahead-entity"
:field [:forecast-match]}])
(error-notification)
(when-not should-disable-for-client?
(submit-button "Save"))]]]]))])

View File

@@ -7,7 +7,7 @@
[auto-ap.views.components.date-range-filter :refer [date-range-filter]]
[auto-ap.views.components.number-filter :refer [number-filter]]
[auto-ap.views.components.switch-field :refer [switch-field]]
[auto-ap.views.components.typeahead :refer [typeahead-v3]]
[auto-ap.views.components.typeahead :refer [typeahead-entity]]
[auto-ap.views.pages.data-page :as data-page]
[auto-ap.views.utils :refer [active-when dispatch-event dispatch-value-change ->$ account->match-text]]
[bidi.bidi :as bidi]
@@ -17,8 +17,7 @@
(let [ap @(re-frame/subscribe [::subs/active-page])
user @(re-frame/subscribe [::subs/user])
accounts @(re-frame/subscribe [::subs/accounts-by-id])
account-index @(re-frame/subscribe [::subs/accounts-index])
accounts @(re-frame/subscribe [::subs/accounts])
]
[:div
[:div [:p.menu-label "Type"]
@@ -65,20 +64,20 @@
[:p.menu-label "Financial Account"]
[:div
[typeahead-v3 {:entities-by-id accounts
:entity-index account-index
:entity->text account->match-text
:type "typeahead-v3"
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :account (some-> % (select-keys [:name :id :numeric-code]))])
:value @(re-frame/subscribe [::data-page/filter data-page :account])}]]
[typeahead-entity {:matches accounts
:match->text account->match-text
:include-keys [:name :id :numeric-code]
:type "typeahead-entity"
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :account %])
:value @(re-frame/subscribe [::data-page/filter data-page :account])}]]
[:p.menu-label "Vendor"]
[:div
[typeahead-v3 {:entities-by-id @(re-frame/subscribe [::subs/vendors-by-id])
:entity-index @(re-frame/subscribe [::subs/searchable-vendors-index])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor (some-> % (select-keys [:name :id]))])
:entity->text :name
:type "typeahead-v3"
[typeahead-entity {:matches @(re-frame/subscribe [::subs/searchable-vendors])
:on-change #(re-frame/dispatch [::data-page/filter-changed data-page :vendor %])
:include-keys [:name :id]
:match->text :name
:type "typeahead-entity"
:value @(re-frame/subscribe [::data-page/filter data-page :vendor])}]]

View File

@@ -100,9 +100,6 @@
e
(date->str (time/from-default-time-zone (c/from-date e)) standard))))))
;; TODO inline on-changes causes each field to be rerendered each time. When we fix this
;; let's make sure that we find away not to trigger a re-render for every component any time any form field
;; changes
(defmulti do-bind (fn [a {:keys [type] :as x}]
type))
@@ -280,21 +277,6 @@
keys (dissoc keys :field :subscription :event :spec)]
(into [dom keys] (with-keys rest))))
(defmethod do-bind "typeahead-v3" [dom {:keys [field event text-event subscription class spec match->text] :as keys} & rest]
(let [field (if (keyword? field) [field] field)
event (if (keyword? event) [event] event)
keys (assoc keys
:on-change (fn [selected]
(re-frame/dispatch (conj (conj event field) selected))
#_(when text-field
(re-frame/dispatch (conj (conj (or text-event event) text-field) text-value))))
:value (get-in subscription field)
:class (str class
(when (and spec (not (s/valid? spec (get-in subscription field))))
" is-danger")))
keys (dissoc keys :field :subscription :event :spec)]
(into [dom keys] (with-keys rest))))
(defmethod do-bind "date" [dom {:keys [field event subscription class spec] :as keys} & rest]
(let [field (if (keyword? field) [field] field)
event (if (keyword? event) [event] event)