Fork me on GitHub
#fulcro
<
2022-07-24
>
janezj19:07:57

I would like to fill picker control in rad report with data from db. how to access props?

ro/query-inclusions [{:company (comp/get-query Company)}]
ro/controls {:company {:type :picker
                       :options (for [{:company/keys [id name]} (:company props)] {:value id :text name})
                       :label "company"}}

1
janezj19:07:14

No, I haven't. Thanks

👍 1
janezj08:07:38

Above is the solution. Very elegant. I like it.

janezj08:07:21

But now I am in bigger trouble. Region must be converted to a picker, and options are on the selected company. (for [{:region/keys [id name]} (:regions company)] {:value (int id) :text name})

sheluchin09:07:42

Take a look at https://github.com/fulcrologic/fulcro-rad/blob/develop/src/main/com/fulcrologic/rad/report_options.cljc#L528=, it might be helpful along with the rest of that namespace. There are many functions in the reports that receive report-instance or something like it as an argument, and you can use (comp/props report-instance) to pull props from your report in various places as you set up the report's data display. More generally, it's worth familiarizing yourself with the various *-options namespaces as they contain the levers for making stuff happen and are not all documented in the RAD book.

❤️ 1
tony.kay22:07:29

@UQ5QFFX54 this is where you’re having trouble?

tony.kay22:07:46

selected company…as in the picker needs to be dependent on another choice?

tony.kay22:07:22

you can use po/query-parameters, which receives the app, cls, and props. It can use props to derive what to send to the server to ask for the options. The load-picker-options! function in the picker-options ns can be called from the action of the one that causes the change. E.g. you pick company, and it triggers a load of the picker options. Set the cache-time-ms to 0.

tony.kay22:07:21

So, you’d: 1. Have a resolver for the regions of a company 2. In the company picker, call load-picker-options! for the regions, where a company id is passed as a parameter (you just picked it, so you know it) where the picker-options you’d use in (2) is just a hand-coded map within that call that sets po/query-params, along with the others (e.g. po/cache-time-ms, etc)

janezj14:08:08

@U0CKQ19AQ I think that it will not work that way. Because I have a Company with the Regions already. (defsc Company [this {:company/keys [id name] :as props}] {:initial-state {:regions {}} :query [:company/id :company/name {:regions (comp/get-query Region)}] :ident :company/id}) Regions are on the company and they are loaded with companies, region resolver exists. And is called when loading companies. I have a working example - form- that I want to reproduce with report controls: { :initial-state (fn [_] {:company [:company/id 9110] :companies {} :cur-reg ""}) :query [{:company (comp/get-query lst/Company)} :cur-reg {:companies (comp/get-query lst/Company)}] :ident (fn [] [:component/id :search]) ... (sui/ui-form-group {:widths "equal"} (sui/ui-form-field {} (dom/label "Podjetje") (sui/ui-dropdown {:value (:company/id company) :selection true :disabled false :options (for [{:company/keys [id name]} companies] {:value id :text name}) :onChange (fn [_ v] (when-let [v (some-> (.-value v))] (m/set-value! this :company [:company/id v]) (m/set-value! this :cur-reg nil)))})) (sui/ui-form-field {} (dom/label "Regija") (sui/ui-dropdown {:value cur-reg :selection true :clearable true :options (for [{:region/keys [id name]} (:regions company)] {:value (int id) :text name}) :onChange (fn [_ v] (when-let [v (some-> (.-value v))] (m/set-value! this :cur-reg v)))})) I also found that I can set set regions at start, because there is no event if default value is set (no action or onChange). One situatation is really interested for me, how to prepare query parameters but not run the report, just leave it to the user to click on button.