import React from 'react'; import { DataSourceSettings, SelectableValue } from '@grafana/data'; import { FieldSet, InlineField, Input, Select, InlineSwitch } from '@grafana/ui'; import { ElasticsearchOptions, Interval } from '../types'; const indexPatternTypes: Array> = [ { label: 'No pattern', value: 'none' }, { label: 'Hourly', value: 'Hourly', example: '[logstash-]YYYY.MM.DD.HH' }, { label: 'Daily', value: 'Daily', example: '[logstash-]YYYY.MM.DD' }, { label: 'Weekly', value: 'Weekly', example: '[logstash-]GGGG.WW' }, { label: 'Monthly', value: 'Monthly', example: '[logstash-]YYYY.MM' }, { label: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY' }, ]; type Props = { value: DataSourceSettings; onChange: (value: DataSourceSettings) => void; }; export const ElasticDetails = ({ value, onChange }: Props) => { return ( <>
A lower limit for the auto group by time interval. Recommended to be set to write frequency, for example{' '} 1m if your data is written every minute. } error="Value is not valid, you can use number with time unit specifier: y, M, w, d, h, m, s" invalid={!!value.jsonData.timeInterval && !/^\d+(ms|[Mwdhmsy])$/.test(value.jsonData.timeInterval)} > includeFrozenIndicesOnChange(event.currentTarget.checked, value, onChange)} />
); }; // TODO: Use change handlers from @grafana/data const changeHandler = (key: keyof DataSourceSettings, value: Props['value'], onChange: Props['onChange']) => (event: React.SyntheticEvent) => { onChange({ ...value, [key]: event.currentTarget.value, }); }; // TODO: Use change handlers from @grafana/data const jsonDataChangeHandler = (key: keyof ElasticsearchOptions, value: Props['value'], onChange: Props['onChange']) => (event: React.SyntheticEvent) => { onChange({ ...value, jsonData: { ...value.jsonData, [key]: event.currentTarget.value, }, }); }; const includeFrozenIndicesOnChange = (newValue: boolean, formValue: Props['value'], onChange: Props['onChange']) => { const newJsonData = { ...formValue.jsonData }; if (newValue) { newJsonData.xpack = true; newJsonData.includeFrozen = true; } else { delete newJsonData.xpack; delete newJsonData.includeFrozen; } onChange({ ...formValue, jsonData: newJsonData, }); }; const intervalHandler = (value: Props['value'], onChange: Props['onChange']) => (option: SelectableValue) => { const { database } = value; // If option value is undefined it will send its label instead so we have to convert made up value to undefined here. const newInterval = option.value === 'none' ? undefined : option.value; if (!database || database.length === 0 || database.startsWith('[logstash-]')) { let newDatabase = ''; if (newInterval !== undefined) { const pattern = indexPatternTypes.find((pattern) => pattern.value === newInterval); if (pattern) { newDatabase = pattern.example ?? ''; } } onChange({ ...value, database: newDatabase, jsonData: { ...value.jsonData, interval: newInterval, }, }); } else { onChange({ ...value, jsonData: { ...value.jsonData, interval: newInterval, }, }); } }; export function defaultMaxConcurrentShardRequests() { return 5; }