@@ -13,6 +13,7 @@ import {
13
13
Stack ,
14
14
FeatureBadge ,
15
15
Switch ,
16
+ Modal ,
16
17
type monacoTypes ,
17
18
} from '@grafana/ui' ;
18
19
import { CoreApp , FeatureState , QueryEditorProps , SelectableValue } from '@grafana/data' ;
@@ -44,9 +45,11 @@ const languageOptions: Array<SelectableValue<string>> = [
44
45
] ;
45
46
46
47
export function QueryEditor ( { query, onChange, app } : Props ) {
47
- const codeEditorRef = useRef < monacoTypes . editor . IStandaloneCodeEditor | null > ( null ) ;
48
+ const codeEditorMainRef = useRef < monacoTypes . editor . IStandaloneCodeEditor | null > ( null ) ;
49
+ const codeEditorModalRef = useRef < monacoTypes . editor . IStandaloneCodeEditor | null > ( null ) ;
48
50
const [ queryTextError , setQueryTextError ] = useState < string | null > ( null ) ;
49
- const [ isOpen , setIsOpen ] = useState ( false ) ;
51
+ const [ isAggregateOptionPanelOpen , setIsAggregateOptionPanelOpen ] = useState ( false ) ;
52
+ const [ isEditorModalOpen , setIsEditorModalOpen ] = useState ( false ) ;
50
53
const setupAutocompleteFn = useAutocomplete ( ) ;
51
54
52
55
const [ maxTimeMSText , setMaxTimeMSText ] = useState < string > (
@@ -131,10 +134,8 @@ export function QueryEditor({ query, onChange, app }: Props) {
131
134
onChange ( { ...query , aggregateComment : event . target . value } ) ;
132
135
} ;
133
136
134
- const onFormatQueryText = ( ) => {
135
- if ( codeEditorRef . current ) {
136
- codeEditorRef . current . getAction ( 'editor.action.formatDocument' ) . run ( ) ;
137
- }
137
+ const onFormatQueryText = ( editor : monacoTypes . editor . IStandaloneCodeEditor | null ) => {
138
+ editor ?. getAction ( 'editor.action.formatDocument' ) . run ( ) ;
138
139
} ;
139
140
140
141
const onIsStreamingChange : FormEventHandler < HTMLInputElement > = ( e ) => {
@@ -204,7 +205,7 @@ export function QueryEditor({ query, onChange, app }: Props) {
204
205
/>
205
206
</ InlineField >
206
207
</ InlineFieldRow >
207
- < ControlledCollapse label = "Aggregate Options" isOpen = { isOpen } onToggle = { ( ) => setIsOpen ( ! isOpen ) } >
208
+ < ControlledCollapse label = "Aggregate Options" isOpen = { isAggregateOptionPanelOpen } onToggle = { ( ) => setIsAggregateOptionPanelOpen ( ! isAggregateOptionPanelOpen ) } >
208
209
< InlineFieldRow >
209
210
< InlineField
210
211
label = "Max time(ms)"
@@ -268,15 +269,14 @@ export function QueryEditor({ query, onChange, app }: Props) {
268
269
</ ControlledCollapse >
269
270
< Field
270
271
label = "Query Text"
271
- description = { `Enter the Mongo Aggregation Pipeline (${
272
- query . queryLanguage === QueryLanguage . JSON ? 'JSON' : 'JavaScript'
273
- } )`}
272
+ description = { `Enter the Mongo Aggregation Pipeline (${ query . queryLanguage === QueryLanguage . JSON ? 'JSON' : 'JavaScript'
273
+ } )`}
274
274
error = { queryTextError }
275
275
invalid = { queryTextError != null }
276
276
>
277
277
< CodeEditor
278
278
onEditorDidMount = { ( editor , monaco ) => {
279
- codeEditorRef . current = editor ;
279
+ codeEditorMainRef . current = editor ;
280
280
setupAutocompleteFn ( editor , monaco ) ;
281
281
} }
282
282
width = "100%"
@@ -294,10 +294,42 @@ export function QueryEditor({ query, onChange, app }: Props) {
294
294
/>
295
295
</ Field >
296
296
< Stack direction = "row" wrap alignItems = "flex-start" justifyContent = "start" gap = { 1 } >
297
- < Button onClick = { onFormatQueryText } variant = "secondary" >
297
+ < Button onClick = { ( ) => onFormatQueryText ( codeEditorMainRef . current ) } variant = "secondary" >
298
298
Format
299
299
</ Button >
300
+ < Button onClick = { ( ) => setIsEditorModalOpen ( true ) } variant = "secondary" >
301
+ Open editor in pop-up view
302
+ </ Button >
300
303
</ Stack >
304
+ { /* Code Editoor Modal */ }
305
+ < Modal title = "title" isOpen = { isEditorModalOpen } >
306
+ < CodeEditor
307
+ onEditorDidMount = { ( editor , monaco ) => {
308
+ codeEditorModalRef . current = editor ;
309
+ setupAutocompleteFn ( editor , monaco ) ;
310
+ } }
311
+ width = "100%"
312
+ height = { 500 }
313
+ language = {
314
+ query . queryLanguage === QueryLanguage . JAVASCRIPT || query . queryLanguage === QueryLanguage . JAVASCRIPT_SHADOW
315
+ ? 'javascript'
316
+ : 'json'
317
+ }
318
+ onBlur = { onQueryTextChange }
319
+ value = { query . queryText || '' }
320
+ showMiniMap = { true }
321
+ showLineNumbers = { true }
322
+ monacoOptions = { { fontSize : 15 } }
323
+ />
324
+ < Modal . ButtonRow >
325
+ < Button onClick = { ( ) => onFormatQueryText ( codeEditorModalRef . current ) } variant = "secondary" >
326
+ Format
327
+ </ Button >
328
+ < Button variant = "primary" fill = "outline" onClick = { ( ) => setIsEditorModalOpen ( false ) } >
329
+ Close
330
+ </ Button >
331
+ </ Modal . ButtonRow >
332
+ </ Modal >
301
333
</ >
302
334
) ;
303
335
}
0 commit comments