diff --git a/src/cljs/auto_ap/views/components/grid.cljs b/src/cljs/auto_ap/views/components/grid.cljs index 15c62952..81ed2988 100644 --- a/src/cljs/auto_ap/views/components/grid.cljs +++ b/src/cljs/auto_ap/views/components/grid.cljs @@ -107,7 +107,6 @@ [:> Consumer {} (fn [consume] (let [{:strs [on-params-change params] :as consume} (js->clj consume)] - (println "PARAMS" params) (r/as-element (into [:div {:style {:margin-bottom "1rem"}} [:div.level @@ -139,7 +138,7 @@ :class class}] (r/children (r/current-component)))) -(defn row [{:keys [class id checkable?]}] +(defn row [{:keys [class id checkable? entity] }] (let [children (r/children (r/current-component))] [:> Consumer {} (fn [consume] @@ -153,9 +152,15 @@ "") :on-change (fn [x e] (let [checked (or checked #{})] - (if (get checked id) - (on-check-changed (disj checked id)) - (on-check-changed (conj checked id)))))} + ;; TODO only map once everything is moved over to data-page + (if (map? checked) + (if (get checked id) + (on-check-changed (dissoc checked id)) + (on-check-changed (assoc checked id entity))) + + (if (get checked id) + (on-check-changed (disj checked id)) + (on-check-changed (conj checked id))))))} (boolean? checkable?) (assoc :disabled (not checkable?))) ]])) (map r/as-element children))))])) diff --git a/src/cljs/auto_ap/views/components/invoice_table.cljs b/src/cljs/auto_ap/views/components/invoice_table.cljs index 7cb5668b..bb6cb241 100644 --- a/src/cljs/auto_ap/views/components/invoice_table.cljs +++ b/src/cljs/auto_ap/views/components/invoice_table.cljs @@ -95,7 +95,7 @@ (let [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor checkable?] :as i} invoice accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client]) account->name #(:name (accounts-by-id (:id %)))] - [grid/row {:class (:class i) :id id :checkable? checkable?} + [grid/row {:class (:class i) :id id :checkable? checkable? :entity invoice} (when-not selected-client [grid/cell {} (if-let [client-override (:client overrides)] diff --git a/src/cljs/auto_ap/views/pages/data_page.cljs b/src/cljs/auto_ap/views/pages/data_page.cljs index 4cbd2ece..cb6d9746 100644 --- a/src/cljs/auto_ap/views/pages/data_page.cljs +++ b/src/cljs/auto_ap/views/pages/data_page.cljs @@ -7,7 +7,7 @@ (re-frame/reg-sub ::checked (fn [db [_ id]] - (get-in db [::checked id] #{}))) + (get-in db [::checked id] {}))) (re-frame/reg-event-db ::toggle-check @@ -20,13 +20,17 @@ (update-in db [::checked id] (fn [checked] - (let [checked (or checked #{})] - (disj checked to-remove)))))) + (let [checked (or checked {})] + (dissoc checked to-remove)))))) + +(re-frame/reg-sub + ::checked-set + (fn [db [_ id]] + (keys (get-in db [::checked id] {})))) (re-frame/reg-event-db ::reset-checked (fn [db [_ id]] - (update db ::checked dissoc id))) (re-frame/reg-event-db @@ -82,14 +86,16 @@ [(re-frame/subscribe [::data id]) (re-frame/subscribe [::status/single [::page id]]) (re-frame/subscribe [::checked id]) + (re-frame/subscribe [::checked-set id]) (re-frame/subscribe [::params id]) (re-frame/subscribe [::table-params id]) (re-frame/subscribe [::filters id])]) - (fn [[data status checked params table-params filters] [_ id]] + (fn [[data status checked checked-set params table-params filters] [_ id]] {:id id :data data :status status :checked checked + :checked-set checked-set :params params :filters filters :table-params table-params})) diff --git a/src/cljs/auto_ap/views/pages/import_invoices.cljs b/src/cljs/auto_ap/views/pages/import_invoices.cljs index 12c36491..2c0699f2 100644 --- a/src/cljs/auto_ap/views/pages/import_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/import_invoices.cljs @@ -82,7 +82,7 @@ ::invalidated (fn [{:keys [db]} [_ params]] {:dispatch-n [[::params-change @(re-frame/subscribe [::data-page/params :import-invoices])] - [::data-page/reset-checked :import-invoices]/] + [::data-page/reset-checked :import-invoices]] :db (update db ::batch inc)} )) @@ -122,7 +122,7 @@ (re-frame/reg-event-fx ::received (fn [_ [_ data]] - {:dispatch [::data-page/toggle-check :import-invoices (set (map :id data))]})) + {:dispatch [::data-page/toggle-check :import-invoices (by :id data)]})) (re-frame/reg-event-fx ::reject-invoices-clicked @@ -203,7 +203,7 @@ [:div {:class "card-header"} [:span {:class "card-header-title"} "Found Invoices"]] [:div {:class "card-content"} - [approve-reject-button (:checked page)] + [approve-reject-button (:checked-set page)] (if (seq (:data (:data page))) [invoice-table {:id :approved :data-page :import-invoices diff --git a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs index 7b3ce02b..eed0ae72 100644 --- a/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs +++ b/src/cljs/auto_ap/views/pages/unpaid_invoices.cljs @@ -75,14 +75,6 @@ [::checks-printed invoices pdf-url])}]})) -(re-frame/reg-sub - ::checked-invoices - :<- [::data-page/data :invoices] - :<- [::data-page/checked :invoices] - (fn [[data checked]] - (filter (comp #(get checked %) :id) (:data data)))) - - (defn print-checks-query [invoice-payments bank-account-id type client-id] {:venia/operation {:operation/type :mutation :operation/name "PrintChecks"} @@ -104,7 +96,7 @@ :query-obj (print-checks-query (map (fn [{:keys [id outstanding-balance] }] {:invoice-id id :amount outstanding-balance}) - @(re-frame/subscribe [::checked-invoices])) + (vals @(re-frame/subscribe [::data-page/checked :invoices]))) bank-account-id type (:client db)) @@ -140,7 +132,7 @@ (defn pay-button [] (let [current-client @(re-frame/subscribe [::subs/client]) - checked-invoices @(re-frame/subscribe [::checked-invoices])] + checked-invoices (vals @(re-frame/subscribe [::data-page/checked :invoices]))] [:div [:div.is-pulled-right [:div.buttons