mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 02:22:38 +08:00

* Jaeger: add QueryField component * Remove unused imports * Fix e2e test so that it checks for QueryField component * Remove comments * Fix failing e2e test
79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
import { css } from '@emotion/css';
|
|
import { QueryEditorProps } from '@grafana/data';
|
|
import { FileDropzone, InlineField, InlineFieldRow, QueryField, RadioButtonGroup, useTheme2 } from '@grafana/ui';
|
|
import React from 'react';
|
|
import { JaegerDatasource } from '../datasource';
|
|
import { JaegerQuery, JaegerQueryType } from '../types';
|
|
import { SearchForm } from './SearchForm';
|
|
|
|
type Props = QueryEditorProps<JaegerDatasource, JaegerQuery>;
|
|
|
|
export function QueryEditor({ datasource, query, onChange, onRunQuery }: Props) {
|
|
const theme = useTheme2();
|
|
|
|
const onChangeQuery = (value: string) => {
|
|
const nextQuery: JaegerQuery = { ...query, query: value };
|
|
onChange(nextQuery);
|
|
};
|
|
|
|
const renderEditorBody = () => {
|
|
switch (query.queryType) {
|
|
case 'search':
|
|
return <SearchForm datasource={datasource} query={query} onChange={onChange} />;
|
|
case 'upload':
|
|
return (
|
|
<div className={css({ padding: theme.spacing(2) })}>
|
|
<FileDropzone
|
|
options={{ multiple: false }}
|
|
onLoad={(result) => {
|
|
datasource.uploadedJson = result;
|
|
onRunQuery();
|
|
}}
|
|
/>
|
|
</div>
|
|
);
|
|
default:
|
|
return (
|
|
<InlineFieldRow>
|
|
<InlineField label="Trace ID" labelWidth={21} grow>
|
|
<QueryField
|
|
query={query.query}
|
|
onChange={onChangeQuery}
|
|
onRunQuery={onRunQuery}
|
|
placeholder={'Enter a Trace ID (run with Shift+Enter)'}
|
|
portalOrigin="jaeger"
|
|
/>
|
|
</InlineField>
|
|
</InlineFieldRow>
|
|
);
|
|
}
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<div className={css({ width: query.queryType === 'upload' ? '100%' : '50%' })}>
|
|
<InlineFieldRow>
|
|
<InlineField label="Query type">
|
|
<RadioButtonGroup<JaegerQueryType>
|
|
options={[
|
|
{ value: 'search', label: 'Search' },
|
|
{ value: undefined, label: 'TraceID' },
|
|
{ value: 'upload', label: 'JSON file' },
|
|
]}
|
|
value={query.queryType}
|
|
onChange={(v) =>
|
|
onChange({
|
|
...query,
|
|
queryType: v,
|
|
})
|
|
}
|
|
size="md"
|
|
/>
|
|
</InlineField>
|
|
</InlineFieldRow>
|
|
{renderEditorBody()}
|
|
</div>
|
|
</>
|
|
);
|
|
}
|