@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.
@@ -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;
@@ -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;
@@ -22,6 +22,7 @@ export interface DataProviderParams {
22
22
  url?: string;
23
23
  lookbackInterval?: number;
24
24
  variablesNames?: string[];
25
+ durationVariablesCompletion?: boolean;
25
26
  request: FetchFn;
26
27
  httpMethod?: 'POST' | 'GET';
27
28
  apiPrefix?: string;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.2",
6
+ "version": "0.1.3",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
9
9
  "module": "dist/monaco-editor.esm.js",
@@ -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[] = ['$__interval', '$__range', '$__rate_interval', '1m', '5m', '10m', '30m', '1h', '1d'].map((text) => ({
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);
@@ -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 = {
@@ -28,6 +28,7 @@ export interface DataProviderParams {
28
28
  url?: string;
29
29
  lookbackInterval?: number;
30
30
  variablesNames?: string[];
31
+ durationVariablesCompletion?: boolean;
31
32
  request: FetchFn;
32
33
  httpMethod?: 'POST' | 'GET';
33
34
  apiPrefix?: string;