fulcro

Book: http://book.fulcrologic.com, Community Resources: https://fulcro-community.github.io/, RAD book at http://book.fulcrologic.com/RAD.html
Jakub Holý 2021-04-15T14:38:41.098700Z

So do I :-) If you search for the error under https://book.fulcrologic.com/#_appendix_fulcro_errors_and_warnings_explained, I will find it there too. I've recently made a video of how to check the graph is connected, not sure if of any help here though.

Jakub Holý 2021-04-15T14:41:40.098900Z

In RAD, I'd like to have a report with checkbox controls to show/hide some columns but I see no simple way of doing that, other than creating my own table and row components. Correct?

donavan 2021-04-15T14:50:01.101700Z

I’m busy trying to track down a bug in my app and just want to check that what I’m trying to do is supported. I have a union component that has a to many recursive collection of itself. The union component uses the correct query when in isolation but when the union component is a child it doesn’t use the correct query when its type differs from its parent. It’s denormalised using the parent’s type query.

hadils 2021-04-15T15:01:40.103400Z

I am trying to use JS async/await functions from 3rd party libraries in Fulcro. I have tried using mutations and state machine to handle the asynchrony of the call, but without success. Does anyone have any experience solving this problem? I appreciate what you can share.

hadils 2021-04-18T14:46:19.145400Z

Thanks @holyjak. I put the ImagePicker code inside. a mutation. That worked.

1👍
Jakub Holý 2021-04-15T15:24:18.104500Z

