@fc-components/monaco-editor 0.1.15 → 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.
@@ -6,7 +6,6 @@ import { promLanguageDefinition } from 'monaco-promql';
6
6
  import { parser, LabelMatchers, VectorSelector, PromQL, FunctionCallBody, StringLiteral, UnquotedLabelMatcher, BinaryExpr, NumberDurationLiteralInDurationContext, MatrixSelector, GroupingLabels, AggregateModifier, AggregateExpr, Identifier, LabelName, MatchOp, EqlSingle, EqlRegex, Neq, NeqRegex } from '@fc-components/lezer-metricsql';
7
7
  import { v4 } from 'uuid';
8
8
  import { css } from '@emotion/css';
9
- import UFuzzy from '@leeoniya/ufuzzy';
10
9
 
11
10
  function _arrayLikeToArray(r, a) {
12
11
  (null == a || a > r.length) && (a = r.length);
@@ -875,6 +874,7 @@ var DataProvider = /*#__PURE__*/function () {
875
874
  this.variablesNames = [];
876
875
  this.httpMethod = 'GET';
877
876
  this.apiPrefix = '/api/v1';
877
+ this.enableRequests = true;
878
878
  this.customRequest = function (input, init) {
879
879
  return fetch(input, init);
880
880
  };
@@ -884,6 +884,12 @@ var DataProvider = /*#__PURE__*/function () {
884
884
  return _regenerator().w(function (_context) {
885
885
  while (1) switch (_context.n) {
886
886
  case 0:
887
+ if (_this.enableRequests) {
888
+ _context.n = 1;
889
+ break;
890
+ }
891
+ return _context.a(2, []);
892
+ case 1:
887
893
  end = new Date();
888
894
  start = new Date(end.getTime() - _this.lookbackInterval);
889
895
  url = _this.apiPrefix + "/series";
@@ -900,14 +906,14 @@ var DataProvider = /*#__PURE__*/function () {
900
906
  });
901
907
  }
902
908
  request = _this.buildRequest(url, new URLSearchParams(urlParams));
903
- _context.n = 1;
909
+ _context.n = 2;
904
910
  return _this.request(request.uri, {
905
911
  method: _this.httpMethod,
906
912
  body: request.body
907
913
  })["catch"](function () {
908
914
  return [];
909
915
  });
910
- case 1:
916
+ case 2:
911
917
  return _context.a(2, _context.v);
912
918
  }
913
919
  }, _callee);
@@ -922,6 +928,12 @@ var DataProvider = /*#__PURE__*/function () {
922
928
  return _regenerator().w(function (_context2) {
923
929
  while (1) switch (_context2.n) {
924
930
  case 0:
931
+ if (_this.enableRequests) {
932
+ _context2.n = 1;
933
+ break;
934
+ }
935
+ return _context2.a(2, []);
936
+ case 1:
925
937
  end = new Date();
926
938
  start = new Date(end.getTime() - _this.lookbackInterval);
927
939
  url = _this.apiPrefix + "/labels";
@@ -933,7 +945,7 @@ var DataProvider = /*#__PURE__*/function () {
933
945
  urlParams['match[]'] = selector;
934
946
  }
935
947
  request = _this.buildRequest(url, new URLSearchParams(urlParams));
936
- _context2.n = 1;
948
+ _context2.n = 2;
937
949
  return _this.request(request.uri, {
938
950
  method: _this.httpMethod,
939
951
  body: request.body
@@ -943,7 +955,7 @@ var DataProvider = /*#__PURE__*/function () {
943
955
  })["catch"](function () {
944
956
  return [];
945
957
  });
946
- case 1:
958
+ case 2:
947
959
  return _context2.a(2, _context2.v);
948
960
  }
949
961
  }, _callee2);
@@ -958,6 +970,12 @@ var DataProvider = /*#__PURE__*/function () {
958
970
  return _regenerator().w(function (_context3) {
959
971
  while (1) switch (_context3.n) {
960
972
  case 0:
973
+ if (_this.enableRequests) {
974
+ _context3.n = 1;
975
+ break;
976
+ }
977
+ return _context3.a(2, []);
978
+ case 1:
961
979
  end = new Date();
962
980
  start = new Date(end.getTime() - _this.lookbackInterval);
963
981
  url = _this.apiPrefix + "/label/" + labelName + "/values";
@@ -969,14 +987,14 @@ var DataProvider = /*#__PURE__*/function () {
969
987
  urlParams['match[]'] = selector;
970
988
  }
971
989
  request = _this.buildRequest(url, new URLSearchParams(urlParams));
972
- _context3.n = 1;
990
+ _context3.n = 2;
973
991
  return _this.request(request.uri, {
974
992
  method: _this.httpMethod,
975
993
  body: request.body
976
994
  })["catch"](function () {
977
995
  return [];
978
996
  });
979
- case 1:
997
+ case 2:
980
998
  return _context3.a(2, _context3.v);
981
999
  }
982
1000
  }, _callee3);
@@ -1026,6 +1044,10 @@ var DataProvider = /*#__PURE__*/function () {
1026
1044
  if (params.apiPrefix) {
1027
1045
  this.apiPrefix = params.apiPrefix;
1028
1046
  }
1047
+ // control whether DataProvider should actually send network requests
1048
+ if (typeof params.enableRequests !== 'undefined') {
1049
+ this.enableRequests = !!params.enableRequests;
1050
+ }
1029
1051
  this.metrics = [];
1030
1052
  this.labelKeys = [];
1031
1053
  }
@@ -1089,18 +1111,24 @@ var DataProvider = /*#__PURE__*/function () {
1089
1111
  return _regenerator().w(function (_context5) {
1090
1112
  while (1) switch (_context5.n) {
1091
1113
  case 0:
1114
+ if (this.enableRequests) {
1115
+ _context5.n = 1;
1116
+ break;
1117
+ }
1118
+ this.metricsMetadata = {};
1119
+ return _context5.a(2, this.metricsMetadata);
1120
+ case 1:
1092
1121
  request = this.buildRequest(this.apiPrefix + "/metadata", new URLSearchParams({}));
1093
- _context5.n = 1;
1122
+ _context5.n = 2;
1094
1123
  return this.request(request.uri, {
1095
1124
  method: this.httpMethod,
1096
1125
  body: request.body
1097
1126
  })["catch"](function () {
1098
1127
  return {};
1099
1128
  });
1100
- case 1:
1101
- this.metricsMetadata = _context5.v;
1102
1129
  case 2:
1103
- return _context5.a(2);
1130
+ this.metricsMetadata = _context5.v;
1131
+ return _context5.a(2, this.metricsMetadata || {});
1104
1132
  }
1105
1133
  }, _callee5, this);
1106
1134
  }));
@@ -1487,24 +1515,23 @@ function notEmpty(value) {
1487
1515
  return value !== null && value !== undefined;
1488
1516
  }
1489
1517
 
1490
- var metricNamesSearchClient = /*#__PURE__*/new UFuzzy({
1491
- intraMode: 1
1492
- });
1518
+ // const metricNamesSearchClient = new UFuzzy({ intraMode: 1 });
1493
1519
  // we order items like: history, functions, metrics
1494
1520
  function getAllMetricNamesCompletions(dataProvider) {
1495
1521
  var metricNames = dataProvider.getAllMetricNames();
1496
- if (metricNames.length > dataProvider.metricNamesSuggestionLimit) {
1497
- var monacoSettings = dataProvider.monacoSettings;
1498
- monacoSettings.enableAutocompleteSuggestionsUpdate();
1499
- if (monacoSettings.inputInRange) {
1500
- var _metricNamesSearchCli, _metricNamesSearchCli2;
1501
- metricNames = (_metricNamesSearchCli = (_metricNamesSearchCli2 = metricNamesSearchClient.filter(metricNames, monacoSettings.inputInRange)) == null ? void 0 : _metricNamesSearchCli2.slice(0, dataProvider.metricNamesSuggestionLimit).map(function (idx) {
1502
- return metricNames[idx];
1503
- })) != null ? _metricNamesSearchCli : [];
1504
- } else {
1505
- metricNames = metricNames.slice(0, dataProvider.metricNamesSuggestionLimit);
1506
- }
1507
- }
1522
+ // if (metricNames.length > dataProvider.metricNamesSuggestionLimit) {
1523
+ // const { monacoSettings } = dataProvider;
1524
+ // monacoSettings.enableAutocompleteSuggestionsUpdate();
1525
+ // if (monacoSettings.inputInRange) {
1526
+ // metricNames =
1527
+ // metricNamesSearchClient
1528
+ // .filter(metricNames, monacoSettings.inputInRange)
1529
+ // ?.slice(0, dataProvider.metricNamesSuggestionLimit)
1530
+ // .map((idx) => metricNames[idx]) ?? [];
1531
+ // } else {
1532
+ // metricNames = metricNames.slice(0, dataProvider.metricNamesSuggestionLimit);
1533
+ // }
1534
+ // }
1508
1535
  return dataProvider.metricNamesToMetrics(metricNames).map(function (metric) {
1509
1536
  return {
1510
1537
  type: 'METRIC_NAME',
@@ -1728,7 +1755,7 @@ function _getLabelValues() {
1728
1755
  }
1729
1756
  return _context6.a(3, 7);
1730
1757
  case 6:
1731
- if (key === labelName) {
1758
+ if (key === labelName && value) {
1732
1759
  labelValues.add(value);
1733
1760
  }
1734
1761
  case 7:
@@ -2001,6 +2028,8 @@ function PromQLEditor(props) {
2001
2028
  interpolateString = props.interpolateString,
2002
2029
  _props$enableAutocomp = props.enableAutocomplete,
2003
2030
  enableAutocomplete = _props$enableAutocomp === void 0 ? true : _props$enableAutocomp,
2031
+ _props$enableRequests = props.enableRequests,
2032
+ enableRequests = _props$enableRequests === void 0 ? true : _props$enableRequests,
2004
2033
  _props$readOnly = props.readOnly,
2005
2034
  readOnly = _props$readOnly === void 0 ? false : _props$readOnly,
2006
2035
  _props$disabled = props.disabled,
@@ -2153,7 +2182,8 @@ function PromQLEditor(props) {
2153
2182
  request: props.request,
2154
2183
  httpMethod: props.httpMethod,
2155
2184
  apiPrefix: props.apiPrefix,
2156
- httpErrorHandler: props.httpErrorHandler
2185
+ httpErrorHandler: props.httpErrorHandler,
2186
+ enableRequests: enableRequests
2157
2187
  });
2158
2188
  dataProviderRef.current = dataProvider;
2159
2189
  dataProvider.start();
@@ -2200,7 +2230,7 @@ function PromQLEditor(props) {
2200
2230
  checkDecorators();
2201
2231
  editor.onDidChangeModelContent(checkDecorators);
2202
2232
  }
2203
- }, [enableAutocomplete, props.url, props.lookbackInterval, JSON.stringify(props.variablesNames), props.durationVariablesCompletion, props.httpMethod, props.apiPrefix, placeholder]);
2233
+ }, [enableAutocomplete, props.url, props.lookbackInterval, JSON.stringify(props.variablesNames), props.durationVariablesCompletion, props.httpMethod, props.apiPrefix, placeholder, enableRequests]);
2204
2234
  return React.createElement("div", {
2205
2235
  className: 'ant-input' + (size ? " " + SIZE_MAP[size].className : '') + (disabled ? " ant-input-disabled " + containerDisabledClassName : '') + (readOnly ? " " + containerReadOnlyClassName : '')
2206
2236
  }, React.createElement("div", {