Trouble with react final form FieldArray, listeners and displaying data from api call outside of form - react-final-form

I want to trigger an API call to fetch some supplemental data and display it alongside my react final form. What's the best way to do this?
I've started by using OnChange from react-final-form-listeners to listen for a field change and make an API call, but I don't really know how to store this data somewhere and display it within the react-final-form framework. Using a functional component and a State hook, it would be relatively trivial, because I would just set the state of a variable and then display it somewhere in the same component. Is this a sign that I should be storing these kinds of things in redux? Can I use hooks instead?
I forked one of the examples and added what I am trying to do:
https://codesandbox.io/embed/react-final-form-field-arrays-k9pqm

You're talking a little too abstractly about your goal here, but sure, you could keep the loaded data in state with a useState() hook. If I were you, I'd want to debounce it, and keep track of whether or not the Promise from your API call was the Promise from the last call or not.

Related

What is the best way to assign incoming task (SMS, call, chat) to a person based on custom logic?

I need to create a rule in Twilio Flex to assign incoming calls, SMS, chat messages to different people based on a custom rule in our existing system, e.g. make a GET request to our backend and decide based on the returned response.
Is this possible to implement with Twilio Flex? What is the best way to do it?
I would prefer to keep as much logic as possible on our server, to avoid all the button clicking and drag&dropping widgets around and to keep it in VCS.
I solved the problem by using a Twilio Function in Studio.
When a call comes in to Studio, it makes an API call via the function that returns some custom JSON data (e.g. assignedWorkerEmail). Then I can pass this data to the Send To Flex widget, which adds that data to its task's attributes. Further routing within Flex happens based on the task attributes.

Is there a way to create a global variable from a firestore Stream<DocumentSnapshot> that updates itself?

I'm making an e commerce app and have all the prices in a Map in firestore. I was looking forward to make a global variable that can be accessed from every part of the app and that updates if there's a change in the database.
What I'm trying to avoid is using StreamBuilder everytime I need to access a price.
I'm been trying to come up with a solution but every way I've found of dealing with firestore is using the StreamBuilder method, and I can't find a way of turning that into a variable.
I know my explanation may have been a little messy. But basically what Im trying to do is " Map price = 'Map in firestore' "
Any ideas? I'm new in flutter, so thanks to everyone in advance!
Yes, you have to use StreamBuilder in everywhere if you want reactive widgets. Because if the data update itself, so your widget has state, because of that you need a StatefulWidget(StreamBuilder is a StatefulWidget).
Imagine you get the variable you want, even so you'll still need a StreamBuilder similars like FutureBuilder or ScopedModelDescendant(if you use ScopedModel) or Provider(if you use provider package) and the list is go on depending on which package you use...
Don't be afraid of using them. If you make rest of the page StatelessWidget, you won't notice any performance issue probably.
You can use Inherited Widgets.
Watch this video:
https://www.youtube.com/watch?v=Zbm3hjPjQMk
You can read the data when your App starts using BLoC to separate the data from the UI. It is explained here:
https://www.youtube.com/watch?v=fahC3ky_zW0

Umbraco automatic update

I need some help with umbraco.
Let's say that I have an umbraco grid with a custom editor, just like the one in this tutorial: https://our.umbraco.com/documentation/Getting-Started/Backoffice/Property-Editors/Built-in-Property-Editors/Grid-Layout/build-your-own-editor
Ok, so I wrote this editor to build a gallery of items with image/title, I get the item list from an api call made by an angular service and this works fine when I publish the page by hand. What I want is to automatically update this gallery with new items where available, so my idea was to make a timed ajax call, let's say every hour, to update the items. But sadly this doesn't work, I suppose that the call is made but the list isn't updated.
Any suggestion? Thanks
You need to handle this differently. Right now it sounds like what you have is an implementation that works when you are browsing to this node in the backoffice using your browser and the browser makes the API calls through Angular. This all happens in your UI and when you manually hit save/publish - the data in the UI gets saved. Keep in mind that this is basically your browser doing the "work" - and this (and all other Angular code) will of course only ever run while your browser is open, in the backoffice, viewing this node.
What you want to do is to have this run automatically (and preferably in some sort of background task) to ensure that you do not really have to open up the backoffice for this to actually be automatically updated over time.
You need to create some sort of background job running on the server-side instead. This would have to be done in C# and I would recommend looking into Hangfire or Quartz frameworks to handle all the scheduling/making sure the job runs.
This job/task should do the external API calls in C# and transform the result into the same format as the format you are saving when you save data from the manual update. Then fetch the content nodes you need to update using the ContentService API and update the specific property values on those nodes. When this is done you need to make sure the changes are saved and the node is then republished with its updated data. All of this is done through the ContentService.

How to update Relay store without pushing to server

I have a form in my React/Relay app that I am using to modify some fields. I don't want to send a server update every time a new letter is typed into an input. How can I use Relay to support the application state without always pushing to the server? Having read through most of the Relay docs it seems to me that I have to basically copy the Relay state either to the local state of my form or to some other Flux store, deal with changing it in there, and then commit it into Relay. That seems like a lot of extra work though just to keep a local state.
Relay current version is a glue between graphQL and React, it only handles the data from server.
...it seems to me that I have to basically copy the Relay state either
to the local state of my form...
I fail to see the problem. The way React works, requires you to store state for the whole form or for each input separately anyway.
If you add edit functionality (render form and fetch data to populate inputs for user to change them), all the Relay data is available as this.props.RelayFragmentName on form level anyway.
You pass it down to inputs where you assign it to state and circle is complete. You could also feed inputs directly from props (without assigning data to input state) and change form state from inputs via methods.
Now when user makes the changes and confirms it, you'll just collect all the state again to make a mutation.
I see it as a complete circle that is basically unbreakable if all the defaults are set.
Relay has imperative API to get, add or update cache directly but it's relatively dirty and rarely used (especially for local state). It's used for features like WebSockets where you want to push updates from server to client and update cache manually.
Current Relay is meant to work with server data only. Relay 2 has a local cache but it's not out yet.
If we're talking about different things or you could use some code samples, let me know.
In relay modern you can use commitLocalUpdate to do that.
For example
onEmailChange = (email) => {
commitLocalUpdate(environment, (proxy) => {
const userProxy = proxy.get(this.props.user.__id);
userProxy.setValue(email, 'email');
});
}

Write in the Database from within the database

Hopefully the title is clear, I couldn't find a better name but if someone can improve it please update it, thanks.
I would like the Firebase database to write on a node if a certain condition is met. For example, if one node receives an input from a client (say an angular app) then another node in the database should write certain data, something like a callback that is fired when a node receives some data.
I know there are 4 rule types (.read .write .validate .indexOn), what I am thinking of is some kind of .callback rule that is fired and writes on a node after some other node has received an input.
Obviously this can be achieved via a server side script but Firebase is about a server-less approach so I am trying to understand what are its current limits and what I can do with it.
Thanks for your responses
firebaser here
Running the multi-location update client-side or on a server-side process that you control are currently the only ways to accomplish this.
There is currently no way to trigger updates based on modifications to the database on Firebase servers. It is no big secret that we've been working on such functionality for a while now, but we have made no announcement as to when that will be available.
Also see Can I host a listener on Firebase?, which (I realize now) is probably a duplicate.

Resources