Commit 8499d140 by Torkel Ödegaard Committed by GitHub

TestData: Fix issue with numeric inputs in TestData query editor (#28936)

parent ef2de2d3
...@@ -23,9 +23,6 @@ const endpoints = [ ...@@ -23,9 +23,6 @@ const endpoints = [
{ value: 'annotations', label: 'Annotations' }, { value: 'annotations', label: 'Annotations' },
]; ];
// Fields that need to be transformed to numbers
const numberFields = ['lines', 'seriesCount', 'timeStep'];
const selectors = editorSelectors.components.DataSource.TestData.QueryTab; const selectors = editorSelectors.components.DataSource.TestData.QueryTab;
export interface EditorProps { export interface EditorProps {
...@@ -80,22 +77,29 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props) ...@@ -80,22 +77,29 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props)
}; };
const onInputChange = (e: FormEvent<HTMLInputElement | HTMLTextAreaElement>) => { const onInputChange = (e: FormEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const { name, value } = e.target as HTMLInputElement | HTMLTextAreaElement; const { name, value, type } = e.target as HTMLInputElement | HTMLTextAreaElement;
let newValue: Partial<TestDataQuery> = { [name]: value }; let newValue: any = value;
if (type === 'number') {
newValue = Number(value);
}
if (name === 'levelColumn') { if (name === 'levelColumn') {
newValue = { levelColumn: (e.target as HTMLInputElement).checked }; newValue = (e.target as HTMLInputElement).checked;
} else if (numberFields.includes(name)) {
newValue = { [name]: Number(value) };
} }
onUpdate({ ...query, ...newValue }); onUpdate({ ...query, [name]: newValue });
}; };
const onFieldChange = (field: string) => (e: ChangeEvent<HTMLInputElement>) => { const onFieldChange = (field: string) => (e: ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target as HTMLInputElement; const { name, value, type } = e.target as HTMLInputElement;
const formattedValue = numberFields.includes(name) ? Number(value) : value; let newValue: any = value;
onUpdate({ ...query, [field]: { ...query[field as keyof TestDataQuery], [name]: formattedValue } });
if (type === 'number') {
newValue = Number(value);
}
onUpdate({ ...query, [field]: { ...query[field as keyof TestDataQuery], [name]: newValue } });
}; };
const onEndPointChange = ({ value }: SelectableValue) => { const onEndPointChange = ({ value }: SelectableValue) => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment