diff --git a/packages/grafana-ui/src/components/Forms/Checkbox.tsx b/packages/grafana-ui/src/components/Forms/Checkbox.tsx index 1802382d588..74716ec57d5 100644 --- a/packages/grafana-ui/src/components/Forms/Checkbox.tsx +++ b/packages/grafana-ui/src/components/Forms/Checkbox.tsx @@ -12,7 +12,7 @@ export interface CheckboxProps extends Omit, 'value' /** Label to display next to checkbox */ label?: string; /** Description to display under the label */ - description?: string; + description?: string | React.ReactElement; /** Current value of the checkbox */ value?: boolean; /** htmlValue allows to specify the input "value" attribute */ diff --git a/public/app/features/auth-config/AuthProvidersListPage.tsx b/public/app/features/auth-config/AuthProvidersListPage.tsx index 53d31756529..77acdcc2c01 100644 --- a/public/app/features/auth-config/AuthProvidersListPage.tsx +++ b/public/app/features/auth-config/AuthProvidersListPage.tsx @@ -75,8 +75,8 @@ export const AuthConfigPageUnconnected = ({ ) : ( {providerList - // Temporarily filter providers that don't have the UI implemented - .filter(({ provider }) => !['grafana_com', 'generic_oauth'].includes(provider)) + // Temporarily filter out providers that don't have the UI implemented + .filter(({ provider }) => !['grafana_com'].includes(provider)) .map(({ provider, settings }) => ( , 'register' | 'control' | 'watch' | 'setValue' | 'unregister'> { + field: SSOSettingsField; + errors: UseFormReturn['formState']['errors']; + secretConfigured: boolean; +} + +export const FieldRenderer = ({ + field, + register, + errors, + watch, + setValue, + control, + unregister, + secretConfigured, +}: FieldRendererProps) => { + const [isSecretConfigured, setIsSecretConfigured] = useState(secretConfigured); + const isDependantField = typeof field !== 'string'; + const name = isDependantField ? field.name : field; + const parentValue = isDependantField ? watch(field.dependsOn) : null; + const fieldData = fieldMap[name]; + const theme = useTheme2(); + // Unregister a field that depends on a toggle to clear its data + useEffect(() => { + if (isDependantField) { + if (!parentValue) { + unregister(name); + } + } + }, [unregister, name, parentValue, isDependantField]); + + if (!field) { + console.log('missing field:', name); + return null; + } + + // Dependant field means the field depends on another field's value and shouldn't be rendered if the parent field is false + if (isDependantField) { + const parentValue = watch(field.dependsOn); + if (!parentValue) { + return null; + } + } + const fieldProps = { + label: fieldData.label, + required: !!fieldData.validation?.required, + invalid: !!errors[name], + error: fieldData.validation?.message, + key: name, + description: fieldData.description, + defaultValue: fieldData.defaultValue, + }; + + switch (fieldData.type) { + case 'text': + return ( + + + + ); + case 'secret': + return ( + + ( + { + setIsSecretConfigured(false); + setValue(name, ''); + }} + /> + )} + /> + + ); + case 'select': + const watchOptions = watch(name); + let options = fieldData.options; + + if (!fieldData.options?.length) { + options = isSelectableValue(watchOptions) ? watchOptions : [{ label: '', value: '' }]; + } + return ( + + { + return ( + - - ); - case 'secret': - return ( - - ( - { - setIsSecretConfigured(false); - setValue(name, ''); - }} - /> - )} - /> - - ); - case 'select': - const watchOptions = watch(name); - const options = isSelectableValue(watchOptions) ? watchOptions : [{ label: '', value: '' }]; - return ( - - { - return ( -