The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
grafana/e2e/test-plugins/grafana-test-datasource/components/QueryEditor.tsx

46 lines
1.3 KiB

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>
);
}