diff --git a/.betterer.results b/.betterer.results index 226e8c813d9..1c1a03ef8a5 100644 --- a/.betterer.results +++ b/.betterer.results @@ -8681,9 +8681,6 @@ exports[`better eslint`] = { [0, 0, 0, "Do not use any type assertions.", "10"], [0, 0, 0, "Unexpected any. Specify a different type.", "11"] ], - "public/app/plugins/datasource/testdata/components/CSVWaveEditor.tsx:5381": [ - [0, 0, 0, "Do not use any type assertions.", "0"] - ], "public/app/plugins/datasource/testdata/components/PredictablePulseEditor.tsx:5381": [ [0, 0, 0, "Do not use any type assertions.", "0"] ], diff --git a/public/app/plugins/datasource/testdata/components/CSVWaveEditor.tsx b/public/app/plugins/datasource/testdata/components/CSVWaveEditor.tsx index b1090c2d6c1..585112ec037 100644 --- a/public/app/plugins/datasource/testdata/components/CSVWaveEditor.tsx +++ b/public/app/plugins/datasource/testdata/components/CSVWaveEditor.tsx @@ -1,9 +1,9 @@ -import React, { ChangeEvent, PureComponent } from 'react'; +import React, { PureComponent, useState } from 'react'; import { Button, InlineField, InlineFieldRow, Input } from '@grafana/ui'; import { defaultCSVWaveQuery } from '../constants'; -import { CSVWave } from '../types'; +import type { CSVWave } from '../types'; interface WavesProps { waves?: CSVWave[]; @@ -18,59 +18,74 @@ interface WaveProps { onAdd: () => void; } -class CSVWaveEditor extends PureComponent { - onFieldChange = (field: keyof CSVWave) => (e: ChangeEvent) => { - const { value } = e.target as HTMLInputElement; - - this.props.onChange(this.props.index, { - ...this.props.wave, - [field]: value, - }); - }; - - onNameChange = this.onFieldChange('name'); - onLabelsChange = this.onFieldChange('labels'); - onCSVChange = this.onFieldChange('valuesCSV'); - onTimeStepChange = (e: ChangeEvent) => { - const timeStep = e.target.valueAsNumber; - this.props.onChange(this.props.index, { - ...this.props.wave, - timeStep, - }); - }; - - render() { - const { wave, last } = this.props; - let action = this.props.onAdd; - if (!last) { - action = () => { - this.props.onChange(this.props.index, undefined); // remove - }; +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 ( - - - - - - - - - - - - - -