import React, { FunctionComponent, FormEvent, useMemo, useState } from 'react'; import { config } from '@grafana/runtime'; import { InlineField, InlineFieldRow, InlineSwitch, Input } from '@grafana/ui'; import { HttpSettingsBaseProps } from '@grafana/ui/src/components/DataSourceSettings/types'; import { KnownAzureClouds, AzureCredentials } from './AzureCredentials'; import { getCredentials, updateCredentials } from './AzureCredentialsConfig'; import { AzureCredentialsForm } from './AzureCredentialsForm'; export const AzureAuthSettings: FunctionComponent = (props: HttpSettingsBaseProps) => { const { dataSourceConfig, onChange } = props; const [overrideAudienceAllowed] = useState( config.featureToggles.prometheusAzureOverrideAudience || !!dataSourceConfig.jsonData.azureEndpointResourceId ); const [overrideAudienceChecked, setOverrideAudienceChecked] = useState( !!dataSourceConfig.jsonData.azureEndpointResourceId ); const credentials = useMemo(() => getCredentials(dataSourceConfig), [dataSourceConfig]); const onCredentialsChange = (credentials: AzureCredentials): void => { onChange(updateCredentials(dataSourceConfig, credentials)); }; const onOverrideAudienceChange = (ev: FormEvent): void => { setOverrideAudienceChecked(ev.currentTarget.checked); if (!ev.currentTarget.checked) { onChange({ ...dataSourceConfig, jsonData: { ...dataSourceConfig.jsonData, azureEndpointResourceId: undefined }, }); } }; const onResourceIdChange = (ev: FormEvent): void => { if (overrideAudienceChecked) { onChange({ ...dataSourceConfig, jsonData: { ...dataSourceConfig.jsonData, azureEndpointResourceId: ev.currentTarget.value }, }); } }; return ( <>
Azure Authentication
{overrideAudienceAllowed && ( <>
Azure Configuration
{overrideAudienceChecked && ( )}
)} ); }; export default AzureAuthSettings;