import { uniqueId } from 'lodash'; import React, { PureComponent } from 'react'; import { DataSourcePluginOptionsEditorProps, SelectableValue, onUpdateDatasourceOption, updateDatasourcePluginResetOption, onUpdateDatasourceJsonDataOption, onUpdateDatasourceJsonDataOptionSelect, onUpdateDatasourceSecureJsonDataOption, updateDatasourcePluginJsonDataOption, } from '@grafana/data'; import { Alert, DataSourceHttpSettings, InfoBox, InlineField, InlineFormLabel, LegacyForms, Select } from '@grafana/ui'; const { Input, SecretFormField } = LegacyForms; import { InfluxOptions, InfluxSecureJsonData, InfluxVersion } from '../types'; const httpModes = [ { label: 'GET', value: 'GET' }, { label: 'POST', value: 'POST' }, ] as SelectableValue[]; const versions = [ { label: 'InfluxQL', value: InfluxVersion.InfluxQL, description: 'The InfluxDB SQL-like query language.', }, { label: 'Flux', value: InfluxVersion.Flux, description: 'Advanced data scripting and query language. Supported in InfluxDB 2.x and 1.8+', }, ] as Array>; export type Props = DataSourcePluginOptionsEditorProps; type State = { maxSeries: string | undefined; }; export class ConfigEditor extends PureComponent { state = { maxSeries: '', }; htmlPrefix: string; constructor(props: Props) { super(props); this.state.maxSeries = props.options.jsonData.maxSeries?.toString() || ''; this.htmlPrefix = uniqueId('influxdb-config'); } // 1x onResetPassword = () => { updateDatasourcePluginResetOption(this.props, 'password'); }; // 2x onResetToken = () => { updateDatasourcePluginResetOption(this.props, 'token'); }; onVersionChanged = (selected: SelectableValue) => { const { options, onOptionsChange } = this.props; const copy: any = { ...options, jsonData: { ...options.jsonData, version: selected.value, }, }; if (selected.value === InfluxVersion.Flux) { copy.access = 'proxy'; copy.basicAuth = true; copy.jsonData.httpMode = 'POST'; // Remove old 1x configs delete copy.user; delete copy.database; } onOptionsChange(copy); }; renderInflux2x() { const { options } = this.props; const { secureJsonFields } = options; const secureJsonData = (options.secureJsonData || {}) as InfluxSecureJsonData; const { htmlPrefix } = this; return ( <>
Organization
Default Bucket
Min time interval
); } renderInflux1x() { const { options } = this.props; const { secureJsonFields } = options; const secureJsonData = (options.secureJsonData || {}) as InfluxSecureJsonData; const { htmlPrefix } = this; return ( <>
Database Access

Setting the database for this datasource does not deny access to other databases. The InfluxDB query syntax allows switching the database in the query. For example: SHOW MEASUREMENTS ON _internal or SELECT * FROM "_internal".."database" LIMIT 10

To support data isolation and security, make sure appropriate permissions are configured in InfluxDB.

Database
User
HTTP Method
); } render() { const { options, onOptionsChange } = this.props; return ( <>

Query Language

{ // We duplicate this state so that we allow to write freely inside the input. We don't have // any influence over saving so this seems to be only way to do this. this.setState({ maxSeries: event.currentTarget.value }); const val = parseInt(event.currentTarget.value, 10); updateDatasourcePluginJsonDataOption(this.props, 'maxSeries', Number.isFinite(val) ? val : undefined); }} />
); } } export default ConfigEditor;