Files
grafana/e2e/test-plugins/grafana-test-datasource/components/QueryEditor.tsx
Erik Sundell c29ed503db Test plugins: Add datasource test plugin with field tests (#95472)
* add new test plugin

* add some field validation tests

* update lockfile

* fix bad test file name
2024-11-01 08:25:27 +01:00

46 lines
1.3 KiB
TypeScript

import { ChangeEvent } from 'react';
import { InlineField, Input, Stack } from '@grafana/ui';
import { QueryEditorProps } from '@grafana/data';
import { DataSource } from '../datasource';
import { MyDataSourceOptions, MyQuery } from '../types';
type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>;
export function QueryEditor({ query, onChange, onRunQuery }: Props) {
const onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => {
onChange({ ...query, queryText: event.target.value });
};
const onConstantChange = (event: ChangeEvent<HTMLInputElement>) => {
onChange({ ...query, constant: parseFloat(event.target.value) });
// executes the query
onRunQuery();
};
const { queryText, constant } = query;
return (
<Stack gap={0}>
<InlineField label="Constant">
<Input
id="query-editor-constant"
onChange={onConstantChange}
value={constant}
width={8}
type="number"
step="0.1"
/>
</InlineField>
<InlineField label="Query Text" labelWidth={16} tooltip="Not used yet">
<Input
id="query-editor-query-text"
onChange={onQueryTextChange}
value={queryText || ''}
required
placeholder="Enter a query"
/>
</InlineField>
</Stack>
);
}