import React, { useEffect, useState } from 'react'; import { getDataSourceSrv } from '@grafana/runtime'; import { DataSourcePluginOptionsEditorProps, DataSourceSettings, SelectableValue } from '@grafana/data'; import { DataSourceHttpSettings, LegacyForms, Field, Input, Button, InlineFormLabel, Select } from '@grafana/ui'; const { FormField, Switch } = LegacyForms; import { ZabbixDSOptions, ZabbixSecureJSONData } from '../types'; const SUPPORTED_SQL_DS = ['mysql', 'postgres', 'influxdb']; export type Props = DataSourcePluginOptionsEditorProps; export const ConfigEditor = (props: Props) => { const { options, onOptionsChange } = props; const [selectedDBDatasource, setSelectedDBDatasource] = useState(null); const [currentDSType, setCurrentDSType] = useState(''); // Apply some defaults on initial render useEffect(() => { const { jsonData, secureJsonFields } = options; // Set secureJsonFields.password to password and then remove it from config const { password, ...restJsonData } = jsonData; if (!secureJsonFields?.password) { if (!options.secureJsonData) { options.secureJsonData = {}; } options.secureJsonData.password = password; } onOptionsChange({ ...options, jsonData: { trends: true, trendsFrom: '', trendsRange: '', cacheTTL: '', ...restJsonData, }, }); if (options.jsonData.dbConnectionEnable) { if (!options.jsonData.dbConnectionDatasourceId) { const dsName = options.jsonData.dbConnectionDatasourceName; getDataSourceSrv().get(dsName) .then(ds => { if (ds) { const selectedDs = getDirectDBDatasources().find(dsOption => dsOption.id === ds.id); setSelectedDBDatasource({ label: selectedDs.name, value: selectedDs.id }); setCurrentDSType(selectedDs.type); onOptionsChange({ ...options, jsonData: { ...options.jsonData, dbConnectionDatasourceId: ds.id, }, }); } }); } else { const selectedDs = getDirectDBDatasources().find(dsOption => dsOption.id === options.jsonData.dbConnectionDatasourceId); setSelectedDBDatasource({ label: selectedDs.name, value: selectedDs.id }); setCurrentDSType(selectedDs.type); } } }, []); return ( <>

Zabbix API details

{options.secureJsonFields?.password ? <> : }
{options.jsonData.trends && <>
}

Direct DB Connection

{options.jsonData.dbConnectionEnable && <>
Data Source