1
1
import { cx } from '@emotion/css' ;
2
2
import { isDataFrame , QueryEditorProps , QueryHint , TimeRange , toLegacyResponseData } from '@grafana/data' ;
3
3
import { reportInteraction } from '@grafana/runtime' ;
4
- import {
5
- BracesPlugin ,
6
- clearButtonStyles ,
7
- DOMUtil ,
8
- Icon ,
9
- SlatePrism ,
10
- SuggestionsState ,
11
- Themeable2 ,
12
- TypeaheadInput ,
13
- TypeaheadOutput ,
14
- withTheme2 ,
15
- } from '@grafana/ui' ;
16
- import { LocalStorageValueProvider } from 'app/core/components/LocalStorageValueProvider' ;
4
+ import { clearButtonStyles , Icon , Themeable2 , withTheme2 } from '@grafana/ui' ;
5
+ import React , { ReactNode } from 'react' ;
6
+
7
+ import { PrometheusDatasource } from '../datasource' ;
8
+ import { LocalStorageValueProvider } from '../gcopypaste/app/core/components/LocalStorageValueProvider' ;
17
9
import {
18
10
CancelablePromise ,
19
11
isCancelablePromiseRejection ,
20
12
makePromiseCancelable ,
21
- } from 'app/core/utils/CancelablePromise' ;
22
- import { LanguageMap , languages as prismLanguages } from 'prismjs' ;
23
- import React , { ReactNode } from 'react' ;
24
- import { Plugin } from 'slate' ;
25
- import { Editor } from 'slate-react' ;
26
-
27
- import { PrometheusDatasource } from '../datasource' ;
13
+ } from '../gcopypaste/app/core/utils/CancelablePromise' ;
28
14
import { roundMsToMin } from '../language_utils' ;
29
15
import { PromOptions , PromQuery } from '../types' ;
30
16
31
17
import { PrometheusMetricsBrowser } from './PrometheusMetricsBrowser' ;
32
18
import { MonacoQueryFieldWrapper } from './monaco-query-field/MonacoQueryFieldWrapper' ;
33
19
34
- export const RECORDING_RULES_GROUP = '__recording_rules__' ;
35
20
const LAST_USED_LABELS_KEY = 'grafana.datasources.prometheus.browser.labels' ;
36
21
37
22
function getChooserText ( metricsLookupDisabled : boolean , hasSyntax : boolean , hasMetrics : boolean ) {
@@ -50,33 +35,6 @@ function getChooserText(metricsLookupDisabled: boolean, hasSyntax: boolean, hasM
50
35
return 'Metrics browser' ;
51
36
}
52
37
53
- export function willApplySuggestion ( suggestion : string , { typeaheadContext, typeaheadText } : SuggestionsState ) : string {
54
- // Modify suggestion based on context
55
- switch ( typeaheadContext ) {
56
- case 'context-labels' : {
57
- const nextChar = DOMUtil . getNextCharacter ( ) ;
58
- if ( ! nextChar || nextChar === '}' || nextChar === ',' ) {
59
- suggestion += '=' ;
60
- }
61
- break ;
62
- }
63
-
64
- case 'context-label-values' : {
65
- // Always add quotes and remove existing ones instead
66
- if ( ! typeaheadText . match ( / ^ ( ! ? = ~ ? " | " ) / ) ) {
67
- suggestion = `"${ suggestion } ` ;
68
- }
69
- if ( DOMUtil . getNextCharacter ( ) !== '"' ) {
70
- suggestion = `${ suggestion } "` ;
71
- }
72
- break ;
73
- }
74
-
75
- default :
76
- }
77
- return suggestion ;
78
- }
79
-
80
38
interface PromQueryFieldProps extends QueryEditorProps < PrometheusDatasource , PromQuery , PromOptions > , Themeable2 {
81
39
ExtraFieldElement ?: ReactNode ;
82
40
'data-testid' ?: string ;
@@ -89,23 +47,11 @@ interface PromQueryFieldState {
89
47
}
90
48
91
49
class PromQueryField extends React . PureComponent < PromQueryFieldProps , PromQueryFieldState > {
92
- plugins : Array < Plugin < Editor > > ;
93
50
declare languageProviderInitializationPromise : CancelablePromise < any > ;
94
51
95
52
constructor ( props : PromQueryFieldProps , context : React . Context < any > ) {
96
53
super ( props , context ) ;
97
54
98
- this . plugins = [
99
- BracesPlugin ( ) ,
100
- SlatePrism (
101
- {
102
- onlyIn : ( node : any ) => node . type === 'code_block' ,
103
- getSyntax : ( node : any ) => 'promql' ,
104
- } ,
105
- { ...( prismLanguages as LanguageMap ) , promql : this . props . datasource . languageProvider . syntax }
106
- ) ,
107
- ] ;
108
-
109
55
this . state = {
110
56
labelBrowserVisible : false ,
111
57
syntaxLoaded : false ,
@@ -254,26 +200,6 @@ class PromQueryField extends React.PureComponent<PromQueryFieldProps, PromQueryF
254
200
this . setState ( { syntaxLoaded : true } ) ;
255
201
} ;
256
202
257
- onTypeahead = async ( typeahead : TypeaheadInput ) : Promise < TypeaheadOutput > => {
258
- const {
259
- datasource : { languageProvider } ,
260
- } = this . props ;
261
-
262
- if ( ! languageProvider ) {
263
- return { suggestions : [ ] } ;
264
- }
265
-
266
- const { history } = this . props ;
267
- const { prefix, text, value, wrapperClasses, labelKey } = typeahead ;
268
-
269
- const result = await languageProvider . provideCompletionItems (
270
- { text, value, prefix, wrapperClasses, labelKey } ,
271
- { history }
272
- ) ;
273
-
274
- return result ;
275
- } ;
276
-
277
203
render ( ) {
278
204
const {
279
205
datasource,
0 commit comments