Fork me on GitHub
#fulcro
<
2020-05-29
>
folcon11:05:42

Really not sure what to do here: I’m constructing a favourites list, and if pathom returns this sort of thing:

{:avatar/id 354
 :avatar/favourite-items [[:item/id 7]]}
Then Fulcro silently discards :avatar/favourite-items… However if I return this:
{:avatar/id 354
 :avatar/favourite-items [{:item/id 7}]}
It doesn’t, but that’s not a valid join, so {:item/id 7} doesn’t ever resolve into anything…

tony.kay14:05:54

The former is not correct. Results of queries are maps or sequences of maps. Idents are an artifact of normalization. The latter is fine, and will normalize…but has no data (other than an id). What do you expect?

codonnell12:05:27

You should be able to continue resolution with [{:item/id 7}]. I have resolvers that return data in that shape, and they work fine.

codonnell12:05:05

Ah, never mind. I misunderstood.

codonnell12:05:06

I think if you have a component with an :item/id ident composed into the query that's causing the load, then normalization should convert [{:item/id 7}] into [[:item/id 7]]. Does that make sense?

folcon12:05:35

I was doing that I believe…

folcon12:05:23

I managed to work around it by introducing a layer of nesting… (too many layers of nesting though, this feels like a patch, not a fix) >_<…

folcon13:05:23

I’m having to do weird get-in’s all over the place to grab the data I want, which feels very much against the spirit of what I’m trying to achieve using fulcro, but I’m really unclear what to do here…

folcon13:05:10

eg:

(get-in props [[:component/id ::fav-item-list] :fav-item-list/avatar :avatar/favourite-items :items])
So that my :items can know which things are favourites, so that it can correctly render UI buttons… I could push this stuff into pathom, 🤷:skin-tone-4:?

codonnell13:05:37

I won't be able to look for a little bit, but it would be helpful to see your component queries/idents and the load you're using.

murtaza5214:05:10

@folcon it should resolve itself and do the normalization if you have structured your components as nested ones.

tony.kay14:05:33

@folcon you’re asking questions with incomplete information. I, nor anyone else, can answer these kinds of questions if we cannot see your components. We always need to see query/ident from each component to understand what to expect to happen…then you’re asking about get-in…no context…where? in the UI? You not have to do a get-in on this kind of thing in a properly structured UI

tony.kay14:05:14

And you’re stacking on the expected behavior of pathom. That’s a lot of mixing of concerns

folcon14:05:31

That’s fair, let me add in a bit of detail =)… I’m currently in the middle of a client call. But will update as soon as I can

tony.kay14:05:05

cool, yeah, otherwise we’re just guessing, and that’s frustrating in both directions 🙂

zilti14:05:45

Wow, I just used the UI State Machine for the first time now, and while I am pretty sure I haven't understood it 100% just yet, thanks for implementing that. It feels crazy to have something like that! 😄 Especially since my last project was the maintenance of a Symfony-based PHP page...

tony.kay14:05:19

@zilti glad you like it.

tony.kay14:05:34

keep them small 🙂

zilti14:05:08

Well, what is small? ^^ I ported over the login state machine from the template and plan to add TOTP to it

zilti14:05:15

It is basically screen-filling as is

tony.kay14:05:50

I just mean it’s roughly a hybrid of FSM and my own invention. Don’t write whole programs as one SM 🙂

zilti14:05:25

Ah, no, I won't do that, don't worry! But I will probably use it for things like multi-page forms

tony.kay14:05:32

but it is meant for your use-case, of course

tony.kay14:05:26

yeah, when you get to forms, look at how RAD does that.

tony.kay15:05:31

summary: if you can, load your multi-page as a single load (with form-state support), and use UI to show page by page from parent controller…then you can save it all at once and load it all at once.

tony.kay15:05:50

if they are orthogonal, then UISM is super nice for the stepwise load/save too

zilti15:05:13

form-state? Is that part of RAD? Thanks for the heads-up

tony.kay15:05:23

form-state is part of Fulcro

tony.kay15:05:35

and you should know about it, for sure.

zilti15:05:01

Ah, found it, chapter 19

zilti15:05:10

