Simplifies a lot by using cursors

This commit is contained in:
2023-10-20 00:12:42 -07:00
parent 174c428405
commit ce8fa027b2
6 changed files with 381 additions and 173 deletions

View File

@@ -122,3 +122,9 @@ htmx.defineExtension('trigger-filter', {
initDatepicker = function(elem) { initDatepicker = function(elem) {
elem.dp = new Datepicker(elem, {format: "mm/dd/yyyy", autohide: true}); elem.dp = new Datepicker(elem, {format: "mm/dd/yyyy", autohide: true});
} }
countRows = function(id) {
var table = document.querySelector(id);
var rows = table.querySelectorAll("tbody tr");
return rows.length;
}

137
src/clj/auto_ap/cursor.clj Normal file
View File

@@ -0,0 +1,137 @@
(ns auto-ap.cursor
(:import (clojure.lang IDeref Atom ILookup Counted IFn AFn Indexed ISeq Seqable)))
; TODO not sure if these methods are needed at all; ICursor is used solely as a marker right now
(defprotocol ICursor
(path [cursor])
(state [cursor]))
(defprotocol ITransact
(-transact! [cursor f]))
(declare to-cursor cursor?)
(deftype ValCursor [value state path]
IDeref
(deref [_]
(get-in @state path value))
ICursor
(path [_] path)
(state [_] state)
ITransact
(-transact! [_ f]
(get-in
(swap! state (if (empty? path) f #(update-in % path f)))
path)))
(deftype MapCursor [value state path]
Counted
(count [_]
(count (get-in @state path value)))
ICursor
(path [_] path)
(state [_] state)
IDeref
(deref [_]
(get-in @state path value))
IFn
(invoke [this key]
(get this key))
(invoke [this key defval]
(get this key defval))
(applyTo [this args]
(AFn/applyToHelper this args))
ILookup
(valAt [obj key]
(.valAt obj key nil))
(valAt [_ key defv]
(let [value (get-in @state path value)]
(to-cursor (get value key defv) state (conj path key) defv)))
ITransact
(-transact! [cursor f]
(get-in
(swap! state (if (empty? path) f #(update-in % path f)))
path))
Seqable
(seq [this]
(for [[k v] @this]
[k (to-cursor v state (conj path k) nil)])))
(deftype VecCursor [value state path]
Counted
(count [_]
(count (get-in @state path)))
ICursor
(path [_] path)
(state [_] state)
IDeref
(deref [_]
(get-in @state path))
IFn
(invoke [this i]
(nth this i))
(applyTo [this args]
(AFn/applyToHelper this args))
ILookup
(valAt [this i]
(nth this i))
(valAt [this i not-found]
(nth this i not-found))
Indexed
(nth [_ i]
(let [value (get-in @state path value)]
(to-cursor (nth value i) state (conj path i) nil)))
(nth [_ i not-found]
(let [value (get-in @state path value)]
(to-cursor (nth value i not-found) state (conj path i) not-found)))
ITransact
(-transact! [cursor f]
(get-in
(swap! state (if (empty? path) f #(update-in % path f)))
path))
Seqable
(seq [this]
(for [[v i] (map vector @this (range))]
(to-cursor v state (conj path i) nil))))
(defn- to-cursor
([v state path value]
(cond
(cursor? v) v
(map? v) (MapCursor. value state path)
(vector? v) (VecCursor. value state path)
:else (ValCursor. value state path)
)))
(defn cursor? [c]
"Returns true if c is a cursor."
(satisfies? ICursor c))
(defn cursor [v]
"Creates cursor from supplied value v. If v is an ordinary
data structure, it is wrapped into atom. If v is an atom,
it is used directly, so all changes by cursor modification
functions are reflected in supplied atom reference."
(to-cursor (if (instance? Atom v) @v v)
(if (instance? Atom v) v (atom v))
[] nil))
(defn transact! [cursor f]
"Changes value beneath cursor by passing it to a single-argument
function f. Old value will be passed as function argument. Function
result will be the new value."
(-transact! cursor f))
(defn update! [cursor v]
"Replaces value supplied by cursor with value v."
(-transact! cursor (constantly v)))

View File

@@ -45,7 +45,8 @@
[datomic.api :as dc] [datomic.api :as dc]
[hiccup2.core :as hiccup] [hiccup2.core :as hiccup]
[iol-ion.query :refer [ident]] [iol-ion.query :refer [ident]]
[malli.core :as mc])) [malli.core :as mc]
[auto-ap.cursor :as cursor]))
;; TODO with dependencies, I really don't like that you have to be ultra specific in what ;; TODO with dependencies, I really don't like that you have to be ultra specific in what
;; you want to include, and generating the routes and interconnection is weird too. ;; you want to include, and generating the routes and interconnection is weird too.
@@ -57,6 +58,27 @@
;; TODO better generation of names? ;; TODO better generation of names?
(def ^:dynamic *errors*)
(def ^:dynamic *prev-cursor* nil)
(def ^:dynamic *cursor* nil)
(defmacro with-cursor [cursor & rest]
`(binding [*prev-cursor* (or *cursor* ~cursor)]
(binding [*cursor* ~cursor]
~@rest)))
(defn cursor-name []
(apply path->name2 (cursor/path *cursor*)))
(defn cursor-value []
@*cursor*)
(defn cursor-errors []
(:errors (get
(meta @*prev-cursor*)
(last (cursor/path *cursor*)))))
(defn filters [request] (defn filters [request]
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms" [:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
@@ -271,21 +293,21 @@
bank-account-id)) bank-account-id))
(defn transaction-rule-save [{:keys [form-params request-method identity] :as request}] (defn transaction-rule-save [{:keys [form-params request-method identity] :as request}]
(let [entity (cond-> form-params (let [entity (cond-> form-params
(= :post request-method) (assoc :db/id "new") (= :post request-method) (assoc :db/id "new")
true (assoc :transaction-rule/note (entity->note form-params))) true (assoc :transaction-rule/note (entity->note form-params)))
_ (doseq [[{:transaction-rule-account/keys [account location]} i] (map vector (:transaction-rule/accounts entity) (range)) _ (doseq [[{:transaction-rule-account/keys [account location]} i] (map vector (:transaction-rule/accounts entity) (range))
:let [account-location (pull-attr (dc/db conn) :account/location account)] :let [account-location (pull-attr (dc/db conn) :account/location account)]
:when (and account-location (not= account-location location))] :when (and account-location (not= account-location location))]
(field-validation-error (str "must be " account-location) (field-validation-error (str "must be " account-location)
[:transaction-rule/accounts i :transaction-rule-account/location] [:transaction-rule/accounts i :transaction-rule-account/location]
:form entity)) :form entity))
total (reduce + total (reduce +
0.0 0.0
(map :transaction-rule-account/percentage (map :transaction-rule-account/percentage
(:transaction-rule/accounts entity))) (:transaction-rule/accounts entity)))
_ (when-not (dollars= 1.0 total) _ (when-not (dollars= 1.0 total)
(form-validation-error (format "Expense accounts total (%d%%) must add to 100%%" (int (* 100.0 total))) (form-validation-error (format "Expense accounts total (%d%%) must add to 100%%" (int (* 100.0 total)))
:form entity)) :form entity))
@@ -344,64 +366,65 @@
(defn- transaction-rule-account-row* (defn- transaction-rule-account-row*
[transaction-rule account] [transaction-rule account]
(com/data-grid-row {} (com/data-grid-row {}
(let [account-name (path->name2 :transaction-rule/accounts (:db/id account) :transaction-rule-account/account) (let [account-name (with-cursor (:transaction-rule-account/account account)
location-name (path->name2 :transaction-rule/accounts (:db/id account) :transaction-rule-account/location)] (cursor-name))]
(list (list
(com/data-grid-cell {} (with-cursor (:db/id account)
[:div {:hx-trigger (hx/trigger-field-change :name "transaction-rule/client" (com/hidden {:name (cursor-name)
:from "#edit-form") :value (cursor-value)}))
:hx-include "#edit-form" (with-cursor (:transaction-rule-account/account account)
:hx-vals (hx/vals {:name account-name}) (com/data-grid-cell {}
:hx-ext "rename-params" [:div {:hx-trigger (hx/trigger-field-change :name "transaction-rule/client"
:hx-rename-params-ex (hx/json {:transaction-rule/client "client-id" :from "#edit-form")
:name "name" :hx-include "#edit-form"
account-name "value"}) :hx-vals (hx/vals {:name account-name})
:hx-get (str (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-account-typeahead)) :hx-ext "rename-params"
:hx-swap "innerHTML"} :hx-rename-params-ex (hx/json {:transaction-rule/client "client-id"
(account-typeahead* {:value (:transaction-rule-account/account account) :name "name"
:client-id (:db/id (:transaction-rule/client transaction-rule)) account-name "value"})
:name account-name}) :hx-get (str (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-account-typeahead))
(com/field-errors {:source account :hx-swap "innerHTML"}
:key :transaction-rule-account/account})]) (account-typeahead* {:value (cursor-value)
(com/data-grid-cell {} :client-id (:db/id (:transaction-rule/client transaction-rule))
[:div [:div {:hx-trigger (hx/triggers :name (cursor-name)})
(hx/trigger-field-change :name "transaction-rule/client" (com/errors {:errors (cursor-errors)})]))
:from "#edit-form") (with-cursor (:transaction-rule-account/location account)
(hx/trigger-field-change :name account-name (com/data-grid-cell {}
:from "#edit-form")) [:div [:div {:hx-trigger (hx/triggers
:hx-include "#edit-form" (hx/trigger-field-change :name "transaction-rule/client"
:hx-vals (hx/vals {:name location-name}) :from "#edit-form")
:hx-ext "rename-params" (hx/trigger-field-change :name account-name
:hx-rename-params-ex (hx/json {"transaction-rule/client" "client-id" :from "#edit-form"))
account-name "account-id" :hx-include "#edit-form"
"name" "name" :hx-vals (hx/vals {:name (cursor-name)})
location-name "value"}) :hx-ext "rename-params"
:hx-get (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-location-select) :hx-rename-params-ex (hx/json {"transaction-rule/client" "client-id"
:hx-swap "innerHTML"} account-name "account-id"
(location-select* {:name location-name "name" "name"
:account-location (:account/location (cond->> (:transaction-rule-account/account account) (cursor-name) "value"})
(nat-int? (:transaction-rule-account/account account)) (dc/pull (dc/db conn) :hx-get (bidi/path-for ssr-routes/only-routes :admin-transaction-rule-location-select)
'[:account/location]))) :hx-swap "innerHTML"}
:client-locations (:client/locations (:transaction-rule/client transaction-rule)) (location-select* {:name (cursor-name)
:value (:transaction-rule-account/location account)})] :account-location (:account/location (cond->> (:transaction-rule-account/account @account)
(com/field-errors {:source account (nat-int? (:transaction-rule-account/account @account)) (dc/pull (dc/db conn)
:key :transaction-rule-account/location})]) '[:account/location])))
(com/data-grid-cell (com/money-input {:name (format "transaction-rule/accounts[%s][transaction-rule-account/percentage]" (:db/id account)) :client-locations (:client/locations (:transaction-rule/client transaction-rule))
:class "w-16" :value (cursor-value)})]
:value (some-> account (com/errors {:errors (cursor-errors)})]
:transaction-rule-account/percentage ))
(* 100 ) (with-cursor (:transaction-rule-account/percentage account)
(long ))}) (com/data-grid-cell (com/money-input {:name (cursor-name)
(com/field-errors {:source account :class "w-16"
:key :transaction-rule-account/percentage})))) :value (some-> (cursor-value)
(* 100 )
(long ))})
(com/errors {:errors (cursor-errors)})))))
(com/data-grid-cell (com/data-grid-cell
(com/a-icon-button (com/a-icon-button
{"_" (hiccup/raw "on click halt the event then transition the closest <tr />'s opacity to 0 then remove closest <tr />") {"_" (hiccup/raw "on click halt the event then transition the closest <tr />'s opacity to 0 then remove closest <tr />")
:href "#"} :href "#"}
svg/x)))) svg/x))))
(defn dialog* [& {:keys [ entity form-params]}] (defn dialog* [& {:keys [ entity form-params]}]
(com/modal (com/modal
{:modal-class "max-w-4xl"} {:modal-class "max-w-4xl"}
@@ -415,121 +438,151 @@
form-params) form-params)
[:fieldset {:class "hx-disable" :hx-disinherit "hx-target"} [:fieldset {:class "hx-disable" :hx-disinherit "hx-target"}
[:div.space-y-6 (with-cursor (cursor/cursor entity)
(when-let [id (:db/id entity)] [:div.space-y-2
(com/hidden {:name "db/id" (when-let [id (:db/id entity)]
:value id})) (com/hidden {:name "db/id"
(com/field {:label "Client"} :value id}))
[:div.w-96 (with-cursor (:transaction-rule/client *cursor*)
(com/typeahead {:name "transaction-rule/client" (com/validated-field
:class "w-96" {:label "Client"
:placeholder "Search..." :errors (cursor-errors)}
:url (bidi/path-for ssr-routes/only-routes :company-search) [:div.w-96
:id (str "form-client-search") (com/typeahead {:name (cursor-name)
:value (:transaction-rule/client entity) :class "w-96"
:value-fn (some-fn :db/id identity) :placeholder "Search..."
:content-fn (fn [c] (cond->> c :url (bidi/path-for ssr-routes/only-routes :company-search)
(nat-int? c) (dc/pull (dc/db conn) '[:client/name]) :id (str "form-client-search")
true :client/name))})]) :value (cursor-value)
:value-fn (some-fn :db/id identity)
:content-fn (fn [c] (cond->> c
(nat-int? c) (dc/pull (dc/db conn) '[:client/name])
true :client/name))})]))
(com/field {:label "Bank Account"} (with-cursor (:transaction-rule/bank-account *cursor*)
[:div#bank-account-spot.w-96 {:hx-get (bidi/path-for ssr-routes/only-routes :bank-account-typeahead) (com/validated-field {:label "Bank Account"
:hx-trigger (hx/trigger-field-change :name "transaction-rule/client" :errors (cursor-errors)}
:from "#edit-form") [:div#bank-account-spot.w-96 {:hx-get (bidi/path-for ssr-routes/only-routes :bank-account-typeahead)
:hx-swap "innerHTML" :hx-trigger (hx/trigger-field-change :name "transaction-rule/client"
:hx-ext "rename-params" :from "#edit-form")
:hx-include "#edit-form" :hx-swap "innerHTML"
:hx-vals (hx/vals {:name "transaction-rule/bank-account"}) :hx-ext "rename-params"
:hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id" :hx-include "#edit-form"
"name" "name"})} :hx-vals (hx/vals {:name (cursor-name)})
(bank-account-typeahead* {:client-id ((some-fn :db/id identity) (:transaction-rule/client entity)) :hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"
:name "transaction-rule/bank-account" "name" "name"})}
:value (:transaction-rule/bank-account entity)}) (bank-account-typeahead* {:client-id ((some-fn :db/id identity) (:transaction-rule/client entity))
(com/field-errors {:source entity :name (cursor-name)
:key :transaction-rule/bank-account})]) :value (cursor-value)})]))
(com/field {:label "Description" (with-cursor (:transaction-rule/description *cursor*)
:error-source entity (com/validated-field {:label "Description"
:error-key :transaction-rule/description} :errors (cursor-errors)}
(com/text-input {:name "transaction-rule/description" (com/text-input {:name (cursor-name)
"_" (hiccup/raw "on load call me.focus()") :placeholder "HOME DEPOT"
:placeholder "HOME DEPOT" :class "w-96"
:class "w-96" :value (cursor-value)})))
:value (:transaction-rule/description entity)}))
(com/field {:label "Amount"}
[:div.flex.gap-2
(with-cursor (:transaction-rule/amount-gte *cursor*)
[:div.flex.flex-col
(com/money-input {:name (cursor-name)
:placeholder ">="
:class "w-24"
:value (cursor-value)})
(com/errors {:errors (cursor-errors)})])
(with-cursor (:transaction-rule/amount-lte *cursor*)
[:div.flex.flex-col
(com/money-input {:name (cursor-name)
:placeholder "<="
:class "w-24"
:value (cursor-value)})
(com/errors {:errors (cursor-errors)})])])
(com/field {:label "Day of month"}
[:div.flex.gap-2
(with-cursor (:transaction-rule/dom-gte *cursor*)
[:div.flex.flex-col
(com/int-input {:name (cursor-name)
:placeholder ">="
:class "w-24"
:value (cursor-value)})
(com/errors {:errors (cursor-errors)})])
(with-cursor (:transaction-rule/dom-lte *cursor*)
[:div.flex.flex-col
(com/int-input {:name (cursor-name)
:placeholder ">="
:class "w-24"
:value (cursor-value)})
(com/errors {:errors (cursor-errors)})])])
(com/field {:label "Amount"} [:h2.text-lg "Outcomes"]
[:div.flex.gap-2 (with-cursor (:transaction-rule/vendor *cursor*)
(com/money-input {:name "transaction-rule/amount-gte" (com/validated-field {:label "Assign Vendor"
:placeholder ">=" :errors (cursor-errors)}
:class "w-24" [:div.w-96
:value (:transaction-rule/amount-gte entity)}) (com/typeahead {:name (cursor-name)
(com/money-input {:name "transaction-rule/amount-lte" :placeholder "Search..."
:placeholder "<=" :url (bidi/path-for ssr-routes/only-routes :vendor-search)
:class "w-24" :id (str "form-vendor-search")
:value (:transaction-rule/amount-lte entity)})]) :value (cursor-value)
:value-fn (some-fn :db/id identity)
:content-fn (some-fn :vendor/name #(pull-attr (dc/db conn) :vendor/name %))})]))
(com/field {:label "Day of month"} (with-cursor (:transaction-rule/accounts *cursor*)
[:div.flex.gap-2 (list
(com/int-input {:name "transaction-rule/dom-gte" (com/data-grid {:headers [(com/data-grid-header {}
:placeholder ">=" "Account")
:class "w-24" (com/data-grid-header {:class "w-32"} "Location")
:value (:transaction-rule/dom-gte entity)}) (com/data-grid-header {:class "w-16"} "%")
(com/int-input {:name "transaction-rule/dom-lte" (com/data-grid-header {:class "w-16"})]
:placeholder "<=" :id "transaction-rule-account-table"}
:class "w-24" (for [tra *cursor*]
:value (:transaction-rule/dom-lte entity)})]) (with-cursor tra
(transaction-rule-account-row* entity tra))))
[:h2.text-lg "Outcomes"] (com/errors {:errors (cursor-errors)})))
(com/field {:label "Assign Vendor" (com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:error-source entity :admin-transaction-rule-new-account)
:error-key :transaction-rule/vendor} :hx-include "#edit-form"
[:div.w-96 :hx-ext "rename-params"
(com/typeahead {:name "transaction-rule/vendor" :hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"
:placeholder "Search..." "index" "index"})
:url (bidi/path-for ssr-routes/only-routes :vendor-search) :hx-vals (hiccup/raw "js:{index: countRows(\"#transaction-rule-account-table\")}")
:id (str "form-vendor-search") :hx-target "#transaction-rule-account-table tbody"
:value (:transaction-rule/vendor entity) :hx-swap "beforeend"}
:value-fn (some-fn :db/id identity) "New account")
:content-fn (some-fn :vendor/name #(pull-attr (dc/db conn) :vendor/name %))})]) (with-cursor (:transaction-rule/transaction-approval-status *cursor*)
(com/radio {:options (ref->radio-options "transaction-approval-status")
(com/data-grid {:headers [(com/data-grid-header {} :value (cursor-value)
"Account") :name (cursor-name)}))
(com/data-grid-header {:class "w-32"} "Location")
(com/data-grid-header {:class "w-16"} "%") [:div#form-errors [:span.error-content
(com/data-grid-header {:class "w-16"})] (com/errors {:errors (:errors (meta entity))})]]
:id "transaction-rule-account-table"} (com/button {:color :primary :form "edit-form" :type "submit"}
(for [tra (:transaction-rule/accounts entity)] "Save")])]]
(transaction-rule-account-row* entity tra)))
(com/field-errors {:source entity
:key :transaction-rule/accounts})
(com/a-button {:hx-get (bidi/path-for ssr-routes/only-routes
:admin-transaction-rule-new-account)
:hx-include "#edit-form"
:hx-ext "rename-params"
:hx-rename-params-ex (cheshire/generate-string {"transaction-rule/client" "client-id"})
:hx-target "#transaction-rule-account-table tbody"
:hx-swap "beforeend"}
"New account")
(com/radio {:options (ref->radio-options "transaction-approval-status")
:value (:transaction-rule/transaction-approval-status entity)
:name (path->name2 :transaction-rule/transaction-approval-status)})
[:div#form-errors [:span.error-content
(com/field-errors {:source entity})]]
(com/button {:color :primary :form "edit-form" :type "submit"}
"Save")]]]
[:div]))) [:div])))
(defn new-account [{{:keys [client-id]} :query-params}] (defn new-account [{{:keys [client-id index]} :query-params}]
(html-response (let [transaction-rule {:transaction-rule/client (dc/pull (dc/db conn) '[:client/name :client/locations :db/id]
(transaction-rule-account-row* client-id)
{:transaction-rule/client (dc/pull (dc/db conn) '[:client/name :client/locations :db/id] :transaction-rule/accounts (conj (into [] (repeat (inc index) {} ))
client-id)} {:db/id (str (java.util.UUID/randomUUID))
{:db/id (str (java.util.UUID/randomUUID)) :transaction-rule-account/location "Shared"})}]
:transaction-rule-account/location "shared"}))) (html-response
(with-cursor (cursor/cursor transaction-rule)
(with-cursor (:transaction-rule/accounts *cursor*)
(with-cursor (nth *cursor* 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
*cursor*
)))))))
;; TODO check to see if it should be called "Shared" or "shared" for the value
(defn location-select [{{:keys [name account-id client-id value] :as qp} :query-params}] (defn location-select [{{:keys [name account-id client-id value] :as qp} :query-params}]
(html-response (location-select* {:name name (html-response (location-select* {:name name
@@ -574,7 +627,7 @@
(def transaction-rule-schema (mc/schema (def transaction-rule-schema (mc/schema
[:map [:map
[:db/id {:optional true} [:maybe entity-id]] [:db/id {:optional true} [:maybe entity-id]]
[:transaction-rule/client {:optional true} [:maybe entity-id]] [:transaction-rule/client entity-id]
[:transaction-rule/description [:and regex [:transaction-rule/description [:and regex
[:string {:min 3}]]] [:string {:min 3}]]]
[:transaction-rule/bank-account [:maybe entity-id]] [:transaction-rule/bank-account [:maybe entity-id]]
@@ -599,7 +652,8 @@
:admin-transaction-rule-new-account (-> new-account :admin-transaction-rule-new-account (-> new-account
(wrap-schema-decode :query-schema [:map (wrap-schema-decode :query-schema [:map
[:client-id {:optional true} [:client-id {:optional true}
[:maybe entity-id]]]) [:maybe entity-id]]
[:index nat-int?]])
wrap-admin wrap-client-redirect-unauthenticated) wrap-admin wrap-client-redirect-unauthenticated)
:admin-transaction-rule-location-select (-> location-select :admin-transaction-rule-location-select (-> location-select
(wrap-schema-decode :query-schema [:map (wrap-schema-decode :query-schema [:map

View File

@@ -33,6 +33,8 @@
(def typeahead inputs/typeahead-) (def typeahead inputs/typeahead-)
(def field-errors inputs/field-errors-) (def field-errors inputs/field-errors-)
(def field inputs/field-) (def field inputs/field-)
(def validated-field inputs/validated-field-)
(def errors inputs/errors-)
(def left-aside aside/left-aside-) (def left-aside aside/left-aside-)
(def company-aside-nav aside/company-aside-nav-) (def company-aside-nav aside/company-aside-nav-)

View File

@@ -122,5 +122,13 @@ c.clearChoices();
(field-errors- {:source (:error-source params) (field-errors- {:source (:error-source params)
:key (:error-key params)}))]) :key (:error-key params)}))])
(defn errors- [{:keys [errors]}]
[:p.mt-2.text-xs.text-red-600.dark:text-red-500.h-4 (str/join ", " errors)])
(defn validated-field- [params & rest]
(field- (dissoc params :errors)
rest
(errors- {:errors (:errors params)})))
(defn hidden- [{:keys [name value]}] (defn hidden- [{:keys [name value]}]
[:input {:type "hidden" :value value :name name}]) [:input {:type "hidden" :value value :name name}])

View File

@@ -117,8 +117,9 @@
(def map->db-id-decoder (def map->db-id-decoder
{:enter (fn [x] {:enter (fn [x]
(into [] (into []
(for [[k v] x] (for [[k v] (sort-by (comp #(Long/parseLong %) name first) x)]
(assoc v :db/id (cond (and (string? k) (re-find #"^\d+$" k)) v
#_(assoc v :db/id (cond (and (string? k) (re-find #"^\d+$" k))
(Long/parseLong k) (Long/parseLong k)
(keyword? k) (keyword? k)
(name k) (name k)