-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathQueryEditor.tsx
35 lines (31 loc) · 1.12 KB
/
QueryEditor.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React, { useState, useEffect } from 'react';
import { QueryEditorProps } from '@grafana/data';
import { DataSource } from '../datasource';
import { MyDataSourceOptions, MyQuery } from '../types';
import { HorizontalGroup, Input, Label } from '@grafana/ui';
type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>;
export const QueryEditor = (props: Props) => {
const [query, setQuery] = useState<MyQuery>(props.query);
useEffect(() => {
props.datasource.migrateQuery(props.query).then((query) => {
setQuery(query);
});
}, []); // eslint-disable-line react-hooks/exhaustive-deps
const onChangeMultiplier = (multiply: number) => {
const newQuery = { ...query, multiply, pluginVersion: props.datasource.meta.info.version };
setQuery(newQuery);
props.onChange(newQuery);
};
return (
<HorizontalGroup>
<Label htmlFor="multiplier">Multiplier</Label>
<Input
type="number"
id="multiplier"
name="multiplier"
value={query.multiply}
onChange={(e) => onChangeMultiplier(e.currentTarget.valueAsNumber)}
/>
</HorizontalGroup>
);
};