I also wondered about :select-many, it seems to exist in RAD, yet is not implemented? I will take a look at the code there over the weekend I guess

tony.kay15:05:27

select-many isn’t ringing a specific bell. Some things are definitely not implemented yet. You mean a form control that can allow you to do multi-select? I think at least one kind of that exists, but it isn’t there for everything.

zilti15:05:17

Yes, I have the case that one user can have multiple roles, so I made the roles a separate "table", and made a RoleForm that has fo/field-styles {:role/label :pick-many}. It renders the form title, but no selection field or anything. But it also doesn't give an error about it being an invalid field style.

tony.kay15:05:22

I can’t keep it all in my head…that’s why I made the demo…it uses most of what is there

zilti15:05:23

One second thought, I am not sure what kind of outcome I'd expect there...

tony.kay15:05:47

for roles, I do have a thing that generates a set of toggle buttons

zilti15:05:49

Yea. As I said, I'll probably take a look at the RAD code this weekend. Maybe it's something that just isn't finished yet

tony.kay15:05:51

don’t remember how to use it

zilti15:05:08

Ah. True, that could be a way as well

tony.kay15:05:42

this is from my prod code:

(def employee-permission-labels {:employee.permissions/pos-config   "POS Config"
                                 :employee.permissions/pos-checkout "POS Checkout"
                                 :employee.permissions/pos-settings "POS Settings"
                                 :employee.permissions/pos-refund   "POS Refund"})

(defattr permissions :employee/permissions :enum
  {ao/schema            :ucv
   ao/cardinality       :many
   fo/default-value     #{}
   ao/identities        #{:employee/id}
   ao/enumerated-values (set (keys employee-permission-labels))
   ao/enumerated-labels employee-permission-labels})

tony.kay15:05:36

no addl config…that is the default rendering for to-many enums with predefined values

tony.kay15:05:46

but for entities, I don’t have that yet, I don’t think

tony.kay15:05:49

i.e. select many from db

zilti15:05:33

Interesting! Thanks! I will need to tinker a bit anyway, because not every user is supposed to be able to give every role. The whole concept probably needs some hammock development first on my end

tony.kay15:05:30

right, at some pt you’ll get to cases where you just have to provide a plugin for your UI control

zilti15:05:05

One last thing though, somewhat unrelated: it seems no matter the URL I give it, the application always goes straight to the landing page. I am using the MainRouter from RAD-demo, and the root has as initial-state {:router {}} just like the demo. I removed all rad-auth stuff.

tony.kay15:05:20

sorry, you edit the code and break it, I can’t magically tell you what you did 🙂

tony.kay15:05:29

the demo has the bits

tony.kay15:05:56

You have to install history support (html5 in this case) and make sure you initialize it and trigger it properly.

zilti15:05:18

Oh, I assumed that's on by default in rad-demo

tony.kay15:05:32

no no…can’t be

tony.kay15:05:35

might be native app

tony.kay15:05:53

look in the post login handling…I think that’s where I read the URL and tell history to start

zilti15:05:07

Yea, then that is probably the issue. Should be an easy fix then, thanks again

zilti15:05:54

Hmm yes, it is in com.example.client/init, history/install-route-history! app (html5-history)

murtaza5216:05:07

In the rad-demo, in the account_forms.cljc, there is the AccountListItem component, however it is not used anywhere, is it dead code ? Also there is AccountList-Row component, which I see being pulled into the client DB, when inspecting it through FulcroInspect. However I dont see this component anywhere in the project. The only reference is in a comment block. So wondering how is this showing up in the client DB ?

tony.kay16:05:06

So, you can hand a report a component to use for the rows. That is there so I can swap it in and out

tony.kay16:05:43

when you don’t hand it one, it autogenerates one, which is the other one you’re seeing

murtaza5216:05:17

cool thanks that makes sense. So the AccountList-Row is the autogenerated one ?

tony.kay16:05:18

got to have a component to hold a query/ident for the rows

tony.kay16:05:30

but it is trivial to generate that if you don’t want to control the rendering of it

murtaza5216:05:23

(def account-plans {:account.plan/free "Free Plan"
                    :account.plan/plan1 "Paid Plan 1"
                    :account.plan/plan2 "Paid Plan 2"})

