2022-09-01 22:49:27 +01:00
|
|
|
import { css } from '@emotion/css';
|
2022-08-24 17:57:59 +01:00
|
|
|
import { defaults } from 'lodash';
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
|
|
import { QueryEditorProps } from '@grafana/data';
|
2022-09-01 22:49:27 +01:00
|
|
|
import { useStyles2 } from '@grafana/ui';
|
2022-08-24 17:57:59 +01:00
|
|
|
|
|
|
|
|
import { TempoDatasource, TempoQuery } from '../datasource';
|
|
|
|
|
import { defaultQuery, MyDataSourceOptions } from '../types';
|
|
|
|
|
|
2022-09-01 22:49:27 +01:00
|
|
|
import { TempoQueryBuilderOptions } from './TempoQueryBuilderOptions';
|
2022-08-24 17:57:59 +01:00
|
|
|
import { TraceQLEditor } from './TraceQLEditor';
|
|
|
|
|
|
|
|
|
|
type Props = QueryEditorProps<TempoDatasource, TempoQuery, MyDataSourceOptions>;
|
|
|
|
|
|
|
|
|
|
export function QueryEditor(props: Props) {
|
2022-09-01 22:49:27 +01:00
|
|
|
const styles = useStyles2(getStyles);
|
|
|
|
|
const query = defaults(props.query, defaultQuery);
|
2022-08-24 17:57:59 +01:00
|
|
|
|
2022-09-01 22:49:27 +01:00
|
|
|
const onEditorChange = (value: string) => {
|
|
|
|
|
props.onChange({ ...query, query: value });
|
|
|
|
|
};
|
2022-08-24 17:57:59 +01:00
|
|
|
|
|
|
|
|
return (
|
2022-09-01 22:49:27 +01:00
|
|
|
<>
|
2022-08-24 17:57:59 +01:00
|
|
|
<TraceQLEditor value={query.query} onChange={onEditorChange} datasource={props.datasource} />
|
2022-09-01 22:49:27 +01:00
|
|
|
<div className={styles.optionsContainer}>
|
|
|
|
|
<TempoQueryBuilderOptions query={query} onChange={props.onChange} />
|
|
|
|
|
</div>
|
|
|
|
|
</>
|
2022-08-24 17:57:59 +01:00
|
|
|
);
|
|
|
|
|
}
|
2022-09-01 22:49:27 +01:00
|
|
|
|
|
|
|
|
const getStyles = () => ({
|
|
|
|
|
optionsContainer: css`
|
|
|
|
|
margin-top: 10px;
|
|
|
|
|
`,
|
|
|
|
|
});
|