Skip to content

Commit f175332

Browse files
committed
Rework Params UI Utuorial DAG
1 parent 49d33b6 commit f175332

File tree

1 file changed

+77
-83
lines changed

1 file changed

+77
-83
lines changed

airflow/example_dags/example_params_ui_tutorial.py

Lines changed: 77 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,13 @@
4646
# Let's start simple: Standard dict values are detected from type and offered as entry form fields.
4747
# Detected types are numbers, text, boolean, lists and dicts.
4848
# Note that such auto-detected parameters are treated as optional (not required to contain a value)
49-
"x": 3,
50-
"text": "Hello World!",
51-
"flag": False,
52-
"a_simple_list": ["one", "two", "three", "actually one value is made per line"],
49+
"number_param": 3,
50+
"text_param": "Hello World!",
51+
"bool_param": False,
52+
"list_param": ["one", "two", "three", "actually one value is made per line"],
53+
"dict_param": {"key": "value"},
54+
# You can arrange the entry fields in sections so that you can have a better overview for the user
55+
# Therefore you can add the "section" attribute.
5356
# But of course you might want to have it nicer! Let's add some description to parameters.
5457
# Note if you can add any Markdown formatting to the description, you need to use the description_md
5558
# attribute.
@@ -62,6 +65,9 @@
6265
"of the book [The Hitchhiker's Guide to the Galaxy]"
6366
"(https://en.wikipedia.org/wiki/Phrases_from_The_Hitchhiker%27s_Guide_to_the_Galaxy#"
6467
"The_Answer_to_the_Ultimate_Question_of_Life,_the_Universe,_and_Everything_is_42).",
68+
minimum=0,
69+
maximum=128,
70+
section="Typed parameters with Param object",
6571
),
6672
# If you want to have a selection list box then you can use the enum feature of JSON schema
6773
"pick_one": Param(
@@ -70,8 +76,67 @@
7076
title="Select one Value",
7177
description="You can use JSON schema enum's to generate drop down selection boxes.",
7278
enum=[f"value {i}" for i in range(16, 64)],
79+
section="Typed parameters with Param object",
7380
),
7481
# [END section_1]
82+
# Boolean as proper parameter with description
83+
"bool": Param(
84+
True,
85+
type="boolean",
86+
title="Please confirm",
87+
description="A On/Off selection with a proper description.",
88+
section="Typed parameters with Param object",
89+
),
90+
# Dates and Times are also supported
91+
"date_time": Param(
92+
f"{datetime.date.today()}T{datetime.time(hour=12, minute=17, second=00)}+00:00",
93+
type="string",
94+
format="date-time",
95+
title="Date-Time Picker",
96+
description="Please select a date and time, use the button on the left for a pop-up calendar.",
97+
section="Typed parameters with Param object",
98+
),
99+
"date": Param(
100+
f"{datetime.date.today()}",
101+
type="string",
102+
format="date",
103+
title="Date Picker",
104+
description="Please select a date, use the button on the left for a pop-up calendar. "
105+
"See that here are no times!",
106+
section="Typed parameters with Param object",
107+
),
108+
"time": Param(
109+
f"{datetime.time(hour=12, minute=13, second=14)}",
110+
type=["string", "null"],
111+
format="time",
112+
title="Time Picker",
113+
description="Please select a time, use the button on the left for a pop-up tool.",
114+
section="Typed parameters with Param object",
115+
),
116+
# Fields can be required or not. If the defined fields are typed they are getting required by default
117+
# (else they would not pass JSON schema validation) - to make typed fields optional you must
118+
# permit the optional "null" type.
119+
# You can omit a default value if the DAG is triggered manually
120+
# [START section_2]
121+
"required_field": Param(
122+
# In this example we have no default value
123+
# Form will enforce a value supplied by users to be able to trigger
124+
type="string",
125+
title="Required text field",
126+
minLength=10,
127+
maxLength=30,
128+
description="This field is required. You can not submit without having text in here.",
129+
section="Typed parameters with Param object",
130+
),
131+
"optional_field": Param(
132+
"optional text, you can trigger also w/o text",
133+
type=["null", "string"],
134+
title="Optional text field",
135+
description_md="This field is optional. As field content is JSON schema validated you must "
136+
"allow the `null` type.",
137+
section="Typed parameters with Param object",
138+
),
139+
# [END section_2]
75140
# You can also label the selected values via values_display attribute
76141
"pick_with_label": Param(
77142
3,
@@ -90,6 +155,7 @@
90155
8: "Eight",
91156
9: "Nine",
92157
},
158+
section="Drop-Downs and selection lists",
93159
),
94160
# If you want to have a list box with proposals but not enforcing a fixed list
95161
# then you can use the examples feature of JSON schema
@@ -103,6 +169,7 @@
103169
"Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliett,Kilo,Lima,Mike,November,Oscar,Papa,"
104170
"Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,X-ray,Yankee,Zulu"
105171
).split(","),
172+
section="Drop-Downs and selection lists",
106173
),
107174
# If you want to select multiple items from a fixed list JSON schema does not allow to use enum
108175
# In this case the type "array" is being used together with "examples" as pick list
@@ -112,6 +179,7 @@
112179
type="array",
113180
title="Multi Select",
114181
examples=["one", "two", "three", "four", "five"],
182+
section="Drop-Downs and selection lists",
115183
),
116184
# A multiple options selection can also be combined with values_display
117185
"multi_select_with_label": Param(
@@ -127,6 +195,7 @@
127195
"3": "Three apples",
128196
# Note: Value display mapping does not need to be complete
129197
},
198+
section="Drop-Downs and selection lists",
130199
),
131200
# An array of numbers
132201
"array_of_numbers": Param(
@@ -135,91 +204,16 @@
135204
type="array",
136205
title="Array of numbers",
137206
items={"type": "number"},
138-
),
139-
# Boolean as proper parameter with description
140-
"bool": Param(
141-
True,
142-
type="boolean",
143-
title="Please confirm",
144-
description="A On/Off selection with a proper description.",
145-
),
146-
# Dates and Times are also supported
147-
"date_time": Param(
148-
f"{datetime.date.today()}T{datetime.time(hour=12, minute=17, second=00)}+00:00",
149-
type="string",
150-
format="date-time",
151-
title="Date-Time Picker",
152-
description="Please select a date and time, use the button on the left for a pop-up calendar.",
153-
),
154-
"date": Param(
155-
f"{datetime.date.today()}",
156-
type="string",
157-
format="date",
158-
title="Date Picker",
159-
description="Please select a date, use the button on the left for a pop-up calendar. "
160-
"See that here are no times!",
161-
),
162-
"time": Param(
163-
f"{datetime.time(hour=12, minute=13, second=14)}",
164-
type=["string", "null"],
165-
format="time",
166-
title="Time Picker",
167-
description="Please select a time, use the button on the left for a pop-up tool.",
207+
section="Special advanced stuff with form fields",
168208
),
169209
"multiline_text": Param(
170210
"A multiline text Param\nthat will keep the newline\ncharacters in its value.",
171-
description="This field allows for multiline text input. The returned value will be a single with newline (\\n) characters kept intact.",
211+
description="This field allows for multiline text input. The returned value will be a single "
212+
"with newline (\\n) characters kept intact.",
172213
title="Multiline text",
173214
type=["string", "null"],
174215
format="multiline",
175-
),
176-
# Fields can be required or not. If the defined fields are typed they are getting required by default
177-
# (else they would not pass JSON schema validation) - to make typed fields optional you must
178-
# permit the optional "null" type.
179-
# You can omit a default value if the DAG is triggered manually
180-
# [START section_2]
181-
"required_field": Param(
182-
# In this example we have no default value
183-
# Form will enforce a value supplied by users to be able to trigger
184-
type="string",
185-
title="Required text field",
186-
description="This field is required. You can not submit without having text in here.",
187-
),
188-
"optional_field": Param(
189-
"optional text, you can trigger also w/o text",
190-
type=["null", "string"],
191-
title="Optional text field",
192-
description_md="This field is optional. As field content is JSON schema validated you must "
193-
"allow the `null` type.",
194-
),
195-
# [END section_2]
196-
# You can arrange the entry fields in sections so that you can have a better overview for the user
197-
# Therefore you can add the "section" attribute.
198-
# The benefit of the Params class definition is that the full scope of JSON schema validation
199-
# can be leveraged for form fields and they will be validated before DAG submission.
200-
"checked_text": Param(
201-
"length-checked-field",
202-
type="string",
203-
title="Text field with length check",
204-
description_md="""This field is required. And you need to provide something between 10 and 30
205-
characters. See the JSON
206-
[schema description (string)](https://json-schema.org/understanding-json-schema/reference/string.html)
207-
for more details""",
208-
minLength=10,
209-
maxLength=30,
210-
section="JSON Schema validation options",
211-
),
212-
"checked_number": Param(
213-
100,
214-
type="number",
215-
title="Number field with value check",
216-
description_md="""This field is required. You need to provide any number between 64 and 128.
217-
See the JSON
218-
[schema description (numbers)](https://json-schema.org/understanding-json-schema/reference/numeric.html)
219-
for more details""",
220-
minimum=64,
221-
maximum=128,
222-
section="JSON Schema validation options",
216+
section="Special advanced stuff with form fields",
223217
),
224218
# Some further cool stuff as advanced options are also possible
225219
# You can have the user entering a dict object as a JSON with validation

0 commit comments

Comments
 (0)