|
46 | 46 | # Let's start simple: Standard dict values are detected from type and offered as entry form fields.
|
47 | 47 | # Detected types are numbers, text, boolean, lists and dicts.
|
48 | 48 | # 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. |
53 | 56 | # But of course you might want to have it nicer! Let's add some description to parameters.
|
54 | 57 | # Note if you can add any Markdown formatting to the description, you need to use the description_md
|
55 | 58 | # attribute.
|
|
62 | 65 | "of the book [The Hitchhiker's Guide to the Galaxy]"
|
63 | 66 | "(https://en.wikipedia.org/wiki/Phrases_from_The_Hitchhiker%27s_Guide_to_the_Galaxy#"
|
64 | 67 | "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", |
65 | 71 | ),
|
66 | 72 | # If you want to have a selection list box then you can use the enum feature of JSON schema
|
67 | 73 | "pick_one": Param(
|
|
70 | 76 | title="Select one Value",
|
71 | 77 | description="You can use JSON schema enum's to generate drop down selection boxes.",
|
72 | 78 | enum=[f"value {i}" for i in range(16, 64)],
|
| 79 | + section="Typed parameters with Param object", |
73 | 80 | ),
|
74 | 81 | # [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] |
75 | 140 | # You can also label the selected values via values_display attribute
|
76 | 141 | "pick_with_label": Param(
|
77 | 142 | 3,
|
|
90 | 155 | 8: "Eight",
|
91 | 156 | 9: "Nine",
|
92 | 157 | },
|
| 158 | + section="Drop-Downs and selection lists", |
93 | 159 | ),
|
94 | 160 | # If you want to have a list box with proposals but not enforcing a fixed list
|
95 | 161 | # then you can use the examples feature of JSON schema
|
|
103 | 169 | "Alpha,Bravo,Charlie,Delta,Echo,Foxtrot,Golf,Hotel,India,Juliett,Kilo,Lima,Mike,November,Oscar,Papa,"
|
104 | 170 | "Quebec,Romeo,Sierra,Tango,Uniform,Victor,Whiskey,X-ray,Yankee,Zulu"
|
105 | 171 | ).split(","),
|
| 172 | + section="Drop-Downs and selection lists", |
106 | 173 | ),
|
107 | 174 | # If you want to select multiple items from a fixed list JSON schema does not allow to use enum
|
108 | 175 | # In this case the type "array" is being used together with "examples" as pick list
|
|
112 | 179 | type="array",
|
113 | 180 | title="Multi Select",
|
114 | 181 | examples=["one", "two", "three", "four", "five"],
|
| 182 | + section="Drop-Downs and selection lists", |
115 | 183 | ),
|
116 | 184 | # A multiple options selection can also be combined with values_display
|
117 | 185 | "multi_select_with_label": Param(
|
|
127 | 195 | "3": "Three apples",
|
128 | 196 | # Note: Value display mapping does not need to be complete
|
129 | 197 | },
|
| 198 | + section="Drop-Downs and selection lists", |
130 | 199 | ),
|
131 | 200 | # An array of numbers
|
132 | 201 | "array_of_numbers": Param(
|
|
135 | 204 | type="array",
|
136 | 205 | title="Array of numbers",
|
137 | 206 | 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", |
168 | 208 | ),
|
169 | 209 | "multiline_text": Param(
|
170 | 210 | "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.", |
172 | 213 | title="Multiline text",
|
173 | 214 | type=["string", "null"],
|
174 | 215 | 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", |
223 | 217 | ),
|
224 | 218 | # Some further cool stuff as advanced options are also possible
|
225 | 219 | # You can have the user entering a dict object as a JSON with validation
|
|
0 commit comments