import React, { ChangeEvent, PureComponent } from 'react'; import { SelectableValue } from '@grafana/data'; import { Input, FormLabel, Select, Button } from '@grafana/ui'; export interface Props { selectedAzureCloud?: string; selectedSubscription?: string; azureCloudOptions?: SelectableValue[]; tenantId: string; clientId: string; clientSecret: string; clientSecretConfigured: boolean; subscriptionOptions?: SelectableValue[]; onAzureCloudChange?: (value: SelectableValue) => void; onSubscriptionSelectChange?: (value: SelectableValue) => void; onTenantIdChange: (tenantId: string) => void; onClientIdChange: (clientId: string) => void; onClientSecretChange: (clientSecret: string) => void; onResetClientSecret: () => void; onLoadSubscriptions?: () => void; } export interface State { selectedAzureCloud?: string; selectedSubscription: string; tenantId: string; clientId: string; clientSecret: string; clientSecretConfigured: boolean; } export class AzureCredentialsForm extends PureComponent { constructor(props: Props) { super(props); const { selectedAzureCloud, selectedSubscription, tenantId, clientId, clientSecret, clientSecretConfigured, } = this.props; this.state = { selectedAzureCloud, selectedSubscription, tenantId, clientId, clientSecret, clientSecretConfigured, }; } static getDerivedStateFromProps(nextProps: Props, prevState: Props) { const { selectedAzureCloud, tenantId, clientId, clientSecret, clientSecretConfigured } = nextProps; return { selectedAzureCloud, tenantId, clientId, clientSecret, clientSecretConfigured, }; } render() { const { azureCloudOptions, subscriptionOptions, onAzureCloudChange, onSubscriptionSelectChange, onTenantIdChange, onClientIdChange, onClientSecretChange, onResetClientSecret, onLoadSubscriptions, } = this.props; const { selectedAzureCloud, selectedSubscription, tenantId, clientId, clientSecret, clientSecretConfigured, } = this.state; const hasRequiredFields = tenantId && clientId && (clientSecret || clientSecretConfigured); const hasSubscriptions = onLoadSubscriptions && subscriptionOptions; return ( <>
{azureCloudOptions && (
Azure Cloud ) => onTenantIdChange(event.target.value)} />
Application (client) ID
) => onClientIdChange(event.target.value)} />
{clientSecretConfigured ? (
Client Secret
) : (
Client Secret
) => onClientSecretChange(event.target.value)} />
)} {hasSubscriptions && ( <>
Default Subscription