import React, { useMemo } from 'react'; import FormGroup from 'Components/Form/FormGroup'; import FormInputGroup from 'Components/Form/FormInputGroup'; import FormLabel from 'Components/Form/FormLabel'; import { FieldSelectOption } from 'typings/Field'; import { InputChanged } from 'typings/inputs'; import { Failure } from 'typings/pending'; interface ProviderFieldFormGroupProps { advancedSettings: boolean; name: string; label: string; helpText?: string; helpTextWarning?: string; helpLink?: string; placeholder?: string; value?: T; type: string; advanced: boolean; hidden?: string; isDisabled?: boolean; provider?: string; providerData?: object; pending: boolean; errors: Failure[]; warnings: Failure[]; selectOptions?: FieldSelectOption[]; selectOptionsProviderAction?: string; onChange: (change: InputChanged) => void; } function ProviderFieldFormGroup({ advancedSettings = false, name, label, helpText, helpTextWarning, helpLink, placeholder, value, type: providerType, advanced, hidden, pending, errors, warnings, selectOptions, selectOptionsProviderAction, onChange, ...otherProps }: ProviderFieldFormGroupProps) { const type = useMemo(() => { switch (providerType) { case 'captcha': return 'captcha'; case 'checkbox': return 'check'; case 'device': return 'device'; case 'keyValueList': return 'keyValueList'; case 'password': return 'password'; case 'number': return 'number'; case 'path': return 'path'; case 'filePath': return 'path'; case 'select': if (selectOptionsProviderAction) { return 'dynamicSelect'; } return 'select'; case 'seriesTag': return 'seriesTag'; case 'tag': return 'textTag'; case 'tagSelect': return 'tagSelect'; case 'textbox': return 'text'; case 'oAuth': return 'oauth'; case 'rootFolder': return 'rootFolderSelect'; case 'qualityProfile': return 'qualityProfileSelect'; default: return 'text'; } }, [providerType, selectOptionsProviderAction]); const selectValues = useMemo(() => { if (!selectOptions) { return; } return selectOptions.map((option) => { return { key: option.value, value: option.name, hint: option.hint, }; }); }, [selectOptions]); if (hidden === 'hidden' || (hidden === 'hiddenIfNotSet' && !value)) { return null; } return ( {label} ); } export default ProviderFieldFormGroup;