Fork me on GitHub
#fulcro
<
2021-01-12
>
holyjak20:01:05

🙏 If you have any input on how to best learn Fulcro, please https://docs.google.com/document/d/1XMWwwnxtukZ0o3ev4GH2Kpa8MvX4z-r4kYKJMaMBw2A/edit?usp=sharing that I will feed back to ☝️

alex-eberts23:01:28

I’m building a simple Todo app in Fulcro RAD that has Todos organized into Projects. I have a simple RAD report that lists all Projects. Projects can have many Todos (via a ref attribute). My report’s source-attribute is :projects/all-projects, a global resolver that returns all :project/ids. My report columns are “:project/label”, “:project/project-todos” and “:todo/label” (:todo/label is a “to-many” :ref from :project/project-todos to :todo/id). When I render the report, it displays the :project/label and :project/project-todos a vector of id’s (which makes sense). However, I would like to display the :todo/labels in the report. What’s the proper way to have the report render the individual :todo/labels themselves instead of the “idents in a list” that it displays by default? Link to the c.e.model.project.cljc: https://github.com/aeberts/fulcro-rad-demo/blob/develop/src/shared/com/example/model/project.cljc And a link to the c.e.ui.project.cljc: https://github.com/aeberts/fulcro-rad-demo/blob/develop/src/shared/com/example/ui/project.cljc

tony.kay00:01:13

The trivial answer is to make a resolver on an invented property name on the back-end. The alternative is more complicated, but there are many alternatives. Is the invented propery like :project/sample-todo-labels where the resolver sends back a comma-separated string not good enough?

tony.kay00:01:47

The main alts are: • Custom BodyItem • Row query inclusions (alternate to prior, cannot be used together) with a custom column renderer.

alex-eberts01:01:18

Hi @U0CKQ19AQ I think the invented property name you suggested would work in most cases. Does the invented property need to have an associated attribute defined in the model or is defining a resolver sufficient for this approach?

alex-eberts01:01:55

For learning purposes, I’m curious about how custom BodyItem and row query inclusions would work. Is there some example code somewhere that implements that? Thanks for the info!

tony.kay01:01:24

You’ll need an attr in order to add it as a column

👍 1
tony.kay01:01:38

in CLJC, you can co-locate the resolution with the attr

tony.kay01:01:22

On the other: Reports have to have a component for the report rows. The macro, by default, generates one (with -Row as a suffix to your report component’s name). That generated row component has the query for the cols + row query inclusions and an ident based on the id attribute of the row. If you specify BodyItem then you’re making the row component. It’s just a standard Fulcro component. You specify the ident, query, etc. From there the report component will just pass you props for the row, which you can render, or you can call the helper for row rendering the that plugin uses.

tony.kay01:01:11

The macro isn’t a ton of code…for educational purposes it is probably worth reading

alex-eberts01:01:05

Ok - that makes sense. Thanks. What is the name of the macro that generates the -Row component?

tony.kay02:01:35

defsc-report 😄

tony.kay02:01:01

it generates your report component, and if you don’t tell it the row component (BodyItem), it generates that too

alex-eberts02:01:18

re: defsc-report Doh! I probably could have guessed that one..facepalm

holyjak10:01:55

@U0CKQ19AQ could you be so kind and elaborate on > Row query inclusions (alternate to prior, cannot be used together) with a custom column renderer. namely what do you mean by "a custom column renderer"? I know I can have a custom ro/column-formatters but that does not help me because I do not have a column for the child entites (todos) added via row-query-inclusion . Did you mean essentially replacing the default sui-report/render-table-row (https://github.com/fulcrologic/fulcro-rad-semantic-ui/blob/4e331c855ef681152a418ece636628adb7303e25/src/main/com/fulcrologic/rad/rendering/semantic_ui/report.cljc#L50) with a custom one, that both renders the report columns and the row-inclusion-provided todos?

tony.kay14:01:09

I mean you can do a bunch of different things. There are escape hatches everywhere. You can customize render of a column with column formatters, you can take over row query/ident/rendering with BodyItem, you can take over the entire rendering of the table by supplying a body, etc. The generated row component generates a query. Read the macro. See where row-query-inclusions is used? See where BodyItem overrides the generated one? It’s pretty straightforward in the code I think. The rendering plugin doesn’t have many constraints from RAD itself (other than a basic entry point). I wrote SUI renderers one way, but there is definitely room to do it others.

holyjak16:01:18

Thank you. I did have a look at the code. My understanding it: 1. I can add the data using row-query-inclusion but then I cannot use column-formatters to show them - because on which column would I do that? There is no column for the data, it was added via query inclusion. Unless I add a dummy attribute and take over its column with a custom column formatter that would render the data from the query inclusion there. 2. Or I can have specify a ro/BodyItem with the desirable query and e.g. a custom row rendering to display them. 3. (I'm sure there are other, though perhaps more involved, solutions, such as completely replacing the report layout) Is that correct?