({
name,
nodeData,
value,
onSelect,
isCreateNewOption,
onCreateNew,
credentialNames = [],
disabled = false,
freeSolo = false,
disableClearable = false,
multiple = false,
fullWidth = false
})
| 61 | } |
| 62 | |
| 63 | export const AsyncDropdown = ({ |
| 64 | name, |
| 65 | nodeData, |
| 66 | value, |
| 67 | onSelect, |
| 68 | isCreateNewOption, |
| 69 | onCreateNew, |
| 70 | credentialNames = [], |
| 71 | disabled = false, |
| 72 | freeSolo = false, |
| 73 | disableClearable = false, |
| 74 | multiple = false, |
| 75 | fullWidth = false |
| 76 | }) => { |
| 77 | const customization = useSelector((state) => state.customization) |
| 78 | const theme = useTheme() |
| 79 | |
| 80 | const [open, setOpen] = useState(false) |
| 81 | const [options, setOptions] = useState([]) |
| 82 | const [loading, setLoading] = useState(false) |
| 83 | const findMatchingOptions = (options = [], value) => { |
| 84 | if (multiple) { |
| 85 | let values = [] |
| 86 | if ('choose an option' !== value && value && typeof value === 'string') { |
| 87 | values = JSON.parse(value) |
| 88 | } else { |
| 89 | values = value |
| 90 | } |
| 91 | return options.filter((option) => values.includes(option.name)) |
| 92 | } |
| 93 | return options.find((option) => option.name === value) |
| 94 | } |
| 95 | const getDefaultOptionValue = () => (multiple ? [] : '') |
| 96 | const addNewOption = [{ label: '- Create New -', name: '-create-' }] |
| 97 | let [internalValue, setInternalValue] = useState(value ?? 'choose an option') |
| 98 | const { reactFlowInstance } = useContext(flowContext) |
| 99 | |
| 100 | const fetchCredentialList = async () => { |
| 101 | try { |
| 102 | let names = '' |
| 103 | if (credentialNames.length > 1) { |
| 104 | names = credentialNames.join('&credentialName=') |
| 105 | } else { |
| 106 | names = credentialNames[0] |
| 107 | } |
| 108 | const resp = await credentialsApi.getCredentialsByName(names) |
| 109 | if (resp.data) { |
| 110 | const returnList = [] |
| 111 | for (let i = 0; i < resp.data.length; i += 1) { |
| 112 | const data = { |
| 113 | label: resp.data[i].name, |
| 114 | name: resp.data[i].id |
| 115 | } |
| 116 | returnList.push(data) |
| 117 | } |
| 118 | return returnList |
| 119 | } |
| 120 | } catch (error) { |
nothing calls this directly
no test coverage detected