This repository was archived by the owner on Jul 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathQueryEditor.tsx
More file actions
60 lines (52 loc) · 1.56 KB
/
Copy pathQueryEditor.tsx
File metadata and controls
60 lines (52 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { Component } from 'react';
import { DataSource } from '../Datasource';
import { QueryEditorProps } from '@grafana/data';
import { Settings, SqlQuery } from '../../shared/types';
import { Controlled as CodeMirror } from 'react-codemirror2';
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/darcula.css';
require('codemirror/mode/sql/sql');
import './QueryEditor.scss';
type Props = QueryEditorProps<DataSource, SqlQuery, Settings>;
interface State {
sql: string;
}
export class QueryEditor extends Component<Props, State> {
constructor(props: QueryEditorProps<DataSource, SqlQuery, Settings>, context: any) {
super(props, context);
this.state = { sql: props.query.sql };
}
onChange = (editor: any, event: Event) => {
const { onChange, query, onRunQuery } = this.props;
const sql = this.state.sql;
this.setState({ sql });
onChange({ ...query, sql });
onRunQuery(); // executes the query
};
render() {
const { sql } = this.state;
const options = {
mode: 'sql',
theme: 'darcula',
};
return (
<>
<div className={'sql-query-editor'}>
<CodeMirror
value={sql}
options={options}
onBeforeChange={(editor, data, value) => {
this.setState({ sql: value });
}}
onChange={(editor, data, value) => {
this.setState({ sql: value });
}}
onBlur={(editor, event) => {
this.onChange(editor, event);
}}
/>
</div>
</>
);
}
}