fulcro

janezj 2024-11-14T10:46:45.999749Z

Hi Tony, I would like to pass :remote to form/start-edit, PR? Some hints required, where is the best place to store the :remote option? Here is an example what is required now to define a remote.

(defn start-edit [uism-env _]
  (let [FormClass  (uism/actor-class uism-env :actor/form)
        form-ident (uism/actor->ident uism-env :actor/form)]
    (log/debug "Issuing load of pre-existing form entity" form-ident)
    (-> uism-env
      (uism/load form-ident FormClass {::uism/ok-event    :event/loaded
                                       ::uism/error-event :event/failed

                                       ;; !!!! REMOTE !!!
                                       :remote :firebase})
      (uism/activate :state/loading))))

(defn initial* [env]
  (log/info "****** profile-form-machine")
  (def env env)
  (let [{::uism/keys [event-data]} env
        {::form/keys [create?]} event-data
        Form       (uism/actor-class env :actor/form)
        form-ident (uism/actor->ident env :actor/form)
        {{:keys [started]} ::form/triggers} (some-> Form (comp/component-options))]
    (cond-> (uism/store env :options event-data)
      create? (form/start-create event-data)
      (not create?) (start-edit event-data)
      (fn? started) (started form-ident))))

(defstatemachine profile-form-machine
  (-> form/form-machine
      (assoc  :foo :bar)
      (assoc-in [::uism/states :initial ::uism/handler] initial*)))

janezj 2024-11-15T21:50:57.962239Z

I am not on the required level. I can just patch state machine to override loading and saving.

tony.kay 2024-11-14T20:03:06.724169Z

That’s a relatively big change, because you’ll have to update the save system as well…which means writing a save mutation that can take a remote as a parameter. This is somewhat advanced…you have to use defmethod on m/mutate.

tony.kay 2024-11-14T20:03:36.000749Z

but then just make an fo/remote option for it

7e27 2024-11-14T12:54:08.303349Z

Hi:) I’m new to Fulcro, so forgive my somewhat basic question: I’m trying to create a RAD report with a column formatter that should render a sub component. I’m a bit confused about how data is loaded from the server. I’ve tried to ask for the missing data via the row-query-inclusion - but I’m not sure where it would make sense to actually issue the load? I’ve tried to find an example of this use case it both the fulcro-rad-tutorial and the fulcro-rad-demo. Any pointers would be much appreciated. Thanks!

sheluchin 2024-11-14T13:44:34.415079Z

If you're using row-query-inclusion you will receive the data in your component's props, so long as you can navigate to it from your ro/source-attribute using your resolvers. You don't need to do a load yourself in cases like this, that's what RAD is doing for you. Maybe this could help: https://github.com/fulcrologic/fulcro-rad-demo/blob/84237727999b017edb36dcb11ec86d629e649ee4/src/shared/com/example/ui/invoice_forms.cljc#L99 You can then get access to it like in the docstring example:

ro/column-formatters {:account/name
                      (fn [this v]
                        (dom/a {:onClick #(form/edit! this AccountForm (-> this comp/props :account/id)} (str v)))}
or you could include props as the third arg in the formatter fn and destructure the attribute you need from there. Not sure about your mention of "rendering a sub component" from the formatter fn though. Usually I just use this function for adding simple bits of DOM around the value. I don't think this would be an appropriate place to use other defsc components because then their query and initial state won't actually be composed into your tree.

7e27 2024-11-14T13:58:17.825329Z

Thanks:) My problem is that I’m trying to do this from a column witch is a :ref type attribute, say:

ro/row-query-inclusion [{:customer/owner [:account/id :account/name]}
ro/column-formatters {:customer/owner
                      (fn [this v]
                        (dom/a {:href "#"
                                :onClick
                                (fn [e]
                                  (.preventDefault e)
                                  (form/edit! this AccountForm (:account/id v)))}
                          (ui-owner-name (get-in @(::app/state-atom app)
                                                 [:account/id (:account/id v)]))))}
But I’m only getting the :account/id in v

7e27 2024-11-14T14:00:32.134969Z

… and the accounts aren’t automatically fetched - so this only works when I have triggered the loading of the accounts by e.g. visiting the accounts report

7e27 2024-11-14T14:02:02.072139Z

But as you say, this might not be appropriate - just not sure how to else go about it:thinking_face:

tony.kay 2024-11-14T19:53:39.599309Z

It isn’t a column unless it is declared as an attribute. So make an attribute, give it a column EQL parameter and a column formatter, and then just drop that column into the report

tony.kay 2024-11-14T20:02:15.588999Z

The row-query-inclusion route is useful when you want to compltely take over row rendering

7e27 2024-11-15T07:46:23.775429Z

Oh my:) Thank you so much! I was down the column-EQL route at some point, but didn’t catch that this is an option to put on the attribute - tried to put it on the report. Adding it to the attribute it just works:) Thanks!