Fork me on GitHub
#fulcro
<
2022-11-24
>
krapjost07:11:38

Hello fulcro, I have trivial question about Fulcro RAD: How can i get current logged in user and use it as default value inside form? I tried like follow but it doesn't work apparently.

(defsc AuthorQuery [_ {::auth/keys [authorization]}]
  {:query [:account/id :account/name ::auth/authorization]
   :ident :account/id})

(form/defsc-form BookForm [this props]
  {fo/id             book/id
   fo/attributes     [book/name
                      book/description
                      book/genre
                      book/author
                      ]
   fo/default-values {
                      ;; :book/author (new-uuid 101)
                      :book/author AuthorQuery
                      :book/genre  {}}
   fo/subforms       {:book/genre {fo/title       "Genre"
                                   fo/ui          GenreForm
                                   fo/can-delete? (fn [parent _]
                                                    (> (count (:book/genre (comp/props parent))) 1))
                                   fo/can-add?    (fn [parent _]
                                                    (and
                                                     (< (count (:book/genre (comp/props parent))) 3)
                                                     :prepend))}}
   fo/route-prefix   "book"
   fo/title          "Edit Book"})
My Book model's author attribute is:
(defattr author :book/author :ref
  {ao/target      :account/id
   ao/required?   true
   ao/cardinality :one
   ao/identities  #{:book/id}
   ao/schema      :production})

Quentin Le Guennec14:11:32

Hello, what should be the shape of the data returned by a custom remote in the case of a df/load! mutation? Can’t find anything in the docs on that topic. (in my case it’s a local storage remote)

Quentin Le Guennec14:11:44

Is there a way to include an edge of the client database in a remote mutation?

tony.kay16:11:00

As an arg or return? You can augment parameters with m/with-params. On return you can augment in ok-action. Lots more options, but those are the most direct

Quentin Le Guennec07:11:58

Yes but m/with-params would mean I need to read the edge in the client database before transacting the mutation. I want to read the data I need in the remote section directly.

tony.kay18:11:34

You need to explain exactly what you are trying to do if you want an exact answer. step-by-step. Where is the data, where is it to come from, and where/how do you want it sent?

Quentin Le Guennec21:11:42

Ok. I need to get some credentials from the client db in order to send them to the fulcro backend, but I’d like to pull them from the client db within the mutation code.

tony.kay22:11:24

env has state, which is the client db atom

tony.kay22:11:05

(remote [{:keys [state] :as env}]
  (let [creds (get @state ...)] ...))

tony.kay22:11:35

combine that with the m/with-params and merge in the params you got in the mutation

tony.kay22:11:32

OR, query for the auth stuff in the UI with a link query and combine it in at the transact call site

tony.kay22:11:34

either is fine

Quentin Le Guennec13:11:06

Understood, thanks