import React, { PureComponent } from 'react'; import { FormLabel, Button, Input } from '@grafana/ui'; export interface Props { datasourceConfig: any; onDatasourceUpdate: (config: any) => void; } export interface State { config: any; } export class InsightsConfig extends PureComponent { constructor(props: Props) { super(props); const { datasourceConfig } = this.props; this.state = { config: datasourceConfig, }; } static getDerivedStateFromProps(props: Props, state: State) { return { ...state, config: props.datasourceConfig, }; } onAppInsightsAppIdChange = (appInsightsAppId: string) => { this.props.onDatasourceUpdate({ ...this.state.config, editorJsonData: { ...this.state.config.editorJsonData, appInsightsAppId, }, }); }; onAppInsightsApiKeyChange = (appInsightsApiKey: string) => { this.props.onDatasourceUpdate({ ...this.state.config, editorSecureJsonData: { ...this.state.config.editorSecureJsonData, appInsightsApiKey, }, }); }; onAppInsightsResetApiKey = () => { this.props.onDatasourceUpdate({ ...this.state.config, version: this.state.config.version + 1, secureJsonFields: { ...this.state.config.secureJsonFields, appInsightsApiKey: false, }, }); }; render() { const { config } = this.state; return ( <>

Application Insights Details

{config.secureJsonFields.appInsightsApiKey ? (
API Key
) : (
API Key
this.onAppInsightsApiKeyChange(event.target.value)} />
)}
Application ID
this.onAppInsightsAppIdChange(event.target.value)} />
); } } export default InsightsConfig;