Async just returns a promise, no? Cannot you simply (.then promise #(transact this-component...))?

hadils 2021-04-15T16:02:44.104700Z

The problem is that I am integrating an image picker with a UI component. So I am trying to pick an image then display it. The image picker is async.

Jakub Holý 2021-04-15T16:51:19.105300Z

What exactly does it do? Pick an image from the disk, upload, display? Or pick an image from a list of images? What do you get from the picker, an url?

hadils 2021-04-15T16:53:38.105600Z

It picks an image from storage and returns a url, if one is picked.

hadils 2021-04-15T16:55:01.105800Z

I can't put a Promise or a go block inside a render code block. I can't put it in the event handler of a state machine either.

mruzekw 2021-04-15T17:22:07.107400Z

Hi all, I remember seeing a message here about using Fulcro via a React hook. Does anyone know where that’s documented? Thanks

Jakub Holý 2021-04-15T17:27:19.107500Z

I assume the picker is a React component that you nest in your fulcro component and that it expects that you pass it a callback it will call when the user has picked. Or?

hadils 2021-04-15T17:34:16.107700Z

I don't seem to have a callback. The React example uses await I am sure I can convert that to a callback though.

donavan 2021-04-15T18:35:23.107900Z

I see it’s actually deeper than that… reading the EQL docs it doesn’t seem to me, on first reading at least, that the semantics of recursive unions are spelt out explicitly… but how the AST is structured it seems to me that implicitly a recursive union was intended to only be of one type

donavan 2021-04-15T19:04:09.108400Z

…no, I think there isn’t an implied semantics in the AST. I think it might be in fulcro…

hadils 2021-04-15T19:07:57.108600Z

You can't have a Promise in the render body of a defsc. Any ideas?

hadils 2021-04-15T19:17:04.108800Z

Nvm, I figured it out. Just save the promise and return nil. That works.

1👍
Jakub Holý 2021-04-15T19:48:32.109100Z

BTW, if using React, have you tried https://github.com/holyjak/fulcro-troubleshooting?

Jakub Holý 2021-04-15T19:49:30.109400Z

What do you need? Use hook based instead of class based components? See the doc string of defsc and the Dev Guide

Jakub Holý 2021-04-15T19:50:55.109600Z

Using Fulcro without Fulcro components, via hooks, see the develop branch and the raw-components namespace

Jakub Holý 2021-04-15T19:51:35.109800Z

Search the code for its usages to find the examples.

hadils 2021-04-15T20:11:04.110400Z

No @holyjak. I did not solve it. Here is my code:

(defsc Photo [this {:ui/keys [photo] :as props}]
  {:ident         (fn [] [:component/id ::Photo])
   :query         (fn [] [:ui/photo])
   :initial-state (fn [photo] {:ui/photo photo})
   :route-segment ["photo"]}

  (log/debug "Photo props" props)
  (let [foo (-> (.requestMediaLibraryPermissionsAsync ImagePicker)
              (.then (fn [resp]
                       (let [granted? ^boolean (.-granted resp)]
                         (if granted?
                           (-> (.launchImageLibraryAsync ImagePicker)
                             (.then (fn [resp]
                                      (let [cancelled? ^boolean (.-cancelled resp)
                                            photo (.-uri resp)]
                                        (when-not cancelled?
                                          (log/debug "Photo uri=" photo)
                                          (n/ui-view {:style {:flex 1}}
                                            (n/ui-text {} "Hello there!!!!!!")
                                            (n/ui-image
                                              {:source {:uri photo}})
                                            (rne/ui-button {:title       "Accept"
                                                            :buttonStyle {:height 40}
                                                            :onPress     (fn [] (js/alert "You pressed the button!"))}))))))))))))]))
The code inside the .then does not render.

donavan 2021-04-15T20:19:19.113100Z

Can you not separate out the ui and promise handling code? You might need some internal state to orchestrate? I don’t think what you’re trying to do will ever work the way you want it to.

thosmos 2021-04-15T20:20:32.113900Z

I’m attempting to use ao/style :autocomplete with a RAD :string attribute, but I’m getting an error thrown Uncaught Error: Assert failed: (or (eql/ident? server-property-or-ident) (keyword? server-property-or-ident)) because the :autocomplete/search-key is nil in com.fulcrologic.rad.rendering.semantic-ui.autocomplete/AutocompleteField :initLocalState I’m setting that key in the form like:

fo/field-options {:worktime/task {:autocomplete/search-key :worktime/tasks}}
but it’s missing in the initLocalState call. I think I’m making progress on figuring this out, but maybe there’s a known problem.

thosmos 2021-04-16T20:25:40.122Z

ok, I’ll check the demo

thosmos 2021-04-16T20:33:04.122300Z

It looks like the only :autocomplete in the demo is for an :enum type, not a :string type, and it looks like it only supports having the fo/field-options on the attribute, and not on the form itself. I’ll just use it as a starting point and make my own.

thosmos 2021-04-17T00:50:57.133500Z

Putting the options on the attribute with fo/field-options eliminates the PR I made (I thought that field-options was only for forms), but the dropdown options are still not rendering into the UI, even though they’re where they should be at [::autocomplete-id id :ui/options] in the app DB. It appears that when AutocompleteFieldRoot renders, :ui/options is missing, so when it passes that as props to AutocompleteField , it never sees the :ui/options The problem seems to be here:

field              (get-in props [::autocomplete-id id])
which is null and gets passed to the instance like
(ui-autocomplete-field (assoc field
                         ::autocomplete-id id
                         :autocomplete/search-key search-key
                         :autocomplete/debounce-ms debounce-ms)

thosmos 2021-04-17T00:57:47.134400Z

thosmos 2021-04-17T01:27:54.134800Z

oooh, does this have something to do with which rendering strategy I’m using? :optimized-render! kf2/render!

thosmos 2021-04-17T03:53:45.135Z

:optimized-render! mroot/render! did it

thosmos 2021-04-18T01:12:24.143300Z

Even though it’s working now, it brings up that I think there’s some confusing different places where field-options are located. for example, here’s the let from po/load-options!

[{:com.fulcrologic.rad.form/keys [field-options]} (comp/component-options form-class)
         field-options  (get field-options qualified-key)
         picker-options (merge attribute field-options)]  
It merges field-options from the form directly into the attribute’s map, rather than into ::form/field-options consistent with what my PR change did. In other words, I think the way the :autocomplete is coded in the demo is inconsistent, and the implementation of the :autocomplete component should be changed (breaking) to get its :autocomplete/keys from either ::form/field-options on a form, or directly from the attribute map, which is consistent with everywhere else.

tony.kay 2021-04-21T23:27:13.165400Z

I don’t think there is a need to break it…just add the corrected locations as possibilities via or , where form overrides attribute, and the old location has the least precedence (or form-value correct-attr-location old-attr-location)

donavan 2021-04-15T20:20:47.114Z

The Photo component’s render method (the body of the macro) needs to return react dom constructors. You’re not even using foo in the body

hadils 2021-04-15T20:21:12.114200Z

Hi @donavan. I have tried to separate the ui and promise code. I tried a transaction, and a statemachine without success. I don't use foo, because it is an object and React was complaining about it. I am stumped as to how to separate the concerns.

donavan 2021-04-15T20:22:03.114400Z

Yeah, was just typing that promise then doesn’t return the result of the then method

donavan 2021-04-15T20:22:24.114900Z

…as far as I remember, it’s been a while since I’ve used promises

mruzekw 2021-04-15T20:22:50.115700Z

Thanks @holyjak! I was thinking the second. Using Fulcro without Fulcro components

mruzekw 2021-04-15T20:23:04.116300Z

I’ll check that namespace out, thanks

hadils 2021-04-15T20:23:46.116500Z

The problem is that the function returns immediately, then computes the result and saves it. I don't know how to deref a promise.

donavan 2021-04-15T20:24:23.116700Z

Sorry @hadilsabbagh18 I have food about to arrive but…

donavan 2021-04-15T20:24:41.116900Z

I would just keep some local state…

donavan 2021-04-15T20:25:12.117100Z

and in the .then callback update that state with whatever is in resp (it looks like it’s a URL)

1👍
donavan 2021-04-15T20:25:23.117300Z

then always return DOM from the component

donavan 2021-04-15T20:25:34.117500Z

and check whether you have a URL in the component’s local state

donavan 2021-04-15T20:27:15.117700Z

if you do, do whatver you want like displaying the image, if not show a button saying ‘upload the image’

donavan 2021-04-15T20:27:58.117900Z

I have to go sorry, will try check back later

donavan 2021-04-15T20:28:32.118100Z

You may want to find a plain React tutorial on how to build an upload button… that might help you understand what you need to do?

hadils 2021-04-15T20:31:34.118300Z

Thanks @donavan

Jakub Holý 2021-04-15T20:52:01.118700Z

It was something with raw and components, not sure about the order :)

Jakub Holý 2021-04-15T21:19:55.119100Z

As donovan says. Put the body into photo and inside the then just store the url so the photo component can see it, either in local state or in the Fulcro client db: do there something like (transact! this [(m/set-string :ui/img-url <the url>]))

hadils 2021-04-15T21:55:13.119600Z

Thanks @holyjak. How do I know when the uri is ready?

thosmos 2021-04-15T21:55:20.119800Z

I made a change that fixes the error above, so the remote call is happening, and the options are getting stored, but they’re still not showing up back in the dropdown in the browser. https://github.com/thosmos/fulcro-rad-semantic-ui/tree/bugfix/autocomplete

hadils 2021-04-15T22:05:21.120Z

I think the component will update when the transaction occurs.

1✅