Add vendor pre-population for bulk code and individual edit forms
- Add vendor-changed HTMX handlers for both bulk code and individual edit - Pre-populate default account at 100% when vendor is selected and no accounts exist - Fix render-accounts-section to render from step-params correctly - Change bulk code vendor-changed from hx-get to hx-post to include form data - Add routes for vendor-changed endpoints - Update e2e tests to cover vendor pre-population - Run lein cljfmt fix across codebase
This commit is contained in:
@@ -33,36 +33,34 @@
|
||||
:yodlee-provider-account/client [:client/code]}])
|
||||
|
||||
(def query-schema (mc/schema
|
||||
[:maybe
|
||||
(into [:map {}
|
||||
[:client-id {:optional true} [:maybe entity-id]] ]
|
||||
default-grid-fields-schema)]))
|
||||
[:maybe
|
||||
(into [:map {}
|
||||
[:client-id {:optional true} [:maybe entity-id]]]
|
||||
default-grid-fields-schema)]))
|
||||
|
||||
(defn fetch-ids [db request]
|
||||
(let [query-params (:query-params request)
|
||||
query (cond-> {:query {:find []
|
||||
:in ['$ '[?xx ...]]
|
||||
:where ['[?e :yodlee-provider-account/id]
|
||||
'[?e :yodlee-provider-account/client ?xx]]}
|
||||
:args [db (:trimmed-clients request)]}
|
||||
:in ['$ '[?xx ...]]
|
||||
:where ['[?e :yodlee-provider-account/id]
|
||||
'[?e :yodlee-provider-account/client ?xx]]}
|
||||
:args [db (:trimmed-clients request)]}
|
||||
|
||||
|
||||
(:sort query-params) (add-sorter-fields {"status" ['[?e :yodlee-provider-account/status ?sort-status]]
|
||||
"client" ['[?e :yodlee-provider-account/client ?c]
|
||||
'[?c :client/code ?sort-client]]
|
||||
"provider-account" ['[?e :yodlee-provider-account/id ?sort-provider-account]]
|
||||
"last-updated" ['[?e :yodlee-provider-account/last-updated ?sort-last-updated]]}
|
||||
query-params)
|
||||
true
|
||||
(merge-query {:query {:find ['?e ]
|
||||
:where ['[?e :yodlee-provider-account/id]]}}))]
|
||||
(:sort query-params) (add-sorter-fields {"status" ['[?e :yodlee-provider-account/status ?sort-status]]
|
||||
"client" ['[?e :yodlee-provider-account/client ?c]
|
||||
'[?c :client/code ?sort-client]]
|
||||
"provider-account" ['[?e :yodlee-provider-account/id ?sort-provider-account]]
|
||||
"last-updated" ['[?e :yodlee-provider-account/last-updated ?sort-last-updated]]}
|
||||
query-params)
|
||||
true
|
||||
(merge-query {:query {:find ['?e]
|
||||
:where ['[?e :yodlee-provider-account/id]]}}))]
|
||||
(->> query
|
||||
|
||||
(query2)
|
||||
(apply-sort-3 query-params)
|
||||
(apply-pagination query-params))))
|
||||
|
||||
|
||||
(defn hydrate-results [ids db _]
|
||||
(let [results (->> (pull-many db default-read ids)
|
||||
(group-by :db/id))]
|
||||
@@ -70,26 +68,24 @@
|
||||
(map results)
|
||||
(map first))))
|
||||
|
||||
|
||||
(defn fetch-page [request]
|
||||
(let [db (dc/db conn)
|
||||
{ids-to-retrieve :ids matching-count :count} (fetch-ids db request)]
|
||||
[(->> (hydrate-results ids-to-retrieve db request))
|
||||
matching-count]))
|
||||
|
||||
|
||||
(defn fastlink-dialog [{:keys [client]}]
|
||||
(modal-response
|
||||
(com/modal
|
||||
{}
|
||||
(com/modal-card
|
||||
{}
|
||||
[:div.flex [:div.p-2 "Yodlee Fastlink"] ]
|
||||
[:div
|
||||
[:div#fa-spot]
|
||||
[:script {:lang "text/javascript"}
|
||||
(hiccup/raw
|
||||
(format "
|
||||
(com/modal
|
||||
{}
|
||||
(com/modal-card
|
||||
{}
|
||||
[:div.flex [:div.p-2 "Yodlee Fastlink"]]
|
||||
[:div
|
||||
[:div#fa-spot]
|
||||
[:script {:lang "text/javascript"}
|
||||
(hiccup/raw
|
||||
(format "
|
||||
fastlink.open({fastLinkURL: '%s',
|
||||
accessToken: '%s',
|
||||
params: {'configName': 'Aggregation'},
|
||||
@@ -100,25 +96,24 @@ fastlink.open({fastLinkURL: '%s',
|
||||
}},
|
||||
'fa-spot');
|
||||
|
||||
" (:yodlee2-fastlink env) (yodlee/get-access-token (:client/code client))))]
|
||||
]
|
||||
[:div]))))
|
||||
" (:yodlee2-fastlink env) (yodlee/get-access-token (:client/code client))))]]
|
||||
[:div]))))
|
||||
|
||||
(defn reauthenticate [{:keys [form-params identity]}]
|
||||
(assert-can-see-client identity (-> (dc/pull (dc/db conn) '[{:yodlee-provider-account/client [:db/id]}] (Long/parseLong (get form-params "id")))
|
||||
:yodlee-provider-account/client
|
||||
:db/id))
|
||||
(html-response
|
||||
(com/modal
|
||||
{}
|
||||
(com/modal-card
|
||||
{}
|
||||
[:div.flex [:div.p-2 "Yodlee Fastlink"] ]
|
||||
[:div
|
||||
[:div#fa-spot]
|
||||
[:script {:lang "text/javascript"}
|
||||
(hiccup/raw
|
||||
(format "
|
||||
(com/modal
|
||||
{}
|
||||
(com/modal-card
|
||||
{}
|
||||
[:div.flex [:div.p-2 "Yodlee Fastlink"]]
|
||||
[:div
|
||||
[:div#fa-spot]
|
||||
[:script {:lang "text/javascript"}
|
||||
(hiccup/raw
|
||||
(format "
|
||||
fastlink.open({fastLinkURL: '%s',
|
||||
accessToken: '%s',
|
||||
params: {'configName': 'Aggregation',
|
||||
@@ -127,94 +122,93 @@ fastlink.open({fastLinkURL: '%s',
|
||||
'fa-spot');
|
||||
|
||||
"
|
||||
(:yodlee2-fastlink env)
|
||||
(yodlee/get-access-token (-> (dc/pull (dc/db conn)
|
||||
[{:yodlee-provider-account/client [:client/code]}]
|
||||
(Long/parseLong (get form-params "id")))
|
||||
:yodlee-provider-account/client
|
||||
:client/code))
|
||||
(pull-attr (dc/db conn) :yodlee-provider-account/id (Long/parseLong (get form-params "id")))))]]
|
||||
[:div]))))
|
||||
(:yodlee2-fastlink env)
|
||||
(yodlee/get-access-token (-> (dc/pull (dc/db conn)
|
||||
[{:yodlee-provider-account/client [:client/code]}]
|
||||
(Long/parseLong (get form-params "id")))
|
||||
:yodlee-provider-account/client
|
||||
:client/code))
|
||||
(pull-attr (dc/db conn) :yodlee-provider-account/id (Long/parseLong (get form-params "id")))))]]
|
||||
[:div]))))
|
||||
|
||||
(def grid-page
|
||||
(helper/build
|
||||
{:id "yodlee-table"
|
||||
:nav com/company-aside-nav
|
||||
:id-fn :db/id
|
||||
:fetch-page fetch-page
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company)}
|
||||
"My Company"]
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee)}
|
||||
"Yodlee"]]
|
||||
:title "Yodlee Accounts"
|
||||
:entity-name "Yodlee accounts"
|
||||
:query-schema query-schema
|
||||
:route :company-yodlee-table
|
||||
:action-buttons (fn [request]
|
||||
[[:div.flex.flex-col.flex-shrink
|
||||
[:div.flex-shrink
|
||||
(com/button {:color :primary
|
||||
:on-click "openFastlink()"
|
||||
:disabled (if (:client request)
|
||||
false
|
||||
true)
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee-fastlink-dialog)
|
||||
:hx-target "#modal-holder"}
|
||||
(com/button-icon {} svg/refresh)
|
||||
"Link new account")]
|
||||
(when-not (:client request)
|
||||
[:div.text-xs "Note: please select a specific customer to link a new account."])]])
|
||||
:row-buttons (fn [request _]
|
||||
[
|
||||
(com/button {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee-provider-account-reauthenticate)
|
||||
:color :primary
|
||||
:hx-target "#modal-holder"}
|
||||
"Reauthenticate")
|
||||
(when (is-admin? (:identity request))
|
||||
(com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee-provider-account-refresh)
|
||||
:hx-target "closest tr"}
|
||||
svg/refresh))])
|
||||
:headers [{:key "client"
|
||||
:name "Client"
|
||||
:sort-key "client"
|
||||
:hide? (fn [args]
|
||||
(= (count (:clients args)) 1))
|
||||
:render #(-> % :yodlee-provider-account/client :client/code)}
|
||||
{:key "provider-account"
|
||||
:name "Provider Account"
|
||||
:sort-key "provider-account"
|
||||
:render :yodlee-provider-account/id}
|
||||
{:key "status"
|
||||
:name "Status"
|
||||
:sort-key "status"
|
||||
:render #(when-let [status (:yodlee-provider-account/status %)]
|
||||
(com/pill {:color (if (not= status "SUCCESS")
|
||||
:yellow
|
||||
:primary) }
|
||||
status))}
|
||||
{:key "detailed-status"
|
||||
:name "Detailed Status"
|
||||
:sort-key "detailed-status"
|
||||
:render #(when-let [status (:yodlee-provider-account/detailed-status %)]
|
||||
status)}
|
||||
(helper/build
|
||||
{:id "yodlee-table"
|
||||
:nav com/company-aside-nav
|
||||
:id-fn :db/id
|
||||
:fetch-page fetch-page
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company)}
|
||||
"My Company"]
|
||||
[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee)}
|
||||
"Yodlee"]]
|
||||
:title "Yodlee Accounts"
|
||||
:entity-name "Yodlee accounts"
|
||||
:query-schema query-schema
|
||||
:route :company-yodlee-table
|
||||
:action-buttons (fn [request]
|
||||
[[:div.flex.flex-col.flex-shrink
|
||||
[:div.flex-shrink
|
||||
(com/button {:color :primary
|
||||
:on-click "openFastlink()"
|
||||
:disabled (if (:client request)
|
||||
false
|
||||
true)
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee-fastlink-dialog)
|
||||
:hx-target "#modal-holder"}
|
||||
(com/button-icon {} svg/refresh)
|
||||
"Link new account")]
|
||||
(when-not (:client request)
|
||||
[:div.text-xs "Note: please select a specific customer to link a new account."])]])
|
||||
:row-buttons (fn [request _]
|
||||
[(com/button {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee-provider-account-reauthenticate)
|
||||
:color :primary
|
||||
:hx-target "#modal-holder"}
|
||||
"Reauthenticate")
|
||||
(when (is-admin? (:identity request))
|
||||
(com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||
:company-yodlee-provider-account-refresh)
|
||||
:hx-target "closest tr"}
|
||||
svg/refresh))])
|
||||
:headers [{:key "client"
|
||||
:name "Client"
|
||||
:sort-key "client"
|
||||
:hide? (fn [args]
|
||||
(= (count (:clients args)) 1))
|
||||
:render #(-> % :yodlee-provider-account/client :client/code)}
|
||||
{:key "provider-account"
|
||||
:name "Provider Account"
|
||||
:sort-key "provider-account"
|
||||
:render :yodlee-provider-account/id}
|
||||
{:key "status"
|
||||
:name "Status"
|
||||
:sort-key "status"
|
||||
:render #(when-let [status (:yodlee-provider-account/status %)]
|
||||
(com/pill {:color (if (not= status "SUCCESS")
|
||||
:yellow
|
||||
:primary)}
|
||||
status))}
|
||||
{:key "detailed-status"
|
||||
:name "Detailed Status"
|
||||
:sort-key "detailed-status"
|
||||
:render #(when-let [status (:yodlee-provider-account/detailed-status %)]
|
||||
status)}
|
||||
|
||||
{:key "last-updated"
|
||||
:name "Last Updated"
|
||||
:sort-key "last-updated"
|
||||
:render #(atime/unparse-local (:yodlee-provider-account/last-updated %)
|
||||
atime/normal-date)}
|
||||
{:key "accounts"
|
||||
:name "Accounts"
|
||||
:show-starting "md"
|
||||
:render (fn [e]
|
||||
[:ul
|
||||
(for [a (:yodlee-provider-account/accounts e)]
|
||||
[:li (:yodlee-account/name a) " - " (:yodlee-account/number a)])])}]}))
|
||||
{:key "last-updated"
|
||||
:name "Last Updated"
|
||||
:sort-key "last-updated"
|
||||
:render #(atime/unparse-local (:yodlee-provider-account/last-updated %)
|
||||
atime/normal-date)}
|
||||
{:key "accounts"
|
||||
:name "Accounts"
|
||||
:show-starting "md"
|
||||
:render (fn [e]
|
||||
[:ul
|
||||
(for [a (:yodlee-provider-account/accounts e)]
|
||||
[:li (:yodlee-account/name a) " - " (:yodlee-account/number a)])])}]}))
|
||||
|
||||
(def page (helper/page-route grid-page))
|
||||
(def table (helper/table-route grid-page))
|
||||
@@ -224,26 +218,23 @@ fastlink.open({fastLinkURL: '%s',
|
||||
(yodlee/refresh-provider-account (:client/code (:yodlee-provider-account/client provider-account))
|
||||
(:yodlee-provider-account/id provider-account))
|
||||
(html-response
|
||||
(helper/row*
|
||||
grid-page
|
||||
identity
|
||||
provider-account
|
||||
{:flash? true}))))
|
||||
(helper/row*
|
||||
grid-page
|
||||
identity
|
||||
provider-account
|
||||
{:flash? true}))))
|
||||
|
||||
|
||||
(def key->handler
|
||||
(apply-middleware-to-all-handlers
|
||||
{
|
||||
:company-yodlee page
|
||||
(def key->handler
|
||||
(apply-middleware-to-all-handlers
|
||||
{:company-yodlee page
|
||||
:company-yodlee-table table
|
||||
:company-yodlee-fastlink-dialog fastlink-dialog
|
||||
}
|
||||
:company-yodlee-fastlink-dialog fastlink-dialog}
|
||||
(fn [h]
|
||||
(-> h
|
||||
(wrap-copy-qp-pqp)
|
||||
(wrap-apply-sort grid-page)
|
||||
(wrap-merge-prior-hx)
|
||||
(wrap-schema-enforce :query-schema query-schema)
|
||||
(wrap-schema-enforce :hx-schema query-schema)
|
||||
(wrap-client-redirect-unauthenticated)
|
||||
(wrap-secure)))))
|
||||
(-> h
|
||||
(wrap-copy-qp-pqp)
|
||||
(wrap-apply-sort grid-page)
|
||||
(wrap-merge-prior-hx)
|
||||
(wrap-schema-enforce :query-schema query-schema)
|
||||
(wrap-schema-enforce :hx-schema query-schema)
|
||||
(wrap-client-redirect-unauthenticated)
|
||||
(wrap-secure)))))
|
||||
Reference in New Issue
Block a user