Skip to content

Commit fe0610b

Browse files
authored
update: flow docs (#1056)
* update * update
1 parent 4e4beb0 commit fe0610b

File tree

5 files changed

+104
-6
lines changed

5 files changed

+104
-6
lines changed

changelog/2024-07-22-dynamic-select/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ features:
1212
'Conditional logic within the function to filer and sort select options based on specified conditions.',
1313
]
1414
docs: /docs/core_concepts/json_schema_and_parsing#dynamic-select
15-
video: /videos/dynamic_select.mp4
15+
video: /videos/dynamic_select_script.mp4
1616
---
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
slug: dynamic-select-flows
3+
version: v1.519.0
4+
title: Dynamic select for flows
5+
tags: ['Flow editor']
6+
description: Dynamic select functionality is now available for flow input fields, allowing dynamic options that recompute based on other inputs.
7+
features:
8+
[
9+
'Create dynamic select fields for flow input steps.',
10+
'Options recompute dynamically based on other flow input arguments.',
11+
'Support for TypeScript and Python implementations.',
12+
'Conditional logic for filtering and sorting options.',
13+
]
14+
docs: /docs/core_concepts/json_schema_and_parsing#dynamic-select
15+
video: /videos/dynamic_select_flow.mp4
16+
---

docs/core_concepts/13_json_schema_and_parsing/index.mdx

Lines changed: 87 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,11 @@ wmill script run u/user/path -d '{"example_oneof":{"label":"Option 2","attribute
235235

236236
## Dynamic select
237237

238-
Dynamic select is an helper function within [scripts](../../script_editor/index.mdx) that allows you to create a select field with dynamic options.
238+
Dynamic select is a helper function that allows you to create a select field with dynamic options that recompute based on other input values. It's available in both [scripts](../../script_editor/index.mdx) and [flows](../../flows/1_flow_editor.mdx), but with different implementation requirements.
239239

240-
You must export the string type as `DynSelect_<name>` and the function as `<name>` :
240+
### Dynamic select in scripts
241+
242+
For scripts, you must export both the string type as `DynSelect_<name>` and the function as `<name>`:
241243

242244
<Tabs className="unique-tabs">
243245
<TabItem value="typescript" label="TypeScript" attributes={{className: "text-xs p-4 !mt-0 !ml-0"}}>
@@ -290,14 +292,94 @@ def main(x: str, y: int, xy: DynSelect_foo):
290292
</TabItem>
291293
</Tabs>
292294

293-
The select options recompute dynamically based on the other arguments, in this case `x` and `y`. You can also use `text` as an arg in the function to have the current text select input be passed.
295+
### Dynamic select in flows
296+
297+
In flows, dynamic select is only available for flow input steps. You must define one function for each flow input field that is of dynamic select type. The function name must exactly match the name of the flow input field. No export type is required.
298+
299+
<Tabs className="unique-tabs">
300+
<TabItem value="typescript" label="TypeScript" attributes={{className: "text-xs p-4 !mt-0 !ml-0"}}>
301+
302+
```ts
303+
// Function for flow input field named "foo"
304+
async function foo(x: string, y: number, text: string) {
305+
if (text === '42') {
306+
return [{ value: '42', label: 'The answer to the universe' }];
307+
}
308+
if (x === 'bar') {
309+
return [{ value: 'barbar', label: 'barbarbar' }];
310+
}
311+
return [
312+
{ value: '1', label: 'Foo' + x + y },
313+
{ value: '2', label: 'Bar' },
314+
{ value: '3', label: 'Foobar' }
315+
];
316+
}
317+
318+
// If you have another dynamic select input named "category"
319+
async function category(department: string) {
320+
if (department === 'engineering') {
321+
return [
322+
{ value: 'frontend', label: 'Frontend' },
323+
{ value: 'backend', label: 'Backend' }
324+
];
325+
}
326+
return [
327+
{ value: 'general', label: 'General' }
328+
];
329+
}
330+
```
331+
332+
</TabItem>
333+
<TabItem value="python" label="Python" attributes={{className: "text-xs p-4 !mt-0 !ml-0"}}>
334+
335+
```python
336+
# Function for flow input field named "foo"
337+
def foo(x: str, y: int, text):
338+
if text == "42":
339+
return [{"value": "42", "label": "The answer to the universe"}]
340+
if x == "bar":
341+
return [{"value": "barbar", "label": "barbarbar"}]
342+
return [
343+
{ "value": '1', "label": 'Foo' + x + str(y) },
344+
{ "value": '2', "label": 'Bar' },
345+
{ "value": '3', "label": 'Foobar' }
346+
]
347+
348+
# If you have another dynamic select input named "category"
349+
def category(department: str):
350+
if department == "engineering":
351+
return [
352+
{"value": "frontend", "label": "Frontend"},
353+
{"value": "backend", "label": "Backend"}
354+
]
355+
return [
356+
{"value": "general", "label": "General"}
357+
]
358+
```
359+
360+
</TabItem>
361+
</Tabs>
362+
363+
### How dynamic select works
364+
365+
The select options recompute dynamically based on other input arguments.
366+
367+
You can implement custom filtering and sorting logic within your function. In the examples above in the foo function, when `x` equals "bar" or `text` equals "42", the options are filtered to show only one option.
368+
369+
#### Dynamic select in scripts
370+
371+
<video
372+
className="border-2 rounded-xl object-cover w-full h-full dark:border-gray-800"
373+
controls
374+
src="/videos/dynamic_select_script.mp4"
375+
/>
294376

295-
You can also do your own filtering and sorting of the options. In the example above, if `x` is "bar", the options will be filtered to only one option.
377+
#### Dynamic select in flows
296378

297379
<video
298380
className="border-2 rounded-xl object-cover w-full h-full dark:border-gray-800"
299381
controls
300-
src="/videos/dynamic_select.mp4"
382+
src="/videos/dynamic_select_flow.mp4"
301383
/>
302384

303385
## Backend schema validation

static/videos/dynamic_select_flow.mp4

9.14 MB
Binary file not shown.

0 commit comments

Comments
 (0)