(defattr plan :account/plan :enum
  {ao/cardinality :one
   ao/enumerated-values (set (keys account-plans))
   ao/enumerated-labels account-plans
   ao/identities #{:account/id}
   ao/schema :production})
When I pull this attribute in the rad-report, it shows the keyand not the label, any idea what could be missing ?

tony.kay16:05:06

could be a bug

tony.kay16:05:11

in the to-one renderer

tony.kay16:05:26

remember this stuff is super young

tony.kay16:05:12

I don’t know that I’ve rendered to-one enums in a report yet 😜

murtaza5216:05:13

but it is working in the rad-demo, its almost the same code, this is similar to the role attribute in the accounts form

tony.kay16:05:42

is there a field formatter in the demo?

murtaza5216:05:57

it is there for :account/name

murtaza5216:05:03

not for role

murtaza5216:05:30

ro/field-formatters      {:account/name (fn [this v] v)}

tony.kay16:05:00

on the attr?

tony.kay16:05:13

honestly no other ideas on my part 🙂

murtaza5216:05:04

No problem, where should I look, which code is doing the rendering ?

murtaza5216:05:23

also when I click on the formlink from the report, I get this error in the console, and the form doesnt open for editing / adding new account - ERROR [com.fulcrologic.rad.routing:43] - Cannot find path for jra.ui.farm/AccountForm I have specified the route-prefix key in my form, where should I look to find the problem ?

tony.kay17:05:06

remember to add it to a router as a target

tony.kay17:05:13

routers can’t route to something they don’t know is theirs

tony.kay17:05:43

rendering is all in semantic-ui rendering plugin. Start at semantic_ui_controls.cljc and follow the rabbit down the hole

murtaza5218:05:16

thanks, that was the problem, it was not added to the router. Maybe the rendering for enums doesnt work for the report, for form it works. So just added a field formatter for the report.

murtaza5218:05:37

On the form, when it is a new entry, after pressing save button, the sate does not change, the cancelbutton does not change into done , although the new entity gets transacted on the server.

tony.kay19:05:21

proper save requires server to do proper things.

tony.kay19:05:39

tempid remap in particular.

murtaza5219:05:06

do I need to plugin a server side mutation for the save operation ?

murtaza5219:05:01

it seems the resolution did happen, this was the server response -

:com.fulcrologic.rad.form/save-form
{:account/id #uuid "7eb9913b-f32f-49fc-880a-4ee67c9c7441"
:account/name "abc"
:account/plan :account.plan/plan1}

tony.kay19:05:36

not seeing tempids in that

murtaza5220:05:35

sorry where should I look to correct the above, I have the following as my parser plugin (form/pathom-plugin save/middleware delete/middleware)

murtaza5221:05:12

found it fulcro-rad-appprovides the tempids resolver fn as a default

tony.kay22:05:15

@murtaza52 if you have a suggestion for documenting what you ran into (i.e. remember to add tempid stuff here if you do blah) I’d be interested in that going in the RAD dev guide or something

murtaza5205:05:25

@U0CKQ19AQ these are the problems I have faced - 1. There needs to be documentation regarding fulcro-rad-app that is provides the tempids resolver and second it requires the csrf token js var in the index. Preferrably both of these should not even be here, maybe a default middleware somewhere to be plugged in for the parser. Just like ring-defaults lib. 2. Documentation that Router not only requires the top level forms but also sub forms for the router to work correctly. 3. Documentation that the install-ui-contrrols provides default rendering for the form and needs to be run on init. Again preferably there needs to be a default lib, from which this can just be included. 4. this key used in models in rad-demo is invalid - :com.fulcrologic.rad.database-adapters.datomic/attribute-schema , the correct key that automated-schemauses is :com.fulcrologic.rad.database-adapters.datomic-cloud/attribute-schema. Again better if this is made a property. 5. the generated resolver for fulcro sends only the ident back for an enum attribute, this needs to be documented. I had a custom resolver which was sending back the :db/id and ident for a enum ref attribute. 6. the bug where defsc-records does not play nice with enumerated-labels for an enum attribute.