import { PureComponent } from 'react'; import { DataSourcePluginOptionsEditorProps, updateDatasourcePluginJsonDataOption, onUpdateDatasourceJsonDataOptionSelect, onUpdateDatasourceJsonDataOptionChecked, } from '@grafana/data'; import { Alert, DataSourceHttpSettings, Field, FieldSet, Select, Switch } from '@grafana/ui'; import { config } from 'app/core/config'; import store from 'app/core/store'; import { GraphiteOptions, GraphiteType } from '../types'; import { DEFAULT_GRAPHITE_VERSION, GRAPHITE_VERSIONS } from '../versions'; import { MappingsConfiguration } from './MappingsConfiguration'; import { fromString, toString } from './parseLokiLabelMappings'; export const SHOW_MAPPINGS_HELP_KEY = 'grafana.datasources.graphite.config.showMappingsHelp'; const graphiteVersions = GRAPHITE_VERSIONS.map((version) => ({ label: `${version}.x`, value: version })); const graphiteTypes = Object.entries(GraphiteType).map(([label, value]) => ({ label, value, })); export type Props = DataSourcePluginOptionsEditorProps; type State = { showMappingsHelp: boolean; }; export class ConfigEditor extends PureComponent { constructor(props: Props) { super(props); this.state = { showMappingsHelp: store.getObject(SHOW_MAPPINGS_HELP_KEY, true), }; } componentDidMount() { updateDatasourcePluginJsonDataOption(this.props, 'graphiteVersion', this.currentGraphiteVersion); } render() { const { options, onOptionsChange } = this.props; const currentVersion = graphiteVersions.find((item) => item.value === this.currentGraphiteVersion); return ( <> {options.access === 'direct' && ( This data source uses browser access mode. This mode is deprecated and will be removed in the future. Please use server access mode instead. )}
Graphite details type.value === options.jsonData.graphiteType)} width={16} onChange={onUpdateDatasourceJsonDataOptionSelect(this.props, 'graphiteType')} /> {options.jsonData.graphiteType === GraphiteType.Metrictank && ( )}
{ this.setState({ showMappingsHelp: false }); store.setObject(SHOW_MAPPINGS_HELP_KEY, false); }} onRestoreHelp={() => { this.setState({ showMappingsHelp: true }); store.setObject(SHOW_MAPPINGS_HELP_KEY, true); }} onChange={(mappings) => { onOptionsChange({ ...options, jsonData: { ...options.jsonData, importConfiguration: { ...options.jsonData.importConfiguration, loki: { mappings: mappings.map(fromString), }, }, }, }); }} /> ); } private get currentGraphiteVersion() { return this.props.options.jsonData.graphiteVersion || DEFAULT_GRAPHITE_VERSION; } }