Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 17.8k
Connect Trigger UI Conf with the flexible form#45790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
310e7cacc2071d98dbbf357835740f496a9faa7c95ef543baa8ee2d0aa50c808f72753395c6c10263641dc524bc1854af9d841853e3dba24de891d995bffeacca1b9dd9cbdf5770f039cca09fcFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -16,10 +16,11 @@ | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| import { Select as ReactSelect } from "chakra-react-select"; | ||
| import { type MultiValue, Select as ReactSelect } from "chakra-react-select"; | ||
| import { useState } from "react"; | ||
| import type { FlexibleFormElementProps } from "."; | ||
| import { paramPlaceholder, useParamStore } from "../TriggerDag/useParamStore"; | ||
| const labelLookup = (key: string, valuesDisplay: Record<string, string> | undefined): string => { | ||
| if (valuesDisplay && typeof valuesDisplay === "object") { | ||
| @@ -29,7 +30,11 @@ const labelLookup = (key: string, valuesDisplay: Record<string, string> | undefi | ||
| return key; | ||
| }; | ||
| export const FieldMultiSelect = ({ name, param }: FlexibleFormElementProps) => { | ||
| export const FieldMultiSelect = ({ name }: FlexibleFormElementProps) => { | ||
| const { paramsDict, setParamsDict } = useParamStore(); | ||
| const param = paramsDict[name] ?? paramPlaceholder; | ||
jscheffl marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| // Initialize `selectedOptions` directly from `paramsDict` | ||
| const [selectedOptions, setSelectedOptions] = useState( | ||
| Array.isArray(param.value) | ||
| ? (param.value as Array<string>).map((value) => ({ | ||
| @@ -39,14 +44,35 @@ export const FieldMultiSelect = ({ name, param }: FlexibleFormElementProps) => { | ||
| : [], | ||
| ); | ||
| // Handle changes to the select field | ||
| const handleChange = ( | ||
| newValue: MultiValue<{ | ||
| label: string; | ||
| value: string; | ||
| }>, | ||
| ) => { | ||
| const updatedOptions = [...newValue]; | ||
| setSelectedOptions(updatedOptions); | ||
| // "undefined" values are removed from params, so we set it to null to avoid falling back to DAG defaults. | ||
| // eslint-disable-next-line unicorn/no-null | ||
| const newValueArray = updatedOptions.length ? updatedOptions.map((option) => option.value) : null; | ||
| if (paramsDict[name]) { | ||
| paramsDict[name].value = newValueArray; | ||
| } | ||
| setParamsDict(paramsDict); | ||
bbovenzi marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| }; | ||
| return ( | ||
| <ReactSelect | ||
| aria-label="Select one or multiple values" | ||
| id={`element_${name}`} | ||
| isClearable | ||
| isMulti | ||
| name={`element_${name}`} | ||
| onChange={(newValue) => setSelectedOptions([...newValue])} | ||
| onChange={handleChange} | ||
| options={ | ||
| param.schema.examples?.map((value) => ({ | ||
| label: labelLookup(value, param.schema.values_display), | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.