andness
andness•11mo ago

I'm struggling a bit with something that

I'm struggling a bit with something that feels like it should be very easy to achieve in the app editor, maybe someone here can help? I have created a bunch of input fields (22, actually) and a button. When the button is pressed I want to invoke a flow. But to send the right parameters to the flow I need to transform the values from all the input components into a single workflow parameter. So one of the parameters to the workflow should be something like:
{"prop1": input1.result, "prop2".input2.result, ...}
{"prop1": input1.result, "prop2".input2.result, ...}
(It's a bit more involved than that, I want to check which values have changed from the values I originally loaded, and only send the ones that have changed, but the point is that I need to make a frontend function call to create the workflow parameters)
23 Replies
andness
andnessOP•11mo ago
I found one way to do this but it feels very hacky: The button runs an inline (frontend) script which prepares the parameter and stores it into the state, and then the flow has been added as a background runnable that is fired on success of the button. The workflow then picks the parameter from the state. This feels overly convoluted though, and it means that the button doesn't show the "loading" state for more than a split second and you have no idea that there's a job running... I thought I had it, I created a container for the inputs with the "container is a group" option, and then I used the group fields to remap. But alas, when I try to pass the group value as a parameter to the flow it seems it gets discarded, the flow receives nothing. 😞
rubenf
rubenf•11mo ago
why not have the button be tied to the flow itself ?
andness
andnessOP•11mo ago
Because I can't construct the right parameter, I basically need the equivalent of a transformer, but executed before the flow to transform the fields in my frontend to the right parameter to my flow.
rubenf
rubenf•11mo ago
but the inputs of your flow can be eval
andness
andnessOP•11mo ago
Yeah but it's 22 fields, and I also want to check the values agains the original values I loaded (which I can keep in state) to only send over the values that have changed.
rubenf
rubenf•11mo ago
then have those be connected to your background runnable result that changes upon any form changes
andness
andnessOP•11mo ago
If I try to eval it I get a string, so {"prop1": "${input1.result}"} becomes a string, not an object
rubenf
rubenf•11mo ago
what about {prop1: input1.result} ?
andness
andnessOP•11mo ago
Hm, let me see Hm, it's I write return {prop1: input1.result} and it gets accepted, but no value gets sent to the flow. Even though it previews the right value. I'll try creating something similiar in the app.windmill
rubenf
rubenf•11mo ago
i'm not sure why you have an object
rubenf
rubenf•11mo ago
this is what it should look like:
No description
andness
andnessOP•11mo ago
Yeah but the input needs to be a remapping of all those fields. The flow has 1 argument that should be an object, the input app has 22 fields that I need to map into that object. I just recreated it on app.windmill and nothing gets sent to the flow https://app.windmill.dev/apps/edit/u/andness/call_with_obj
rubenf
rubenf•11mo ago
what workspace is it ?
andness
andnessOP•11mo ago
Not sure, I just signed up to try to reproduce the bugs some time ago "demo" Not sure if you have access to stuff I create on my user there? Maybe I have to share it somehow?
rubenf
rubenf•11mo ago
No description
rubenf
rubenf•11mo ago
works fine for me
andness
andnessOP•11mo ago
Uh? When you look at the debug runs you get an object passed to the flow?
rubenf
rubenf•11mo ago
i mean I had to fix your code you wrote result instead of b.result yes once your code is correct it works
rubenf
rubenf•11mo ago
No description
andness
andnessOP•11mo ago
Ah, maybe I have some similiar typo on my local version then. But ... wait so the code in that eval can be an arbitrarily complex js? Like I could write loops and all in there as long as I return something in the end? No seems to be pretty limited. But I might be able to move the remaining processing to the flow itself. Ah, return (function() { ... })() works 🥳 Thanks @rubenf !
rubenf
rubenf•11mo ago
no you can write arbitrary complex js just write a return at the end otherwise eval get confused
andness
andnessOP•11mo ago
Hmmm, I have to wrap them in a "lambda" like above. I updated my app to demonstrate. On the "c" button I have:
const props = {"a": a.result, "b": b.result, "c": 23}
return props
const props = {"a": a.result, "b": b.result, "c": 23}
return props
And on the "d" button I have:
return (function() {
var retval = {"a": a.result, "b": b.result, "c": 23};
return retval
})()
return (function() {
var retval = {"a": a.result, "b": b.result, "c": 23};
return retval
})()
And only d works
rubenf
rubenf•11mo ago
i think there is a little bug I will fix it thanks for the report