@fc-components/monaco-editor 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -5
- package/dist/monaco-editor.cjs.development.js +26 -13
- package/dist/monaco-editor.cjs.development.js.map +1 -1
- package/dist/monaco-editor.cjs.production.min.js +1 -1
- package/dist/monaco-editor.cjs.production.min.js.map +1 -1
- package/dist/monaco-editor.esm.js +26 -13
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/completion/DataProvider.d.ts +1 -0
- package/dist/promql/index.d.ts +1 -0
- package/dist/promql/types.d.ts +1 -0
- package/package.json +1 -1
- package/src/promql/completion/DataProvider.ts +2 -0
- package/src/promql/completion/completions.ts +10 -1
- package/src/promql/index.tsx +14 -12
- package/src/promql/types.ts +1 -0
|
@@ -13,6 +13,7 @@ export declare class DataProvider {
|
|
|
13
13
|
metrics: string[];
|
|
14
14
|
labelKeys: string[];
|
|
15
15
|
metricsMetadata?: PromMetricsMetadata;
|
|
16
|
+
durationVariablesCompletion: boolean;
|
|
16
17
|
constructor(params: DataProviderParams);
|
|
17
18
|
getVariablesNames(): string[];
|
|
18
19
|
setVariablesNames(variablesNames: string[]): void;
|
package/dist/promql/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ interface PromQLEditorProps {
|
|
|
6
6
|
value?: string;
|
|
7
7
|
placeholder?: string;
|
|
8
8
|
enableAutocomplete?: boolean;
|
|
9
|
+
durationVariablesCompletion?: boolean;
|
|
9
10
|
interpolateString?: (query: string) => string;
|
|
10
11
|
onChange?: (value: string) => void;
|
|
11
12
|
onShiftEnter?: (value: string) => void;
|
package/dist/promql/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -30,6 +30,7 @@ export class DataProvider {
|
|
|
30
30
|
metrics: string[];
|
|
31
31
|
labelKeys: string[];
|
|
32
32
|
metricsMetadata?: PromMetricsMetadata;
|
|
33
|
+
durationVariablesCompletion: boolean;
|
|
33
34
|
|
|
34
35
|
constructor(params: DataProviderParams) {
|
|
35
36
|
this.inputInRange = '';
|
|
@@ -44,6 +45,7 @@ export class DataProvider {
|
|
|
44
45
|
if (params.variablesNames) {
|
|
45
46
|
this.variablesNames = [...params.variablesNames];
|
|
46
47
|
}
|
|
48
|
+
this.durationVariablesCompletion = params.durationVariablesCompletion ?? true;
|
|
47
49
|
if (params.request) {
|
|
48
50
|
this.customRequest = params.request;
|
|
49
51
|
}
|
|
@@ -61,7 +61,13 @@ async function getAllFunctionsAndMetricNamesCompletions(dataProvider: DataProvid
|
|
|
61
61
|
return [...FUNCTION_COMPLETIONS, ...metricNames];
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
const DURATION_COMPLETIONS: Completion[] = ['
|
|
64
|
+
const DURATION_COMPLETIONS: Completion[] = ['1m', '5m', '10m', '30m', '1h', '1d'].map((text) => ({
|
|
65
|
+
type: 'DURATION',
|
|
66
|
+
label: text,
|
|
67
|
+
insertText: text,
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
const DURATION_VARIABLES_COMPLETIONS: Completion[] = ['$__interval', '$__range', '$__rate_interval'].map((text) => ({
|
|
65
71
|
type: 'DURATION',
|
|
66
72
|
label: text,
|
|
67
73
|
insertText: text,
|
|
@@ -165,6 +171,9 @@ async function getLabelValuesForMetricCompletions(
|
|
|
165
171
|
export function getCompletions(situation: Situation, dataProvider: DataProvider): Promise<Completion[]> {
|
|
166
172
|
switch (situation.type) {
|
|
167
173
|
case 'IN_DURATION':
|
|
174
|
+
if (dataProvider.durationVariablesCompletion) {
|
|
175
|
+
return Promise.resolve(DURATION_VARIABLES_COMPLETIONS.concat(DURATION_COMPLETIONS));
|
|
176
|
+
}
|
|
168
177
|
return Promise.resolve(DURATION_COMPLETIONS);
|
|
169
178
|
case 'IN_FUNCTION':
|
|
170
179
|
return getAllFunctionsAndMetricNamesCompletions(dataProvider);
|
package/src/promql/index.tsx
CHANGED
|
@@ -19,6 +19,7 @@ interface PromQLEditorProps {
|
|
|
19
19
|
value?: string;
|
|
20
20
|
placeholder?: string;
|
|
21
21
|
enableAutocomplete?: boolean;
|
|
22
|
+
durationVariablesCompletion?: boolean;
|
|
22
23
|
interpolateString?: (query: string) => string;
|
|
23
24
|
onChange?: (value: string) => void;
|
|
24
25
|
onShiftEnter?: (value: string) => void;
|
|
@@ -107,19 +108,20 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
107
108
|
isEditorFocused.set(true);
|
|
108
109
|
});
|
|
109
110
|
|
|
110
|
-
const dataProvider = new DataProvider({
|
|
111
|
-
url: props.url,
|
|
112
|
-
lookbackInterval: props.lookbackInterval,
|
|
113
|
-
variablesNames: props.variablesNames,
|
|
114
|
-
request: props.request,
|
|
115
|
-
httpMethod: props.httpMethod,
|
|
116
|
-
apiPrefix: props.apiPrefix,
|
|
117
|
-
httpErrorHandler: props.httpErrorHandler,
|
|
118
|
-
});
|
|
119
|
-
dataProviderRef.current = dataProvider;
|
|
120
|
-
dataProvider.start();
|
|
121
|
-
|
|
122
111
|
if (enableAutocomplete) {
|
|
112
|
+
const dataProvider = new DataProvider({
|
|
113
|
+
url: props.url,
|
|
114
|
+
lookbackInterval: props.lookbackInterval,
|
|
115
|
+
variablesNames: props.variablesNames,
|
|
116
|
+
durationVariablesCompletion: props.durationVariablesCompletion,
|
|
117
|
+
request: props.request,
|
|
118
|
+
httpMethod: props.httpMethod,
|
|
119
|
+
apiPrefix: props.apiPrefix,
|
|
120
|
+
httpErrorHandler: props.httpErrorHandler,
|
|
121
|
+
});
|
|
122
|
+
dataProviderRef.current = dataProvider;
|
|
123
|
+
dataProvider.start();
|
|
124
|
+
|
|
123
125
|
const completionProvider = getCompletionProvider(monaco, dataProvider);
|
|
124
126
|
|
|
125
127
|
const filteringCompletionProvider: monacoTypes.languages.CompletionItemProvider = {
|
package/src/promql/types.ts
CHANGED