Support resize Flux Query Editor (#57214)
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { cx, css } from '@emotion/css';
|
import { cx, css } from '@emotion/css';
|
||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
|
|
||||||
import { SelectableValue } from '@grafana/data';
|
import { SelectableValue, GrafanaTheme2 } from '@grafana/data';
|
||||||
import { getTemplateSrv } from '@grafana/runtime';
|
import { getTemplateSrv } from '@grafana/runtime';
|
||||||
import {
|
import {
|
||||||
InlineFormLabel,
|
InlineFormLabel,
|
||||||
@@ -11,12 +11,14 @@ import {
|
|||||||
MonacoEditor,
|
MonacoEditor,
|
||||||
CodeEditorSuggestionItem,
|
CodeEditorSuggestionItem,
|
||||||
CodeEditorSuggestionItemKind,
|
CodeEditorSuggestionItemKind,
|
||||||
|
withTheme2,
|
||||||
|
Themeable2,
|
||||||
} from '@grafana/ui';
|
} from '@grafana/ui';
|
||||||
|
|
||||||
import InfluxDatasource from '../datasource';
|
import InfluxDatasource from '../datasource';
|
||||||
import { InfluxQuery } from '../types';
|
import { InfluxQuery } from '../types';
|
||||||
|
|
||||||
type Props = {
|
interface Props extends Themeable2 {
|
||||||
onChange: (query: InfluxQuery) => void;
|
onChange: (query: InfluxQuery) => void;
|
||||||
onRunQuery: () => void;
|
onRunQuery: () => void;
|
||||||
query: InfluxQuery;
|
query: InfluxQuery;
|
||||||
@@ -25,7 +27,7 @@ type Props = {
|
|||||||
// query-editor gets converted to react we can stop using this component directly
|
// query-editor gets converted to react we can stop using this component directly
|
||||||
// and then we can probably remove the datasource attribute.
|
// and then we can probably remove the datasource attribute.
|
||||||
datasource: InfluxDatasource;
|
datasource: InfluxDatasource;
|
||||||
};
|
}
|
||||||
|
|
||||||
const samples: Array<SelectableValue<string>> = [
|
const samples: Array<SelectableValue<string>> = [
|
||||||
{ label: 'Show buckets', description: 'List the available buckets (table)', value: 'buckets()' },
|
{ label: 'Show buckets', description: 'List the available buckets (table)', value: 'buckets()' },
|
||||||
@@ -93,7 +95,7 @@ v1.tagValues(
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export class FluxQueryEditor extends PureComponent<Props> {
|
class UnthemedFluxQueryEditor extends PureComponent<Props> {
|
||||||
onFluxQueryChange = (query: string) => {
|
onFluxQueryChange = (query: string) => {
|
||||||
this.props.onChange({ ...this.props.query, query });
|
this.props.onChange({ ...this.props.query, query });
|
||||||
this.props.onRunQuery();
|
this.props.onRunQuery();
|
||||||
@@ -164,7 +166,8 @@ export class FluxQueryEditor extends PureComponent<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { query } = this.props;
|
const { query, theme } = this.props;
|
||||||
|
const styles = getStyles(theme);
|
||||||
|
|
||||||
const helpTooltip = (
|
const helpTooltip = (
|
||||||
<div>
|
<div>
|
||||||
@@ -176,7 +179,8 @@ export class FluxQueryEditor extends PureComponent<Props> {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<CodeEditor
|
<CodeEditor
|
||||||
height={'200px'}
|
height={'100%'}
|
||||||
|
containerStyles={styles.editorContainerStyles}
|
||||||
language="sql"
|
language="sql"
|
||||||
value={query.query || ''}
|
value={query.query || ''}
|
||||||
onBlur={this.onFluxQueryChange}
|
onBlur={this.onFluxQueryChange}
|
||||||
@@ -186,14 +190,7 @@ export class FluxQueryEditor extends PureComponent<Props> {
|
|||||||
getSuggestions={this.getSuggestions}
|
getSuggestions={this.getSuggestions}
|
||||||
onEditorDidMount={this.editorDidMountCallbackHack}
|
onEditorDidMount={this.editorDidMountCallbackHack}
|
||||||
/>
|
/>
|
||||||
<div
|
<div className={cx('gf-form-inline', styles.editorActions)}>
|
||||||
className={cx(
|
|
||||||
'gf-form-inline',
|
|
||||||
css`
|
|
||||||
margin-top: 6px;
|
|
||||||
`
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<LinkButton
|
<LinkButton
|
||||||
icon="external-link-alt"
|
icon="external-link-alt"
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
@@ -214,3 +211,19 @@ export class FluxQueryEditor extends PureComponent<Props> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getStyles = (theme: GrafanaTheme2) => ({
|
||||||
|
editorContainerStyles: css`
|
||||||
|
height: 200px;
|
||||||
|
max-width: 100%;
|
||||||
|
resize: vertical;
|
||||||
|
overflow: auto;
|
||||||
|
background-color: ${theme.isDark ? theme.colors.background.canvas : theme.colors.background.primary};
|
||||||
|
padding-bottom: ${theme.spacing(1)};
|
||||||
|
`,
|
||||||
|
editorActions: css`
|
||||||
|
margin-top: 6px;
|
||||||
|
`,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const FluxQueryEditor = withTheme2(UnthemedFluxQueryEditor);
|
||||||
|
|||||||
Reference in New Issue
Block a user