@@ -14,7 +14,7 @@ import {
14
14
import { QueryEditorProps , SelectableValue } from "@grafana/data" ;
15
15
import { DataSource } from "../datasource" ;
16
16
import { MongoDataSourceOptions , MongoQuery , QueryLanguage , QueryType , DEFAULT_QUERY } from "../types" ;
17
- import { parseJsQuery , parseJsQueryLegacy , validateJsonQueryText } from "../utils" ;
17
+ import { parseJsQuery , parseJsQueryLegacy , validateJsonQueryText , validateTimeout } from "../utils" ;
18
18
import * as monacoType from "monaco-editor/esm/vs/editor/editor.api" ;
19
19
20
20
type Props = QueryEditorProps < DataSource , MongoQuery , MongoDataSourceOptions > ;
@@ -35,6 +35,7 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
35
35
36
36
const codeEditorRef = useRef < monacoType . editor . IStandaloneCodeEditor | null > ( null ) ;
37
37
const [ queryTextError , setQueryTextError ] = useState < string | null > ( null ) ;
38
+ const [ timeoutText , setTimeoutText ] = useState < string > ( query . timeout ? query . timeout . toString ( ) : "" ) ;
38
39
39
40
const optionsLanguage = [
40
41
{ label : "JSON" , value : QueryLanguage . JSON } ,
@@ -74,6 +75,16 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
74
75
onChange ( { ...query , collection : event . target . value } ) ;
75
76
} ;
76
77
78
+ const onTimeoutChange = ( event : ChangeEvent < HTMLInputElement > ) => {
79
+ setTimeoutText ( event . target . value ) ;
80
+ console . log ( event . target . value ) ;
81
+ if ( ! event . target . value ) {
82
+ onChange ( { ...query , timeout : undefined } ) ;
83
+ } else if ( validateTimeout ( event . target . value ) ) {
84
+ onChange ( { ...query , timeout : parseInt ( event . target . value , 10 ) } ) ;
85
+ }
86
+ } ;
87
+
77
88
const onCodeEditorDidMount = ( e : monacoType . editor . IStandaloneCodeEditor ) => {
78
89
codeEditorRef . current = e ;
79
90
} ;
@@ -98,6 +109,10 @@ export function QueryEditor({ query, onChange, onRunQuery }: Props) {
98
109
error = "Please enter the collection" invalid = { ! query . collection } >
99
110
< Input id = "query-editor-collection" onChange = { onCollectionChange } value = { query . collection } required />
100
111
</ InlineField >
112
+ < InlineField label = "Timeout" tooltip = "(Optional) The maximum amount of time (in milisecond) that the query can run on the server."
113
+ error = "Invalid timeout" invalid = { timeoutText !== "" && ! validateTimeout ( timeoutText ) } >
114
+ < Input id = "query-editor-timeout" onChange = { onTimeoutChange } value = { timeoutText } />
115
+ </ InlineField >
101
116
</ InlineFieldRow >
102
117
< Divider />
103
118
< InlineField label = "Query language" >
0 commit comments