@fc-components/monaco-editor 0.1.16 → 0.1.17
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/dist/monaco-editor.cjs.development.js +44 -12
- 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 +44 -12
- package/dist/monaco-editor.esm.js.map +1 -1
- package/dist/promql/completion/DataProvider.d.ts +3 -2
- 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 +22 -1
- package/src/promql/index.tsx +5 -0
- package/src/promql/types.ts +2 -0
|
@@ -9,6 +9,7 @@ export declare class DataProvider {
|
|
|
9
9
|
private readonly errorHandler?;
|
|
10
10
|
private readonly httpMethod;
|
|
11
11
|
private readonly apiPrefix;
|
|
12
|
+
private enableRequests;
|
|
12
13
|
private readonly customRequest;
|
|
13
14
|
metrics: string[];
|
|
14
15
|
labelKeys: string[];
|
|
@@ -23,8 +24,8 @@ export declare class DataProvider {
|
|
|
23
24
|
fetchLabels: (selector: string) => Promise<string[]>;
|
|
24
25
|
fetchLabelValues: (labelName: string, selector: string) => Promise<string[]>;
|
|
25
26
|
getAllMetricNames(): string[];
|
|
26
|
-
start: () => Promise<
|
|
27
|
-
loadMetricsMetadata(): Promise<
|
|
27
|
+
start: () => Promise<PromMetricsMetadata[]>;
|
|
28
|
+
loadMetricsMetadata(): Promise<PromMetricsMetadata>;
|
|
28
29
|
metricNamesToMetrics(metricNames: string[]): Metric[];
|
|
29
30
|
private setInputInRange;
|
|
30
31
|
private enableAutocompleteSuggestionsUpdate;
|
package/dist/promql/index.d.ts
CHANGED
package/dist/promql/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -26,6 +26,7 @@ export class DataProvider {
|
|
|
26
26
|
private readonly errorHandler?: (error: any) => void;
|
|
27
27
|
private readonly httpMethod: 'POST' | 'GET' = 'GET';
|
|
28
28
|
private readonly apiPrefix: string = '/api/v1';
|
|
29
|
+
private enableRequests: boolean = true;
|
|
29
30
|
private readonly customRequest: CustomRequest = (input: RequestInfo, init?: RequestInit): Promise<Response> => fetch(input, init);
|
|
30
31
|
metrics: string[];
|
|
31
32
|
labelKeys: string[];
|
|
@@ -56,6 +57,11 @@ export class DataProvider {
|
|
|
56
57
|
this.apiPrefix = params.apiPrefix;
|
|
57
58
|
}
|
|
58
59
|
|
|
60
|
+
// control whether DataProvider should actually send network requests
|
|
61
|
+
if (typeof params.enableRequests !== 'undefined') {
|
|
62
|
+
this.enableRequests = !!params.enableRequests;
|
|
63
|
+
}
|
|
64
|
+
|
|
59
65
|
this.metrics = [];
|
|
60
66
|
this.labelKeys = [];
|
|
61
67
|
}
|
|
@@ -113,6 +119,9 @@ export class DataProvider {
|
|
|
113
119
|
}
|
|
114
120
|
|
|
115
121
|
fetchSeries = async (selector: string, withLimit?: string): Promise<Record<string, string | undefined>[]> => {
|
|
122
|
+
if (!this.enableRequests) {
|
|
123
|
+
return [] as Record<string, string | undefined>[];
|
|
124
|
+
}
|
|
116
125
|
const end = new Date();
|
|
117
126
|
const start = new Date(end.getTime() - this.lookbackInterval);
|
|
118
127
|
const url = `${this.apiPrefix}/series`;
|
|
@@ -138,6 +147,9 @@ export class DataProvider {
|
|
|
138
147
|
};
|
|
139
148
|
|
|
140
149
|
fetchLabels = async (selector: string): Promise<string[]> => {
|
|
150
|
+
if (!this.enableRequests) {
|
|
151
|
+
return [] as string[];
|
|
152
|
+
}
|
|
141
153
|
const end = new Date();
|
|
142
154
|
const start = new Date(end.getTime() - this.lookbackInterval);
|
|
143
155
|
const url = `${this.apiPrefix}/labels`;
|
|
@@ -164,6 +176,9 @@ export class DataProvider {
|
|
|
164
176
|
};
|
|
165
177
|
|
|
166
178
|
fetchLabelValues = async (labelName: string, selector: string): Promise<string[]> => {
|
|
179
|
+
if (!this.enableRequests) {
|
|
180
|
+
return [] as string[];
|
|
181
|
+
}
|
|
167
182
|
const end = new Date();
|
|
168
183
|
const start = new Date(end.getTime() - this.lookbackInterval);
|
|
169
184
|
const url = `${this.apiPrefix}/label/${labelName}/values`;
|
|
@@ -198,7 +213,11 @@ export class DataProvider {
|
|
|
198
213
|
]);
|
|
199
214
|
};
|
|
200
215
|
|
|
201
|
-
async loadMetricsMetadata() {
|
|
216
|
+
async loadMetricsMetadata(): Promise<PromMetricsMetadata> {
|
|
217
|
+
if (!this.enableRequests) {
|
|
218
|
+
this.metricsMetadata = {} as PromMetricsMetadata;
|
|
219
|
+
return this.metricsMetadata;
|
|
220
|
+
}
|
|
202
221
|
const request = this.buildRequest(`${this.apiPrefix}/metadata`, new URLSearchParams({}));
|
|
203
222
|
this.metricsMetadata = await this.request<PromMetricsMetadata>(request.uri, {
|
|
204
223
|
method: this.httpMethod,
|
|
@@ -206,6 +225,8 @@ export class DataProvider {
|
|
|
206
225
|
}).catch(() => {
|
|
207
226
|
return {} as PromMetricsMetadata;
|
|
208
227
|
});
|
|
228
|
+
|
|
229
|
+
return this.metricsMetadata || ({} as PromMetricsMetadata);
|
|
209
230
|
}
|
|
210
231
|
|
|
211
232
|
metricNamesToMetrics(metricNames: string[]): Metric[] {
|
package/src/promql/index.tsx
CHANGED
|
@@ -20,6 +20,8 @@ interface PromQLEditorProps {
|
|
|
20
20
|
placeholder?: string;
|
|
21
21
|
enableAutocomplete?: boolean;
|
|
22
22
|
durationVariablesCompletion?: boolean;
|
|
23
|
+
// When false, DataProvider will not send network requests. Default: true
|
|
24
|
+
enableRequests?: boolean;
|
|
23
25
|
readOnly?: boolean;
|
|
24
26
|
disabled?: boolean;
|
|
25
27
|
interpolateString?: (query: string) => string;
|
|
@@ -92,6 +94,7 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
92
94
|
placeholder,
|
|
93
95
|
interpolateString,
|
|
94
96
|
enableAutocomplete = true,
|
|
97
|
+
enableRequests = true,
|
|
95
98
|
readOnly = false,
|
|
96
99
|
disabled = false,
|
|
97
100
|
onChange,
|
|
@@ -266,6 +269,7 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
266
269
|
httpMethod: props.httpMethod,
|
|
267
270
|
apiPrefix: props.apiPrefix,
|
|
268
271
|
httpErrorHandler: props.httpErrorHandler,
|
|
272
|
+
enableRequests: enableRequests,
|
|
269
273
|
});
|
|
270
274
|
dataProviderRef.current = dataProvider;
|
|
271
275
|
dataProvider.start();
|
|
@@ -331,6 +335,7 @@ export default function PromQLEditor(props: PromQLEditorProps & DataProviderPara
|
|
|
331
335
|
props.httpMethod,
|
|
332
336
|
props.apiPrefix,
|
|
333
337
|
placeholder,
|
|
338
|
+
enableRequests,
|
|
334
339
|
]);
|
|
335
340
|
|
|
336
341
|
return (
|
package/src/promql/types.ts
CHANGED