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 = [
{ value: 'annotations', label: 'Annotations' },
];
// Fields that need to be transformed to numbers
const numberFields = ['lines', 'seriesCount', 'timeStep'];
const selectors = editorSelectors.components.DataSource.TestData.QueryTab;
export interface EditorProps {
......@@ -80,22 +77,29 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props)
};
const onInputChange = (e: FormEvent<HTMLInputElement | HTMLTextAreaElement>) => {
const { name, value } = e.target as HTMLInputElement | HTMLTextAreaElement;
let newValue: Partial<TestDataQuery> = { [name]: value };
const { name, value, type } = e.target as HTMLInputElement | HTMLTextAreaElement;
let newValue: any = value;
if (type === 'number') {
newValue = Number(value);
}
if (name === 'levelColumn') {
newValue = { levelColumn: (e.target as HTMLInputElement).checked };
} else if (numberFields.includes(name)) {
newValue = { [name]: Number(value) };
newValue = (e.target as HTMLInputElement).checked;
}
onUpdate({ ...query, ...newValue });
onUpdate({ ...query, [name]: newValue });
};
const onFieldChange = (field: string) => (e: ChangeEvent<HTMLInputElement>) => {
const { name, value } = e.target as HTMLInputElement;
const formattedValue = numberFields.includes(name) ? Number(value) : value;
onUpdate({ ...query, [field]: { ...query[field as keyof TestDataQuery], [name]: formattedValue } });
const { name, value, type } = e.target as HTMLInputElement;
let newValue: any = value;
if (type === 'number') {
newValue = Number(value);
}
onUpdate({ ...query, [field]: { ...query[field as keyof TestDataQuery], [name]: newValue } });
};
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