import React, { PureComponent, useState } from 'react'; import { Button, InlineField, InlineFieldRow, Input } from '@grafana/ui'; import { defaultCSVWaveQuery } from '../constants'; import type { CSVWave } from '../types'; interface WavesProps { waves?: CSVWave[]; onChange: (waves: CSVWave[]) => void; } interface WaveProps { wave: CSVWave; index: number; last: boolean; onChange: (index: number, wave?: CSVWave) => void; onAdd: () => void; } const CSVWaveEditor = (props: WaveProps) => { const { wave, last, index, onAdd, onChange } = props; const [valuesCSV, setValuesCSV] = useState(wave.valuesCSV || ''); const [labels, setLabels] = useState(wave.labels || ''); const [name, setName] = useState(wave.name || ''); const onAction = () => { if (last) { onAdd(); } else { onChange(index, undefined); } }; const onValueChange = (key: K, value: V) => { onChange(index, { ...wave, [key]: value }); }; const onKeyDown = (evt: React.KeyboardEvent) => { if (evt.key === 'Enter') { onValueChange('valuesCSV', valuesCSV); } }; return ( setValuesCSV(e.currentTarget.value)} autoFocus={true} onBlur={() => onValueChange('valuesCSV', valuesCSV)} onKeyDown={onKeyDown} /> onValueChange('timeStep', e.currentTarget.valueAsNumber)} /> setName(e.currentTarget.value)} onBlur={() => onValueChange('name', name)} /> setLabels(e.currentTarget.value)} onBlur={() => onValueChange('labels', labels)} />