Uses cursors for simplicity, uses common grid bottom

This commit is contained in:
2023-10-23 23:46:01 -07:00
parent 84d6f455ff
commit 48347bb8c5
8 changed files with 98 additions and 90 deletions

View File

@@ -543,31 +543,18 @@
:content-fn (some-fn :vendor/name #(pull-attr (dc/db conn) :vendor/name %))})]))
(fc/with-field :transaction-rule/accounts
(list
(com/data-grid {:headers [(com/data-grid-header {} "Account")
(com/data-grid-header {:class "w-32"} "Location")
(com/data-grid-header {:class "w-16"} "%")
(com/data-grid-header {:class "w-16"})]
:id "transaction-rule-account-table"}
(fc/cursor-map #(transaction-rule-account-row* entity %))
(com/data-grid-row
{:class "new-row"}
(com/data-grid-cell {:colspan 4
:class "bg-gray-100"}
[:div.flex.justify-center
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account)
:color :secondary
:hx-include "#edit-form"
:hx-ext "rename-params"
;; TODO
:hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"
"index" "index"})
:hx-vals (hiccup/raw "js:{index: countRows(\"#transaction-rule-account-table\")}")
:hx-target "#edit-form .new-row"
:hx-swap "beforebegin"}
"New account")])))
(com/errors {:errors (fc/field-errors)})))
(com/data-grid {:headers [(com/data-grid-header {} "Account")
(com/data-grid-header {:class "w-32"} "Location")
(com/data-grid-header {:class "w-16"} "%")
(com/data-grid-header {:class "w-16"})]
:id "transaction-rule-account-table"}
(fc/cursor-map #(transaction-rule-account-row* entity %))
(com/data-grid-new-row {:colspan 4
:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account)
:index (count (fc/field-value))
:tr-params (hx/bind-alpine-vals {} {:client-id "clientId"})}
"New account")))
(fc/with-field :transaction-rule/transaction-approval-status
(com/validated-field {:label "Approval status"
@@ -578,7 +565,6 @@
:size :small
:orientation :horizontal})))
;; TODO componentize
]]
[:div
[:div#form-errors (when (:errors fc/*form-errors*)
@@ -593,21 +579,21 @@
;; pull out the single field to swap
(defn new-account [{{:keys [client-id index]} :query-params}]
(let [index (or index 0) ;; TODO schema decode is not working
transaction-rule {:transaction-rule/client (dc/pull (dc/db conn) '[:client/name :client/locations :db/id]
client-id)
:transaction-rule/accounts (conj (into [] (repeat index {} ))
{:db/id (str (java.util.UUID/randomUUID))
:transaction-rule-account/location "Shared"
:new? true})}]
(html-response
(fc/start-form transaction-rule []
(fc/with-cursor (get-in fc/*current* [:transaction-rule/accounts index])
(transaction-rule-account-row*
;; TODO store a pointer to the "head " cursor for errors instead of nesting them
;; makes it so you don't have to do this
transaction-rule
fc/*current*))))))
(html-response
(fc/start-form-with-prefix
[:transaction-rule/accounts (or index 0)]
{:db/id (str (java.util.UUID/randomUUID))
:transaction-rule-account/location "Shared"
:new? true}
[]
(transaction-rule-account-row*
;; TODO store a pointer to the "head " cursor for errors instead of nesting them
;; makes it so you don't have to do this
{:transaction-rule/client (dc/pull (dc/db conn) '[:client/name :client/locations :db/id]
client-id)}
fc/*current*))))
;; TODO check to see if it should be called "Shared" or "shared" for the value