From 523a96f51b546e24433e6aa122a4cb5347bef68c Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 27 Jul 2018 08:29:01 -0700 Subject: [PATCH] fixing problems with slowness and fixing error with wrong locations. --- .../1532704782-DOWN-fix-iguanas-locations.sql | 1 + .../1532704782-UP-fix-iguanas-locations.sql | 2 ++ .../auto_ap/views/components/typeahead.cljs | 31 ++++++++++--------- .../auto_ap/views/pages/unpaid_invoices.cljs | 18 ++++++----- 4 files changed, 29 insertions(+), 23 deletions(-) create mode 100644 migrator/migrations/1532704782-DOWN-fix-iguanas-locations.sql create mode 100644 migrator/migrations/1532704782-UP-fix-iguanas-locations.sql diff --git a/migrator/migrations/1532704782-DOWN-fix-iguanas-locations.sql b/migrator/migrations/1532704782-DOWN-fix-iguanas-locations.sql new file mode 100644 index 00000000..fe4f1f3e --- /dev/null +++ b/migrator/migrations/1532704782-DOWN-fix-iguanas-locations.sql @@ -0,0 +1 @@ +-- 1532704782 DOWN fix-iguanas-locations \ No newline at end of file diff --git a/migrator/migrations/1532704782-UP-fix-iguanas-locations.sql b/migrator/migrations/1532704782-UP-fix-iguanas-locations.sql new file mode 100644 index 00000000..02d6b19c --- /dev/null +++ b/migrator/migrations/1532704782-UP-fix-iguanas-locations.sql @@ -0,0 +1,2 @@ +-- 1532704782 UP fix-iguanas-locations +update companies set data = '{:locations ["DT" "EG" "SC" "SG" "CB" "BH"] :bank-accounts [{:number "000158443280" :id 1 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1120 BofA Exp and Main - 3280" :yodlee-account-id 16279663} {:number "" :id 2 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1122 BofA Squirrel - 5255" :yodlee-account-id 16279666} {:number "000158743279" :id 3 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1121 BofA Tax & SLO - 3279" :yodlee-account-id 16279664} {:number "" :id 4 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1123 BofA Paychecks - 5250" :yodlee-account-id 16279665} {:number "" :id 5 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1125 BofA EG Exp - 5598" :yodlee-account-id 16279667} {:number "" :id 6 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1126 BofA SC Exp - 5318" :yodlee-account-id 16279668} {:number "" :id 7 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1127 BofA SG Exp - 8407" :yodlee-account-id 16279669} {:number "" :id 8 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1124 BofA DT Exp - 8279" :yodlee-account-id 16279670} {:number "" :id 9 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1128 BofA CB Exp - 2495" :yodlee-account-id 16279671} {:number "" :id 10 :check-number 10000 :bank-name "Bank of America" :bank-code "11-35/1210" :routing "121000358" :name "A1129 BofA BH Exp - 1665" :yodlee-account-id 16279672}]}' where id = 39; diff --git a/src/cljs/auto_ap/views/components/typeahead.cljs b/src/cljs/auto_ap/views/components/typeahead.cljs index 6167b4c1..095bec52 100644 --- a/src/cljs/auto_ap/views/components/typeahead.cljs +++ b/src/cljs/auto_ap/views/components/typeahead.cljs @@ -18,11 +18,12 @@ ] (r/create-class {:reagent-render (fn [{:keys [matches on-change field text-field value class not-found-description]}] - (let [valid-matches (take 5 (for [[[id t :as match] i] (map vector matches (range)) - :when (str/includes? (.toLowerCase t) (.toLowerCase @text))] + (let [text @text + valid-matches (take 5 (for [[[id t :as match] i] (map vector matches (range)) + :when (str/includes? (.toLowerCase t) (.toLowerCase text))] match)) - valid-matches (if (and not-found-description @text) - (concat valid-matches [[:not-found (not-found-description @text) (not-found-value @text)]]) + valid-matches (if (and not-found-description text) + (concat valid-matches [[:not-found (not-found-description text) (not-found-value text)]]) valid-matches)] [:div.typeahead @@ -37,19 +38,19 @@ false))} [:div.control [:div.tags.has-addons - [:span.tag @text] + [:span.tag text] [:a.tag.is-delete {:on-click (fn [] (select [nil "" nil]))}]]]] [:input.input {:type "text" :class class :field field - :value @text + :value text :auto-focus auto-focus :on-blur (fn [e] (cond @selected nil - (#{"" nil} @text) + (#{"" nil} text) nil (seq valid-matches) @@ -71,16 +72,16 @@ (select [nil (.. e -target -value)]))} ]) (cond - (and (seq @text) + (and (seq text) (not @selected) (seq valid-matches)) - [:div.typeahead-menu - [:ul - (for [[id t :as match] valid-matches] - - [:li.typeahead-suggestion {:class (if (= id @highlighted) - "typeahead-highlighted") - :on-mouse-down #(do (select match))} t])]] + (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])]]) diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index ddb4b0e6..096210fc 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -429,6 +429,7 @@ (let [{{:keys [expense-accounts total ] :or {expense-accounts [] total 0} {:keys [locations]} :company} :invoice :as data} @(re-frame/subscribe [::change-expense-accounts]) multi-location? (> (count locations) 1) change-event [::events/change-form [::change-expense-accounts]] + chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts]) expense-accounts-total (->> expense-accounts (map :amount) (map js/parseFloat) @@ -454,15 +455,16 @@ [:th {:style {:width "5em"}}]]] [:tbody (for [[expense-account index] (map vector expense-accounts (range))] + ^{:key index} [:tr [:td.expandable [:div.control - [bind-field - [typeahead {:matches (map (fn [x] [(:id x) (:name x)]) @(re-frame/subscribe [::subs/chooseable-expense-accounts])) - :type "typeahead" - :field [:invoice :expense-accounts index :expense-account-id] - :event change-event - :spec ::invoice/vendor-id - :subscription data}]]]] + [bind-field + [typeahead {:matches (map (fn [x] [(:id x) (:name x)]) chooseable-expense-accounts) + :type "typeahead" + :field [:invoice :expense-accounts index :expense-account-id] + :event change-event + :spec ::invoice/vendor-id + :subscription data}]]]] (when multi-location? [:td @@ -476,7 +478,7 @@ :spec (set locations) :event change-event :subscription data} - (map (fn [l] [:option {:value l} l]) locations)]]])]) + (map (fn [l] ^{:key l} [:option {:value l} l]) locations)]]])]) [:td [:div.control