@perses-dev/prometheus-plugin 0.52.1 → 0.53.1

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.
Files changed (154) hide show
  1. package/__mf/js/Prometheus.c0c6219f.js +5 -0
  2. package/__mf/js/async/1101.9cf067ee.js +73 -0
  3. package/__mf/js/async/1441.c735f7dd.js +1 -0
  4. package/__mf/js/async/1576.8eac7ce9.js +1 -0
  5. package/__mf/js/async/1964.1d168a86.js +2 -0
  6. package/__mf/js/async/212.69f85c2b.js +1 -0
  7. package/__mf/js/async/2188.d2c5eadd.js +1 -0
  8. package/__mf/js/async/2292.57d8fd0d.js +2 -0
  9. package/__mf/js/async/2675.27451820.js +1 -0
  10. package/__mf/js/async/3224.b63f87bf.js +1 -0
  11. package/__mf/js/async/3507.f1653337.js +101 -0
  12. package/__mf/js/async/3863.7192dfdf.js +2 -0
  13. package/__mf/js/async/3960.3eedafbd.js +2 -0
  14. package/__mf/js/async/3980.0b0d272c.js +2 -0
  15. package/__mf/js/async/4062.06f48b93.js +1 -0
  16. package/__mf/js/async/4075.88e3f633.js +1 -0
  17. package/__mf/js/async/4238.422a1b1c.js +1 -0
  18. package/__mf/js/async/4323.fdf7d039.js +1 -0
  19. package/__mf/js/async/4368.5aeca58a.js +2 -0
  20. package/__mf/js/async/4368.5aeca58a.js.LICENSE.txt +15 -0
  21. package/__mf/js/async/4421.39621b12.js +1 -0
  22. package/__mf/js/async/4535.f24704ea.js +1 -0
  23. package/__mf/js/async/4665.cad36935.js +1 -0
  24. package/__mf/js/async/5214.0fca84ed.js +1 -0
  25. package/__mf/js/async/5257.ce463cb7.js +1 -0
  26. package/__mf/js/async/537.82230699.js +1 -0
  27. package/__mf/js/async/5409.955ffd51.js +1 -0
  28. package/__mf/js/async/5614.cce8ba96.js +1 -0
  29. package/__mf/js/async/5724.794828e3.js +1 -0
  30. package/__mf/js/async/5774.a3fae698.js +1 -0
  31. package/__mf/js/async/5790.a9b31ca8.js +1 -0
  32. package/__mf/js/async/5876.1976752d.js +2 -0
  33. package/__mf/js/async/{3057.e568f9b6.js.LICENSE.txt → 5876.1976752d.js.LICENSE.txt} +1 -23
  34. package/__mf/js/async/5981.eb502d27.js +2 -0
  35. package/__mf/js/async/6292.2afe0c6d.js +1 -0
  36. package/__mf/js/async/6377.c40920f2.js +2 -0
  37. package/__mf/js/async/6441.38c30276.js +7 -0
  38. package/__mf/js/async/6441.38c30276.js.LICENSE.txt +21 -0
  39. package/__mf/js/async/6770.7099bb3b.js +1 -0
  40. package/__mf/js/async/684.f7b5c16e.js +1 -0
  41. package/__mf/js/async/694.8462a746.js +1 -0
  42. package/__mf/js/async/7272.6fa2f127.js +1 -0
  43. package/__mf/js/async/7376.2e948f2b.js +1 -0
  44. package/__mf/js/async/738.a1ffff79.js +1 -0
  45. package/__mf/js/async/7740.a8777825.js +1 -0
  46. package/__mf/js/async/8045.7f554a45.js +10 -0
  47. package/__mf/js/async/8216.e689c178.js +1 -0
  48. package/__mf/js/async/8488.cbbe542b.js +1 -0
  49. package/__mf/js/async/8587.40df6f5c.js +1 -0
  50. package/__mf/js/async/8706.9a6f6579.js +1 -0
  51. package/__mf/js/async/8930.700a5439.js +1 -0
  52. package/__mf/js/async/9173.915b80af.js +2 -0
  53. package/__mf/js/async/9550.642ce5ad.js +38 -0
  54. package/__mf/js/async/9817.70eae424.js +1 -0
  55. package/__mf/js/async/__federation_expose_PrometheusDatasource.71aecfaf.js +1 -0
  56. package/__mf/js/async/__federation_expose_PrometheusExplorer.80dd9b47.js +1 -0
  57. package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.86bf76a6.js +1 -0
  58. package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.e5e35f24.js +1 -0
  59. package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.b2270799.js +1 -0
  60. package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.c29461ad.js +1 -0
  61. package/__mf/js/main.afd47409.js +5 -0
  62. package/lib/cjs/components/PromQLEditor.js +1 -0
  63. package/lib/cjs/components/TreeNode.js +9 -1
  64. package/lib/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +48 -10
  65. package/lib/cjs/plugins/prometheus-variables.js +108 -46
  66. package/lib/components/PromQLEditor.d.ts.map +1 -1
  67. package/lib/components/PromQLEditor.js +1 -0
  68. package/lib/components/PromQLEditor.js.map +1 -1
  69. package/lib/components/TreeNode.js +9 -1
  70. package/lib/components/TreeNode.js.map +1 -1
  71. package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
  72. package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +48 -10
  73. package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  74. package/lib/plugins/prometheus-variables.d.ts.map +1 -1
  75. package/lib/plugins/prometheus-variables.js +115 -47
  76. package/lib/plugins/prometheus-variables.js.map +1 -1
  77. package/lib/plugins/test/setup-tests.d.ts.map +1 -0
  78. package/lib/plugins/test/setup-tests.js.map +1 -0
  79. package/mf-manifest.json +262 -483
  80. package/mf-stats.json +270 -491
  81. package/package.json +8 -8
  82. package/__mf/js/622.cc663737.js +0 -5
  83. package/__mf/js/Prometheus.6aae9c64.js +0 -5
  84. package/__mf/js/async/1465.3b5e12d5.js +0 -1
  85. package/__mf/js/async/1620.6376bd14.js +0 -2
  86. package/__mf/js/async/1964.95da06f6.js +0 -2
  87. package/__mf/js/async/212.bd5d617a.js +0 -1
  88. package/__mf/js/async/2285.15378f70.js +0 -1
  89. package/__mf/js/async/2569.daf868a6.js +0 -10
  90. package/__mf/js/async/2675.99cf926f.js +0 -1
  91. package/__mf/js/async/3057.e568f9b6.js +0 -7
  92. package/__mf/js/async/3090.9fb5fe73.js +0 -2
  93. package/__mf/js/async/3224.23f0dccf.js +0 -1
  94. package/__mf/js/async/3355.a4dbcdb0.js +0 -1
  95. package/__mf/js/async/3818.dde21d04.js +0 -1
  96. package/__mf/js/async/3871.6915e369.js +0 -1
  97. package/__mf/js/async/3960.129d5ef5.js +0 -2
  98. package/__mf/js/async/3980.7cea5715.js +0 -2
  99. package/__mf/js/async/4062.3ab7f987.js +0 -1
  100. package/__mf/js/async/4075.b77ca1c7.js +0 -1
  101. package/__mf/js/async/4238.8e4d29d5.js +0 -1
  102. package/__mf/js/async/4323.4266fd6a.js +0 -1
  103. package/__mf/js/async/4421.42e889f6.js +0 -1
  104. package/__mf/js/async/5214.027c4332.js +0 -1
  105. package/__mf/js/async/528.d364bb0e.js +0 -1
  106. package/__mf/js/async/5345.1f4fc17b.js +0 -1
  107. package/__mf/js/async/537.6911ea2e.js +0 -1
  108. package/__mf/js/async/5503.a728b5d7.js +0 -1
  109. package/__mf/js/async/5724.6ee6ec51.js +0 -1
  110. package/__mf/js/async/5769.f14c9663.js +0 -1
  111. package/__mf/js/async/5774.9b0b6be1.js +0 -1
  112. package/__mf/js/async/5790.2273e061.js +0 -1
  113. package/__mf/js/async/5913.4e5abd09.js +0 -73
  114. package/__mf/js/async/5914.bd342d22.js +0 -74
  115. package/__mf/js/async/5981.40bed0d0.js +0 -2
  116. package/__mf/js/async/6292.7b8efa78.js +0 -1
  117. package/__mf/js/async/6377.ca974d89.js +0 -2
  118. package/__mf/js/async/6770.adb1c939.js +0 -1
  119. package/__mf/js/async/684.ca510333.js +0 -1
  120. package/__mf/js/async/694.f861d67c.js +0 -1
  121. package/__mf/js/async/7272.a763aa92.js +0 -1
  122. package/__mf/js/async/7376.c7eb05b9.js +0 -1
  123. package/__mf/js/async/738.aca54e25.js +0 -1
  124. package/__mf/js/async/7740.0c5363fd.js +0 -1
  125. package/__mf/js/async/8488.5237550f.js +0 -1
  126. package/__mf/js/async/8587.4891ea90.js +0 -1
  127. package/__mf/js/async/8930.9fbbc975.js +0 -1
  128. package/__mf/js/async/8980.afe002d4.js +0 -28
  129. package/__mf/js/async/9173.e8fbead5.js +0 -2
  130. package/__mf/js/async/9550.e19763f8.js +0 -38
  131. package/__mf/js/async/__federation_expose_PrometheusDatasource.f9c8cf41.js +0 -1
  132. package/__mf/js/async/__federation_expose_PrometheusExplorer.171d04eb.js +0 -1
  133. package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.8551745e.js +0 -1
  134. package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.a4085adb.js +0 -1
  135. package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.46f99477.js +0 -1
  136. package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.fc3c5730.js +0 -1
  137. package/__mf/js/main.1c9e712b.js +0 -1
  138. package/lib/test/setup-tests.d.ts.map +0 -1
  139. package/lib/test/setup-tests.js.map +0 -1
  140. /package/__mf/css/async/{5263.dacad691.css → 1576.dacad691.css} +0 -0
  141. /package/__mf/css/async/{6759.dacad691.css → 2188.dacad691.css} +0 -0
  142. /package/__mf/js/async/{5913.4e5abd09.js.LICENSE.txt → 1101.9cf067ee.js.LICENSE.txt} +0 -0
  143. /package/__mf/js/async/{1964.95da06f6.js.LICENSE.txt → 1964.1d168a86.js.LICENSE.txt} +0 -0
  144. /package/__mf/js/async/{3090.9fb5fe73.js.LICENSE.txt → 2292.57d8fd0d.js.LICENSE.txt} +0 -0
  145. /package/__mf/js/async/{1620.6376bd14.js.LICENSE.txt → 3863.7192dfdf.js.LICENSE.txt} +0 -0
  146. /package/__mf/js/async/{3960.129d5ef5.js.LICENSE.txt → 3960.3eedafbd.js.LICENSE.txt} +0 -0
  147. /package/__mf/js/async/{3980.7cea5715.js.LICENSE.txt → 3980.0b0d272c.js.LICENSE.txt} +0 -0
  148. /package/__mf/js/async/{5981.40bed0d0.js.LICENSE.txt → 5981.eb502d27.js.LICENSE.txt} +0 -0
  149. /package/__mf/js/async/{6377.ca974d89.js.LICENSE.txt → 6377.c40920f2.js.LICENSE.txt} +0 -0
  150. /package/__mf/js/async/{2569.daf868a6.js.LICENSE.txt → 8045.7f554a45.js.LICENSE.txt} +0 -0
  151. /package/__mf/js/async/{9173.e8fbead5.js.LICENSE.txt → 9173.915b80af.js.LICENSE.txt} +0 -0
  152. /package/lib/cjs/{test → plugins/test}/setup-tests.js +0 -0
  153. /package/lib/{test → plugins/test}/setup-tests.d.ts +0 -0
  154. /package/lib/{test → plugins/test}/setup-tests.js +0 -0
@@ -44,23 +44,53 @@ const _jsxruntime = require("react/jsx-runtime");
44
44
  const _material = require("@mui/material");
45
45
  const _pluginsystem = require("@perses-dev/plugin-system");
46
46
  const _immer = require("immer");
47
+ const _react = require("react");
47
48
  const _components = require("../components");
48
49
  const _model = require("../model");
49
50
  const _MatcherEditor = require("./MatcherEditor");
50
51
  function PrometheusLabelValuesVariableEditor(props) {
51
- const { onChange, value } = props;
52
- const { datasource } = value;
52
+ const { onChange, value, value: { datasource }, queryHandlerSettings } = props;
53
53
  const selectedDatasource = datasource ?? _model.DEFAULT_PROM;
54
- const handleDatasourceChange = (next)=>{
54
+ const [labelValue, setLabelValue] = (0, _react.useState)(props.value.labelName);
55
+ const [matchersValues, setMatchersValues] = (0, _react.useState)(props.value.matchers ?? []);
56
+ const handleDatasourceChange = (0, _react.useCallback)((next)=>{
55
57
  if ((0, _model.isPrometheusDatasourceSelector)(next)) {
56
58
  onChange((0, _immer.produce)(value, (draft)=>{
57
59
  // If they're using the default, just omit the datasource prop (i.e. set to undefined)
58
60
  draft.datasource = (0, _model.isDefaultPromSelector)(next) ? undefined : next;
59
61
  }));
62
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
63
+ ...value,
64
+ datasource: next
65
+ });
60
66
  return;
61
67
  }
62
68
  throw new Error('Got unexpected non-Prometheus datasource selector');
63
- };
69
+ }, [
70
+ onChange,
71
+ queryHandlerSettings,
72
+ value
73
+ ]);
74
+ const handleLabelChange = (0, _react.useCallback)((e)=>{
75
+ setLabelValue(e.target.value);
76
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
77
+ ...value,
78
+ labelName: e.target.value
79
+ });
80
+ }, [
81
+ value,
82
+ queryHandlerSettings
83
+ ]);
84
+ const handleMatchEditorsChange = (0, _react.useCallback)((e)=>{
85
+ setMatchersValues(e);
86
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
87
+ ...value,
88
+ matchers: e
89
+ });
90
+ }, [
91
+ value,
92
+ queryHandlerSettings
93
+ ]);
64
94
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
65
95
  spacing: 2,
66
96
  children: [
@@ -78,44 +108,54 @@ function PrometheusLabelValuesVariableEditor(props) {
78
108
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
79
109
  label: "Label Name",
80
110
  required: true,
81
- value: props.value.labelName,
82
- onChange: (e)=>{
83
- props.onChange({
84
- ...props.value,
85
- labelName: e.target.value
86
- });
87
- },
111
+ value: labelValue,
112
+ onChange: handleLabelChange,
88
113
  InputProps: {
89
114
  readOnly: props.isReadonly
90
115
  }
91
116
  }),
92
117
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_MatcherEditor.MatcherEditor, {
93
- matchers: props.value.matchers ?? [],
94
- onChange: (e)=>{
95
- props.onChange({
96
- ...props.value,
97
- matchers: e
98
- });
99
- },
118
+ matchers: matchersValues,
119
+ onChange: handleMatchEditorsChange,
100
120
  isReadonly: props.isReadonly
101
121
  })
102
122
  ]
103
123
  });
104
124
  }
105
125
  function PrometheusLabelNamesVariableEditor(props) {
106
- const { onChange, value } = props;
107
- const { datasource } = value;
126
+ const { onChange, value, value: { datasource }, queryHandlerSettings } = props;
108
127
  const selectedDatasource = datasource ?? _model.DEFAULT_PROM;
109
- const handleDatasourceChange = (next)=>{
128
+ const [matchersValues, setMatchersValues] = (0, _react.useState)(props.value.matchers ?? []);
129
+ const handleDatasourceChange = (0, _react.useCallback)((next)=>{
110
130
  if ((0, _model.isPrometheusDatasourceSelector)(next)) {
111
131
  onChange((0, _immer.produce)(value, (draft)=>{
112
132
  // If they're using the default, just omit the datasource prop (i.e. set to undefined)
113
133
  draft.datasource = (0, _model.isDefaultPromSelector)(next) ? undefined : next;
114
134
  }));
135
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
136
+ ...value,
137
+ datasource: next
138
+ });
115
139
  return;
116
140
  }
117
141
  throw new Error('Got unexpected non-Prometheus datasource selector');
118
- };
142
+ }, [
143
+ onChange,
144
+ queryHandlerSettings,
145
+ value
146
+ ]);
147
+ const handleMatchEditorChange = (0, _react.useCallback)((e)=>{
148
+ setMatchersValues(e);
149
+ if (queryHandlerSettings?.setWatchOtherSpecs) {
150
+ queryHandlerSettings.setWatchOtherSpecs({
151
+ ...value,
152
+ matchers: e
153
+ });
154
+ }
155
+ }, [
156
+ value,
157
+ queryHandlerSettings
158
+ ]);
119
159
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
120
160
  spacing: 2,
121
161
  children: [
@@ -131,34 +171,65 @@ function PrometheusLabelNamesVariableEditor(props) {
131
171
  })
132
172
  }),
133
173
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_MatcherEditor.MatcherEditor, {
134
- matchers: props.value.matchers ?? [],
174
+ matchers: matchersValues,
135
175
  isReadonly: props.isReadonly,
136
- onChange: (e)=>{
137
- props.onChange({
138
- ...props.value,
139
- matchers: e
140
- });
141
- }
176
+ onChange: handleMatchEditorChange
142
177
  })
143
178
  ]
144
179
  });
145
180
  }
146
181
  function PrometheusPromQLVariableEditor(props) {
147
- const { onChange, value } = props;
148
- const { datasource } = value;
182
+ const { onChange, value, value: { datasource }, queryHandlerSettings } = props;
149
183
  const selectedDatasource = datasource ?? _model.DEFAULT_PROM;
150
184
  const { data: client } = (0, _pluginsystem.useDatasourceClient)(selectedDatasource);
151
185
  const promURL = client?.options.datasourceUrl;
152
- const handleDatasourceChange = (next)=>{
186
+ const [labelValue, setLableValue] = (0, _react.useState)(props.value.labelName);
187
+ const handleDatasourceChange = (0, _react.useCallback)((next)=>{
153
188
  if ((0, _model.isPrometheusDatasourceSelector)(next)) {
154
189
  onChange((0, _immer.produce)(value, (draft)=>{
155
190
  // If they're using the default, just omit the datasource prop (i.e. set to undefined)
156
191
  draft.datasource = (0, _model.isDefaultPromSelector)(next) ? undefined : next;
157
192
  }));
193
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
194
+ ...value,
195
+ datasource: next
196
+ });
158
197
  return;
159
198
  }
160
199
  throw new Error('Got unexpected non-Prometheus datasource selector');
161
- };
200
+ }, [
201
+ value,
202
+ onChange,
203
+ queryHandlerSettings
204
+ ]);
205
+ const handleOnBlurPromQlChange = (0, _react.useCallback)((e)=>{
206
+ onChange({
207
+ ...value,
208
+ expr: e.target.textContent ?? ''
209
+ });
210
+ }, [
211
+ onChange,
212
+ value
213
+ ]);
214
+ const trackPromQlChanges = (0, _react.useCallback)((e)=>{
215
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
216
+ ...value,
217
+ expr: e.target.textContent ?? ''
218
+ });
219
+ }, [
220
+ queryHandlerSettings,
221
+ value
222
+ ]);
223
+ const handleLabelNameChange = (0, _react.useCallback)((e)=>{
224
+ setLableValue(e.target.value);
225
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings?.setWatchOtherSpecs({
226
+ ...value,
227
+ labelName: e.target.value
228
+ });
229
+ }, [
230
+ queryHandlerSettings,
231
+ value
232
+ ]);
162
233
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
163
234
  spacing: 2,
164
235
  children: [
@@ -181,27 +252,18 @@ function PrometheusPromQLVariableEditor(props) {
181
252
  },
182
253
  value: value.expr,
183
254
  datasource: selectedDatasource,
184
- onBlur: (event)=>{
185
- props.onChange({
186
- ...props.value,
187
- expr: event.target.textContent ?? ''
188
- });
189
- },
255
+ onBlur: queryHandlerSettings?.runWithOnBlur ? handleOnBlurPromQlChange : trackPromQlChanges,
190
256
  readOnly: props.isReadonly,
191
257
  width: "100%"
192
258
  }),
193
259
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
194
260
  label: "Label Name",
195
- value: props.value.labelName,
261
+ required: true,
262
+ value: labelValue,
196
263
  InputProps: {
197
264
  readOnly: props.isReadonly
198
265
  },
199
- onChange: (e)=>{
200
- props.onChange({
201
- ...props.value,
202
- labelName: e.target.value
203
- });
204
- }
266
+ onChange: handleLabelNameChange
205
267
  })
206
268
  ]
207
269
  });
@@ -1 +1 @@
1
- {"version":3,"file":"PromQLEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PromQLEditor.tsx"],"names":[],"mappings":"AAaA,OAAmB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAmB,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAI1F,OAAO,EAAE,YAAY,EAAqB,MAAM,OAAO,CAAC;AAIxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AASxD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,qBAAqB,CAAC;IACtC,UAAU,EAAE,4BAA4B,CAAC;CAC1C,GAAG,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC;AAEvD,wBAAgB,YAAY,CAAC,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,EAAE,iBAAiB,GAAG,YAAY,CAoHrG"}
1
+ {"version":3,"file":"PromQLEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PromQLEditor.tsx"],"names":[],"mappings":"AAaA,OAAmB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AACzE,OAAO,EAAmB,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAI1F,OAAO,EAAE,YAAY,EAAqB,MAAM,OAAO,CAAC;AAIxD,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AASxD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,qBAAqB,CAAC;IACtC,UAAU,EAAE,4BAA4B,CAAC;CAC1C,GAAG,IAAI,CAAC,oBAAoB,EAAE,OAAO,GAAG,YAAY,CAAC,CAAC;AAEvD,wBAAgB,YAAY,CAAC,EAAE,cAAc,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,EAAE,iBAAiB,GAAG,YAAY,CAsHrG"}
@@ -64,6 +64,7 @@ export function PromQLEditor({ completeConfig, datasource, ...rest }) {
64
64
  children: "PromQL Expression"
65
65
  }),
66
66
  /*#__PURE__*/ _jsx(CodeMirror, {
67
+ "data-testid": "promql_expression_editor",
67
68
  ...rest,
68
69
  style: {
69
70
  border: `1px solid ${theme.palette.divider}`
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/PromQLEditor.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport CodeMirror, { ReactCodeMirrorProps } from '@uiw/react-codemirror';\nimport { PromQLExtension, CompleteConfiguration } from '@prometheus-io/codemirror-promql';\nimport { EditorView } from '@codemirror/view';\nimport { useTheme, CircularProgress, InputLabel, Stack, IconButton, Tooltip } from '@mui/material';\nimport FileTreeIcon from 'mdi-material-ui/FileTree';\nimport { ReactElement, useMemo, useState } from 'react';\nimport { ErrorAlert } from '@perses-dev/components';\nimport CloseIcon from 'mdi-material-ui/Close';\nimport { useReplaceVariablesInString } from '@perses-dev/plugin-system';\nimport { PrometheusDatasourceSelector } from '../model';\nimport { replacePromBuiltinVariables } from '../plugins/prometheus-time-series-query/replace-prom-builtin-variables';\nimport { useParseQuery } from './query';\nimport TreeNode from './TreeNode';\n\nconst treeViewStr = 'Tree View';\nconst treeViewOpenStr = 'Open ' + treeViewStr;\nconst treeViewCloseStr = 'Close ' + treeViewStr;\n\nexport type PromQLEditorProps = {\n completeConfig: CompleteConfiguration;\n datasource: PrometheusDatasourceSelector;\n} & Omit<ReactCodeMirrorProps, 'theme' | 'extensions'>;\n\nexport function PromQLEditor({ completeConfig, datasource, ...rest }: PromQLEditorProps): ReactElement {\n const theme = useTheme();\n const isDarkMode = theme.palette.mode === 'dark';\n const [isTreeViewVisible, setTreeViewVisible] = useState(false);\n\n const promQLExtension = useMemo(() => {\n return new PromQLExtension().activateLinter(false).setComplete(completeConfig).asExtension();\n }, [completeConfig]);\n\n let queryExpr = useReplaceVariablesInString(rest.value);\n if (queryExpr) {\n // TODO placeholder values for steps to be replaced with actual values\n // Looks like providing proper values involves some refactoring: currently we'd need to rely on the timeseries query context,\n // but these step values are actually computed independently / before the queries are getting fired, so it's useless to fire\n // queries here, so maybe we should extract this part to independant hook(s), to be reused here?\n queryExpr = replacePromBuiltinVariables(queryExpr, 12345, 12345);\n }\n\n const { data: parseQueryResponse, isLoading, error } = useParseQuery(queryExpr ?? '', datasource, isTreeViewVisible);\n\n const handleShowTreeView = (): void => {\n setTreeViewVisible(!isTreeViewVisible);\n };\n\n return (\n <Stack position=\"relative\">\n <InputLabel // reproduce the same kind of input label that regular MUI TextFields have\n shrink\n sx={{\n position: 'absolute',\n top: '-12px',\n left: '10px',\n padding: '0 4px',\n color: theme.palette.text.primary,\n zIndex: 1,\n }}\n >\n PromQL Expression\n </InputLabel>\n <CodeMirror\n {...rest}\n style={{ border: `1px solid ${theme.palette.divider}` }}\n theme={isDarkMode ? 'dark' : 'light'}\n basicSetup={{\n highlightActiveLine: false,\n highlightActiveLineGutter: false,\n foldGutter: false,\n }}\n extensions={[\n EditorView.lineWrapping,\n promQLExtension,\n EditorView.theme({\n '.cm-content': {\n paddingTop: '8px',\n paddingBottom: '8px',\n paddingRight: '40px', // offset for the tree view button\n },\n }),\n ]}\n placeholder=\"Example: sum(rate(http_requests_total[5m]))\"\n />\n {queryExpr && (\n <>\n <Tooltip title={isTreeViewVisible ? treeViewCloseStr : treeViewOpenStr}>\n <IconButton\n aria-label={isTreeViewVisible ? treeViewCloseStr : treeViewOpenStr}\n onClick={handleShowTreeView}\n sx={{ position: 'absolute', right: '5px', top: '5px' }}\n size=\"small\"\n key=\"tree-view-button\"\n >\n <FileTreeIcon sx={{ fontSize: '18px' }} />\n </IconButton>\n </Tooltip>\n {isTreeViewVisible && (\n <div style={{ border: `1px solid ${theme.palette.divider}`, position: 'relative' }}>\n <Tooltip title={treeViewCloseStr}>\n <IconButton\n aria-label={treeViewCloseStr}\n onClick={() => setTreeViewVisible(false)}\n sx={{ position: 'absolute', top: '5px', right: '5px' }}\n size=\"small\"\n key=\"tree-view-close-button\"\n >\n <CloseIcon sx={{ fontSize: '18px' }} />\n </IconButton>\n </Tooltip>\n {error ? (\n // Here the user is able to hide the error alert\n <ErrorAlert\n error={{\n name: `${treeViewStr} not available`,\n message: error.message,\n }}\n />\n ) : (\n <div\n style={{\n padding: `${theme.spacing(1.5)} ${theme.spacing(1.5)} 0 ${theme.spacing(1.5)}`, // let paddingBottom at 0 because nodes have margin-bottom\n overflowX: 'auto',\n backgroundColor: theme.palette.background.default,\n }}\n >\n {isLoading ? (\n <CircularProgress />\n ) : parseQueryResponse?.data ? (\n <TreeNode node={parseQueryResponse.data} reverse={false} childIdx={0} datasource={datasource} />\n ) : null}\n </div>\n )}\n </div>\n )}\n </>\n )}\n </Stack>\n );\n}\n"],"names":["CodeMirror","PromQLExtension","EditorView","useTheme","CircularProgress","InputLabel","Stack","IconButton","Tooltip","FileTreeIcon","useMemo","useState","ErrorAlert","CloseIcon","useReplaceVariablesInString","replacePromBuiltinVariables","useParseQuery","TreeNode","treeViewStr","treeViewOpenStr","treeViewCloseStr","PromQLEditor","completeConfig","datasource","rest","theme","isDarkMode","palette","mode","isTreeViewVisible","setTreeViewVisible","promQLExtension","activateLinter","setComplete","asExtension","queryExpr","value","data","parseQueryResponse","isLoading","error","handleShowTreeView","position","shrink","sx","top","left","padding","color","text","primary","zIndex","style","border","divider","basicSetup","highlightActiveLine","highlightActiveLineGutter","foldGutter","extensions","lineWrapping","paddingTop","paddingBottom","paddingRight","placeholder","title","aria-label","onClick","right","size","fontSize","div","name","message","spacing","overflowX","backgroundColor","background","default","node","reverse","childIdx"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,OAAOA,gBAA0C,wBAAwB;AACzE,SAASC,eAAe,QAA+B,mCAAmC;AAC1F,SAASC,UAAU,QAAQ,mBAAmB;AAC9C,SAASC,QAAQ,EAAEC,gBAAgB,EAAEC,UAAU,EAAEC,KAAK,EAAEC,UAAU,EAAEC,OAAO,QAAQ,gBAAgB;AACnG,OAAOC,kBAAkB,2BAA2B;AACpD,SAAuBC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACxD,SAASC,UAAU,QAAQ,yBAAyB;AACpD,OAAOC,eAAe,wBAAwB;AAC9C,SAASC,2BAA2B,QAAQ,4BAA4B;AAExE,SAASC,2BAA2B,QAAQ,yEAAyE;AACrH,SAASC,aAAa,QAAQ,UAAU;AACxC,OAAOC,cAAc,aAAa;AAElC,MAAMC,cAAc;AACpB,MAAMC,kBAAkB,UAAUD;AAClC,MAAME,mBAAmB,WAAWF;AAOpC,OAAO,SAASG,aAAa,EAAEC,cAAc,EAAEC,UAAU,EAAE,GAAGC,MAAyB;IACrF,MAAMC,QAAQtB;IACd,MAAMuB,aAAaD,MAAME,OAAO,CAACC,IAAI,KAAK;IAC1C,MAAM,CAACC,mBAAmBC,mBAAmB,GAAGnB,SAAS;IAEzD,MA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U;gCAAY0B,OAAO;gCAAOvB,KAAK;4BAAM;4BACrDwB,MAAK;sCAGL,cAAA,KAAC5D;gCAAamC,IAAI;oCAAE0B,UAAU;gCAAO;;2BAFjC;;oBAKPzC,mCACC,MAAC0C;wBAAInB,OAAO;4BAAEC,QAAQ,CAAC,UAAU,EAAE5B,MAAME,OAAO,CAAC2B,OAAO,EAAE;4BAAEZ,UAAU;wBAAW;;0CAC/E,KAAClC;gCAAQyD,OAAO7C;0CACd,cAAA,KAACb;oCACC2D,cAAY9C;oCACZ+C,SAAS,IAAMrC,mBAAmB;oCAClCc,IAAI;wCAAEF,UAAU;wCAAYG,KAAK;wCAAOuB,OAAO;oCAAM;oCACrDC,MAAK;8CAGL,cAAA,KAACxD;wCAAU+B,IAAI;4CAAE0B,UAAU;wCAAO;;mCAF9B;;4BAKP9B,QACC,gDAAgD;0CAChD,KAAC5B;gCACC4B,OAAO;oCACLgC,MAAM,GAAGtD,YAAY,cAAc,CAAC;oCACpCuD,SAASjC,MAAMiC,OAAO;gCACxB;+CAGF,KAACF;gCACCnB,OAAO;oCACLL,SAAS,GAAGtB,MAAMiD,OAAO,CAAC,KAAK,CAAC,EAAEjD,MAAMiD,OAAO,CAAC,KAAK,GAAG,EAAEjD,MAAMiD,OAAO,CAAC,MAAM;oCAC9EC,WAAW;oCACXC,iBAAiBnD,MAAME,OAAO,CAACkD,UAAU,CAACC,OAAO;gCACnD;0CAECvC,0BACC,KAACnC,wBACCkC,oBAAoBD,qBACtB,KAACpB;oCAAS8D,MAAMzC,mBAAmBD,IAAI;oCAAE2C,SAAS;oCAAOC,UAAU;oCAAG1D,YAAYA;qCAChF;;;;;;;;AAStB"}
1
+ {"version":3,"sources":["../../../src/components/PromQLEditor.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport CodeMirror, { ReactCodeMirrorProps } from '@uiw/react-codemirror';\nimport { PromQLExtension, CompleteConfiguration } from '@prometheus-io/codemirror-promql';\nimport { EditorView } from '@codemirror/view';\nimport { useTheme, CircularProgress, InputLabel, Stack, IconButton, Tooltip } from '@mui/material';\nimport FileTreeIcon from 'mdi-material-ui/FileTree';\nimport { ReactElement, useMemo, useState } from 'react';\nimport { ErrorAlert } from '@perses-dev/components';\nimport CloseIcon from 'mdi-material-ui/Close';\nimport { useReplaceVariablesInString } from '@perses-dev/plugin-system';\nimport { PrometheusDatasourceSelector } from '../model';\nimport { replacePromBuiltinVariables } from '../plugins/prometheus-time-series-query/replace-prom-builtin-variables';\nimport { useParseQuery } from './query';\nimport TreeNode from './TreeNode';\n\nconst treeViewStr = 'Tree View';\nconst treeViewOpenStr = 'Open ' + treeViewStr;\nconst treeViewCloseStr = 'Close ' + treeViewStr;\n\nexport type PromQLEditorProps = {\n completeConfig: CompleteConfiguration;\n datasource: PrometheusDatasourceSelector;\n} & Omit<ReactCodeMirrorProps, 'theme' | 'extensions'>;\n\nexport function PromQLEditor({ completeConfig, datasource, ...rest }: PromQLEditorProps): ReactElement {\n const theme = useTheme();\n const isDarkMode = theme.palette.mode === 'dark';\n const [isTreeViewVisible, setTreeViewVisible] = useState(false);\n\n const promQLExtension = useMemo(() => {\n return new PromQLExtension().activateLinter(false).setComplete(completeConfig).asExtension();\n }, [completeConfig]);\n\n let queryExpr = useReplaceVariablesInString(rest.value);\n if (queryExpr) {\n // TODO placeholder values for steps to be replaced with actual values\n // Looks like providing proper values involves some refactoring: currently we'd need to rely on the timeseries query context,\n // but these step values are actually computed independently / before the queries are getting fired, so it's useless to fire\n // queries here, so maybe we should extract this part to independant hook(s), to be reused here?\n queryExpr = replacePromBuiltinVariables(queryExpr, 12345, 12345);\n }\n\n const { data: parseQueryResponse, isLoading, error } = useParseQuery(queryExpr ?? '', datasource, isTreeViewVisible);\n\n const handleShowTreeView = (): void => {\n setTreeViewVisible(!isTreeViewVisible);\n };\n\n return (\n <Stack position=\"relative\">\n <InputLabel // reproduce the same kind of input label that regular MUI TextFields have\n shrink\n sx={{\n position: 'absolute',\n top: '-12px',\n left: '10px',\n padding: '0 4px',\n color: theme.palette.text.primary,\n zIndex: 1,\n }}\n >\n PromQL Expression\n </InputLabel>\n {/* TODO: We need to wait for this to be merged, then we need to add proper e2e for some scenarios */}\n <CodeMirror\n data-testid=\"promql_expression_editor\"\n {...rest}\n style={{ border: `1px solid ${theme.palette.divider}` }}\n theme={isDarkMode ? 'dark' : 'light'}\n basicSetup={{\n highlightActiveLine: false,\n highlightActiveLineGutter: false,\n foldGutter: false,\n }}\n extensions={[\n EditorView.lineWrapping,\n promQLExtension,\n EditorView.theme({\n '.cm-content': {\n paddingTop: '8px',\n paddingBottom: '8px',\n paddingRight: '40px', // offset for the tree view button\n },\n }),\n ]}\n placeholder=\"Example: sum(rate(http_requests_total[5m]))\"\n />\n {queryExpr && (\n <>\n <Tooltip title={isTreeViewVisible ? treeViewCloseStr : treeViewOpenStr}>\n <IconButton\n aria-label={isTreeViewVisible ? treeViewCloseStr : treeViewOpenStr}\n onClick={handleShowTreeView}\n sx={{ position: 'absolute', right: '5px', top: '5px' }}\n size=\"small\"\n key=\"tree-view-button\"\n >\n <FileTreeIcon sx={{ fontSize: '18px' }} />\n </IconButton>\n </Tooltip>\n {isTreeViewVisible && (\n <div style={{ border: `1px solid ${theme.palette.divider}`, position: 'relative' }}>\n <Tooltip title={treeViewCloseStr}>\n <IconButton\n aria-label={treeViewCloseStr}\n onClick={() => setTreeViewVisible(false)}\n sx={{ position: 'absolute', top: '5px', right: '5px' }}\n size=\"small\"\n key=\"tree-view-close-button\"\n >\n <CloseIcon sx={{ fontSize: '18px' }} />\n </IconButton>\n </Tooltip>\n {error ? (\n // Here the user is able to hide the error alert\n <ErrorAlert\n error={{\n name: `${treeViewStr} not available`,\n message: error.message,\n }}\n />\n ) : (\n <div\n style={{\n padding: `${theme.spacing(1.5)} ${theme.spacing(1.5)} 0 ${theme.spacing(1.5)}`, // let paddingBottom at 0 because nodes have margin-bottom\n overflowX: 'auto',\n backgroundColor: theme.palette.background.default,\n }}\n >\n {isLoading ? (\n <CircularProgress />\n ) : parseQueryResponse?.data ? (\n <TreeNode node={parseQueryResponse.data} reverse={false} childIdx={0} datasource={datasource} />\n ) : null}\n </div>\n )}\n </div>\n )}\n </>\n )}\n </Stack>\n );\n}\n"],"names":["CodeMirror","PromQLExtension","EditorView","useTheme","CircularProgress","InputLabel","Stack","IconButton","Tooltip","FileTreeIcon","useMemo","useState","ErrorAlert","CloseIcon","useReplaceVariablesInString","replacePromBuiltinVariables","useParseQuery","TreeNode","treeViewStr","treeViewOpenStr","treeViewCloseStr","PromQLEditor","completeConfig","datasource","rest","theme","isDarkMode","palette","mode","isTreeViewVisible","setTreeViewVisible","promQLExtension","activateLinter","setComplete","asExtension","queryExpr","value","data","parseQueryResponse","isLoading","error","handleShowTreeView","position","shrink","sx","top","left","padding","color","text","primary","zIndex","data-testid","style","border","divider","basicSetup","highlightActiveLine","highlightActiveLineGutter","foldGutter","extensions","lineWrapping","paddingTop","paddingBottom","paddingRight","placeholder","title","aria-label","onClick","right","size","fontSize","div","name","message","spacing","overflowX","backgroundColor","background","default","node","reverse","childIdx"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,OAAOA,gBAA0C,wBAAwB;AACzE,SAASC,eAAe,QAA+B,mCAAmC;AAC1F,SAASC,UAAU,QAAQ,mBAAmB;AAC9C,SAASC,QAAQ,EAAEC,gBAAg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c,CAAC;oCACpCwD,SAASlC,MAAMkC,OAAO;gCACxB;+CAGF,KAACF;gCACCnB,OAAO;oCACLN,SAAS,GAAGtB,MAAMkD,OAAO,CAAC,KAAK,CAAC,EAAElD,MAAMkD,OAAO,CAAC,KAAK,GAAG,EAAElD,MAAMkD,OAAO,CAAC,MAAM;oCAC9EC,WAAW;oCACXC,iBAAiBpD,MAAME,OAAO,CAACmD,UAAU,CAACC,OAAO;gCACnD;0CAECxC,0BACC,KAACnC,wBACCkC,oBAAoBD,qBACtB,KAACpB;oCAAS+D,MAAM1C,mBAAmBD,IAAI;oCAAE4C,SAAS;oCAAOC,UAAU;oCAAG3D,YAAYA;qCAChF;;;;;;;;AAStB"}
@@ -374,13 +374,21 @@ function QueryStatus({ mergedChildState, isFetching, error, resultStats, respons
374
374
  sx: {
375
375
  color: (theme)=>theme.palette.mode === 'dark' // TODO we shouldnt have to do that I guess..
376
376
  ? theme.palette.warning.dark : theme.palette.warning.main,
377
- fontFamily: 'monospace'
377
+ fontFamily: 'monospace',
378
+ whiteSpace: 'nowrap',
379
+ overflow: 'hidden',
380
+ textOverflow: 'ellipsis',
381
+ flexGrow: 1
378
382
  },
379
383
  children: escapeString(value)
380
384
  }),
381
385
  /*#__PURE__*/ _jsxs(Typography, {
382
386
  variant: "body2",
383
387
  component: "span",
388
+ sx: {
389
+ whiteSpace: 'nowrap',
390
+ flexShrink: 0
391
+ },
384
392
  children: [
385
393
  "(",
386
394
  count,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/TreeNode.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Forked from https://github.com/prometheus/prometheus/blob/65f610353919b1c7b42d3776c3a95b68046a6bba/web/ui/mantine-ui/src/pages/query/TreeNode.tsx\n\nimport { Box, CircularProgress, List, ListItem, Stack, Tooltip, Typography, useTheme } from '@mui/material';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport { ReactElement, useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';\nimport AlertCircle from 'mdi-material-ui/AlertCircle';\nimport { StatusError } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector } from '../model';\nimport ASTNode, { nodeType } from './promql/ast';\nimport { escapeString, getNodeChildren } from './promql/utils';\nimport { formatNode } from './promql/format';\nimport serializeNode from './promql/serialize';\nimport { functionSignatures } from './promql/functionSignatures';\nimport { useInstantQuery } from './query';\n\n// The indentation factor for each level of the tree.\nconst nodeIndent = 5;\nconst connectorWidth = nodeIndent * 5;\n\n// max number of label names and values to show in the individual query status\nconst maxLabelNames = 10;\nconst maxLabelValues = 10;\n\ntype NodeState = 'waiting' | 'running' | 'error' | 'success';\n\n// mergeChildStates basically returns the \"worst\" state found among the children.\nconst mergeChildStates = (states: NodeState[]): NodeState => {\n if (states.includes('error')) {\n return 'error';\n }\n if (states.includes('waiting')) {\n return 'waiting';\n }\n if (states.includes('running')) {\n return 'running';\n }\n\n return 'success';\n};\n\ninterface TreeNodeProps {\n // The AST node to render.\n node: ASTNode;\n // The parent element of this node.\n parentEl?: HTMLDivElement | null;\n // Used to compute the position of the connector line between this node and its parent.\n reverse: boolean;\n // Datasource used for the node's individual query.\n datasource: PrometheusDatasourceSelector;\n // The index of this node in its parent's children.\n // Used to render the node's individual query.\n childIdx: number;\n // Function to report the node state to the parent.\n // Used to render the node's individual query.\n reportNodeState?: (childIdx: number, state: NodeState) => void;\n}\n\nexport default function TreeNode({\n node,\n parentEl,\n reverse,\n datasource,\n childIdx,\n reportNodeState,\n}: TreeNodeProps): ReactElement {\n const theme = useTheme();\n const children = getNodeChildren(node);\n\n // A normal ref won't work properly here because the ref's `current` property\n // going from `null` to defined won't trigger a re-render of the child\n // component, since it's not a React state update. So we manually have to\n // create a state update using a callback ref. See also\n // https://tkdodo.eu/blog/avoiding-use-effect-with-callback-refs\n const [nodeEl, setNodeEl] = useState<HTMLDivElement | null>(null);\n const nodeRef = useCallback((node: HTMLDivElement) => setNodeEl(node), []);\n\n const [resultStats, setResultStats] = useState<{\n numSeries: number;\n labelExamples: Record<string, Array<{ value: string; count: number }>>;\n sortedLabelCards: Array<[string, number]>;\n }>({\n numSeries: 0,\n labelExamples: {},\n sortedLabelCards: [],\n });\n\n const [connectorStyle, setConnectorStyle] = useState({\n borderColor: theme.palette.grey['500'],\n borderLeftStyle: 'solid',\n borderLeftWidth: 2,\n width: connectorWidth,\n left: -connectorWidth,\n });\n\n const [childStates, setChildStates] = useState<NodeState[]>(children.map(() => 'waiting'));\n const mergedChildState = useMemo(() => mergeChildStates(childStates), [childStates]);\n\n // Optimize range vector selector fetches to give us the info we're looking for\n // more cheaply. E.g. 'foo[7w]' can be expensive to fully fetch, but wrapping it\n // in 'last_over_time(foo[7w])' is cheaper and also gives us all the info we\n // need (number of series and labels).\n let queryNode = node;\n if (queryNode.type === nodeType.matrixSelector) {\n queryNode = {\n type: nodeType.call,\n func: functionSignatures.last_over_time!,\n args: [node],\n };\n }\n\n // Individual query for the current node\n const {\n data: instantQueryResponse,\n isFetching,\n error,\n } = useInstantQuery(serializeNode(queryNode) ?? '', datasource, mergedChildState === 'success');\n\n // report the node state to the parent\n useEffect(() => {\n if (reportNodeState) {\n if (mergedChildState === 'error' || error) {\n reportNodeState(childIdx, 'error');\n } else if (isFetching) {\n reportNodeState(childIdx, 'running');\n }\n }\n }, [mergedChildState, error, isFetching, reportNodeState, childIdx]);\n\n // This function is passed down to the child nodes so they can report their state.\n const childReportNodeState = useCallback(\n (childIdx: number, state: NodeState) => {\n setChildStates((prev) => {\n const newStates = [...prev];\n newStates[childIdx] = state;\n return newStates;\n });\n },\n [setChildStates]\n );\n\n // Update the size and position of tree connector lines based on the node's and its parent's position.\n useLayoutEffect(() => {\n if (parentEl === undefined) {\n // We're the root node.\n return;\n }\n\n if (parentEl === null || nodeEl === null) {\n // Either of the two connected nodes hasn't been rendered yet.\n return;\n }\n\n const parentRect = parentEl.getBoundingClientRect();\n const nodeRect = nodeEl.getBoundingClientRect();\n if (reverse) {\n setConnectorStyle((prevStyle) => ({\n ...prevStyle,\n top: 'calc(50% - 1px)',\n bottom: nodeRect.bottom - parentRect.top,\n borderTopLeftRadius: 10,\n borderTopStyle: 'solid',\n borderBottomLeftRadius: undefined,\n }));\n } else {\n setConnectorStyle((prevStyle) => ({\n ...prevStyle,\n top: parentRect.bottom - nodeRect.top,\n bottom: 'calc(50% - 1px)',\n borderBottomLeftRadius: 10,\n borderBottomStyle: 'solid',\n borderTopLeftRadius: undefined,\n }));\n }\n }, [parentEl, nodeEl, reverse, nodeRef, setConnectorStyle]);\n\n // Update the node info state based on the query result.\n useEffect(() => {\n if (instantQueryResponse?.status !== 'success') {\n return;\n }\n\n if (reportNodeState) {\n reportNodeState(childIdx, 'success');\n }\n\n let resultSeries = 0;\n // labelValuesByName records the number of times each label value appears for each label name.\n const labelValuesByName: Record<string, Record<string, number>> = {};\n const { resultType, result } = instantQueryResponse.data;\n\n if (resultType === 'scalar' || resultType === 'string') {\n resultSeries = 1;\n } else if (result && result.length > 0) {\n resultSeries = result.length;\n result.forEach((s) => {\n Object.entries(s.metric).forEach(([ln, lv]) => {\n // TODO: If we ever want to include __name__ here again, we cannot use the\n // last_over_time(foo[7d]) optimization since that removes the metric name.\n if (ln !== '__name__') {\n labelValuesByName[ln] = labelValuesByName[ln] ?? {};\n labelValuesByName[ln]![lv] = (labelValuesByName[ln]![lv] ?? 0) + 1;\n }\n });\n });\n }\n\n // labelCardinalities records the number of unique label values for each label name.\n const labelCardinalities: Record<string, number> = {};\n // labelExamples records the most common label values for each label name.\n const labelExamples: Record<string, Array<{ value: string; count: number }>> = {};\n Object.entries(labelValuesByName).forEach(([ln, lvs]) => {\n labelCardinalities[ln] = Object.keys(lvs).length;\n // Sort label values by their number of occurrences within this label name.\n labelExamples[ln] = Object.entries(lvs)\n .sort(([, aCnt], [, bCnt]) => bCnt - aCnt)\n .slice(0, maxLabelValues)\n .map(([lv, cnt]) => ({ value: lv, count: cnt }));\n });\n\n setResultStats({\n numSeries: resultSeries,\n sortedLabelCards: Object.entries(labelCardinalities).sort((a, b) => b[1] - a[1]),\n labelExamples,\n });\n }, [instantQueryResponse, reportNodeState, childIdx]);\n\n const innerNode = (\n <Stack direction=\"row\" gap={2}>\n <Box\n ref={nodeRef}\n sx={{\n position: 'relative',\n display: 'inline-block',\n padding: 1,\n marginBottom: 1.5,\n borderRadius: 2,\n backgroundColor: theme.palette.background.code,\n }}\n >\n {parentEl !== undefined && (\n // Connector line between this node and its parent.\n <Box\n sx={{\n position: 'absolute',\n display: 'inline-block',\n ...connectorStyle,\n }}\n />\n )}\n {/* The node (visible box) itself. */}\n {formatNode(node, false, 1)}\n </Box>\n {/* The node's individual query: */}\n <QueryStatus\n mergedChildState={mergedChildState}\n isFetching={isFetching}\n error={error}\n resultStats={resultStats}\n responseTime={instantQueryResponse?.responseTime}\n />\n </Stack>\n );\n\n if (node.type === nodeType.binaryExpr) {\n return (\n <div>\n <Box ml={nodeIndent}>\n <TreeNode\n node={children[0]!}\n parentEl={nodeEl}\n reverse={true}\n datasource={datasource}\n childIdx={0}\n reportNodeState={childReportNodeState}\n />\n </Box>\n {innerNode}\n <Box ml={nodeIndent}>\n <TreeNode\n node={children[1]!}\n parentEl={nodeEl}\n reverse={false}\n datasource={datasource}\n childIdx={1}\n reportNodeState={childReportNodeState}\n />\n </Box>\n </div>\n );\n }\n\n return (\n <div>\n {innerNode}\n {children.map((child, idx) => (\n <Box ml={nodeIndent} key={idx}>\n <TreeNode\n node={child}\n parentEl={nodeEl}\n reverse={false}\n datasource={datasource}\n childIdx={idx}\n reportNodeState={childReportNodeState}\n />\n </Box>\n ))}\n </div>\n );\n}\n\ninterface QueryStatusProps {\n mergedChildState: NodeState;\n isFetching: boolean;\n error: StatusError | null;\n resultStats: {\n numSeries: number;\n labelExamples: Record<string, Array<{ value: string; count: number }>>;\n sortedLabelCards: Array<[string, number]>;\n };\n responseTime?: number;\n}\n\nfunction QueryStatus({\n mergedChildState,\n isFetching,\n error,\n resultStats,\n responseTime,\n}: QueryStatusProps): ReactElement {\n if (mergedChildState === 'waiting') {\n return <ProgressState text=\"Waiting for child query\" />;\n }\n\n if (mergedChildState === 'running') {\n return <ProgressState text=\"Running\" />;\n }\n\n if (mergedChildState === 'error') {\n return (\n <Stack>\n <AlertCircle />\n Blocked on child query error\n </Stack>\n );\n }\n\n if (isFetching) {\n return <ProgressState text=\"Loading\" />;\n }\n\n if (error) {\n return (\n <Box\n display=\"flex\"\n alignItems=\"center\"\n gap={1}\n sx={{ color: (theme) => theme.palette.error.main }}\n marginBottom={1.5}\n >\n <AlertCircle />\n <Typography variant=\"body2\">\n <strong>Error executing query:</strong> {error.message}\n </Typography>\n </Box>\n );\n }\n\n return (\n <Stack direction=\"row\" gap={1} alignItems=\"center\" marginBottom={1.5}>\n <Typography variant=\"body2\" component=\"span\" sx={{ color: (theme) => theme.palette.grey[500] }}>\n {resultStats.numSeries} result{resultStats.numSeries !== 1 && 's'}\n &nbsp;&nbsp;–&nbsp;&nbsp;\n {responseTime ? `${Math.round(responseTime)}ms` : '? ms'}\n {resultStats.sortedLabelCards.length > 0 && <>&nbsp;&nbsp;–</>}\n </Typography>\n {resultStats.sortedLabelCards.slice(0, maxLabelNames).map(([ln, cnt]) => (\n <Tooltip\n key={ln}\n title={\n <Box>\n <List dense>\n {resultStats.labelExamples[ln]?.map(({ value, count }) => (\n <ListItem\n key={value}\n sx={{\n display: 'flex',\n gap: 1,\n py: 0,\n px: 0.5,\n }}\n >\n <CircleIcon sx={{ fontSize: 8 }} />\n <Typography\n variant=\"body2\"\n component=\"span\"\n sx={{\n color: (theme) =>\n theme.palette.mode === 'dark' // TODO we shouldnt have to do that I guess..\n ? theme.palette.warning.dark\n : theme.palette.warning.main,\n fontFamily: 'monospace',\n }}\n >\n {escapeString(value)}\n </Typography>\n <Typography variant=\"body2\" component=\"span\">\n ({count}x)\n </Typography>\n </ListItem>\n ))}\n {cnt > maxLabelValues && (\n <ListItem\n sx={{\n display: 'flex',\n gap: 1,\n py: 0,\n px: 0.5,\n }}\n >\n <CircleIcon sx={{ fontSize: 8 }} />\n <Typography variant=\"body2\">. . .</Typography>\n </ListItem>\n )}\n </List>\n </Box>\n }\n arrow\n >\n <span style={{ cursor: 'pointer', whiteSpace: 'nowrap' }}>\n <Typography\n variant=\"body2\"\n component=\"span\"\n sx={{ fontFamily: 'monospace', color: (theme) => theme.palette.success.main }}\n >\n {ln}\n </Typography>\n <Typography variant=\"body2\" component=\"span\" sx={{ color: (theme) => theme.palette.grey[500] }}>\n : {cnt}\n </Typography>\n </span>\n </Tooltip>\n ))}\n {resultStats.sortedLabelCards.length > maxLabelNames ? (\n <Typography variant=\"body2\">...{resultStats.sortedLabelCards.length - maxLabelNames} more...</Typography>\n ) : null}\n </Stack>\n );\n}\n\nfunction ProgressState({ text }: { text: string }): ReactElement {\n return (\n <Box display=\"flex\" alignItems=\"center\" gap={1} marginBottom={1.5}>\n <CircularProgress size={16} color=\"secondary\" />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {text}...\n </Typography>\n </Box>\n );\n}\n"],"names":["Box","CircularProgress","List","ListItem","Stack","Tooltip","Typography","useTheme","CircleIcon","useCallback","useEffect","useLayoutEffect","useMemo","useState","AlertCircle","nodeType","escapeString","getNodeChildren","formatNode","serializeNode","functionSignatures","useInstantQuery","nodeIndent","connectorWidth","maxLabelNames","maxLabelValues","mergeChildStates","states","includes","TreeNode","node","parentEl","reverse","datasource","childIdx","reportNodeState","theme","children","nodeEl","setNodeEl","nodeRef","resultStats","setResultStats","numSeries","labelExamples","sortedLabelCards","connectorStyle","setConnectorStyle","borderColor","palette","grey","borderLeftStyle","borderLeftWidth","width","left","childStates","setChildStates","map","mergedChildState","queryNode","type","matrixSelector","call","func","last_over_time","args","data","instantQueryResponse","isFetching","error","childReportNodeState","state","prev","newStates","undefined","parentRect","getBoundingClientRect","nodeRect","prevStyle","top","bottom","borderTopLeftRadius","borderTopStyle","borderBottomLeftRadius","borderBottomStyle","status","resultSeries","labelValuesByName","resultType","result","length","forEach","s","Object","entries","metric","ln","lv","labelCardinalities","lvs","keys","sort","aCnt","bCnt","slice","cnt","value","count","a","b","innerNode","direction","gap","ref","sx","position","display","padding","marginBottom","borderRadius","backgroundColor","background","code","QueryStatus","responseTime","binaryExpr","div","ml","child","idx","ProgressState","text","alignItems","color","main","variant","strong","message","component","Math","round","title","dense","py","px","fontSize","mode","warning","dark","fontFamily","arrow","span","style","cursor","whiteSpace","success","size"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,oJAAoJ;;AAEpJ,SAASA,GAAG,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,gBAAgB;AAC5G,OAAOC,gBAAgB,yBAAyB;AAChD,SAAuBC,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACjG,OAAOC,iBAAiB,8BAA8B;AAGtD,SAAkBC,QAAQ,QAAQ,eAAe;AACjD,SAASC,YAAY,EAAEC,eAAe,QAAQ,iBAAiB;AAC/D,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,OAAOC,mBAAmB,qBAAqB;AAC/C,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,eAAe,QAAQ,UAAU;AAE1C,qDAAqD;AACrD,MAAMC,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AAY;wBAAS;;0CACrD,KAACpJ;gCACCiI,SAAQ;gCACRG,WAAU;gCACVxB,IAAI;oCAAEmC,YAAY;oCAAahB,OAAO,CAACjG,QAAUA,MAAMa,OAAO,CAAC0G,OAAO,CAACrB,IAAI;gCAAC;0CAE3EtC;;0CAEH,MAAC1F;gCAAWiI,SAAQ;gCAAQG,WAAU;gCAAOxB,IAAI;oCAAEmB,OAAO,CAACjG,QAAUA,MAAMa,OAAO,CAACC,IAAI,CAAC,IAAI;gCAAC;;oCAAG;oCAC3FuD;;;;;mBA5DFT;YAiERvD,YAAYI,gBAAgB,CAAC6C,MAAM,GAAGlE,8BACrC,MAAClB;gBAAWiI,SAAQ;;oBAAQ;oBAAI9F,YAAYI,gBAAgB,CAAC6C,MAAM,GAAGlE;oBAAc;;iBAClF;;;AAGV;AAEA,SAAS0G,cAAc,EAAEC,IAAI,EAAoB;IAC/C,qBACE,MAACnI;QAAIoH,SAAQ;QAAOgB,YAAW;QAASpB,KAAK;QAAGM,cAAc;;0BAC5D,KAACrH;gBAAiB2J,MAAM;gBAAIvB,OAAM;;0BAClC,MAAC/H;gBAAWiI,SAAQ;gBAAQF,OAAM;;oBAC/BF;oBAAK;;;;;AAId"}
1
+ {"version":3,"sources":["../../../src/components/TreeNode.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n// Forked from https://github.com/prometheus/prometheus/blob/65f610353919b1c7b42d3776c3a95b68046a6bba/web/ui/mantine-ui/src/pages/query/TreeNode.tsx\n\nimport { Box, CircularProgress, List, ListItem, Stack, Tooltip, Typography, useTheme } from '@mui/material';\nimport CircleIcon from 'mdi-material-ui/Circle';\nimport { ReactElement, useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';\nimport AlertCircle from 'mdi-material-ui/AlertCircle';\nimport { StatusError } from '@perses-dev/core';\nimport { PrometheusDatasourceSelector } from '../model';\nimport ASTNode, { nodeType } from './promql/ast';\nimport { escapeString, getNodeChildren } from './promql/utils';\nimport { formatNode } from './promql/format';\nimport serializeNode from './promql/serialize';\nimport { functionSignatures } from './promql/functionSignatures';\nimport { useInstantQuery } from './query';\n\n// The indentation factor for each level of the tree.\nconst nodeIndent = 5;\nconst connectorWidth = nodeIndent * 5;\n\n// max number of label names and values to show in the individual query status\nconst maxLabelNames = 10;\nconst maxLabelValues = 10;\n\ntype NodeState = 'waiting' | 'running' | 'error' | 'success';\n\n// mergeChildStates basically returns the \"worst\" state found among the children.\nconst mergeChildStates = (states: NodeState[]): NodeState => {\n if (states.includes('error')) {\n return 'error';\n }\n if (states.includes('waiting')) {\n return 'waiting';\n }\n if (states.includes('running')) {\n return 'running';\n }\n\n return 'success';\n};\n\ninterface TreeNodeProps {\n // The AST node to render.\n node: ASTNode;\n // The parent element of this node.\n parentEl?: HTMLDivElement | null;\n // Used to compute the position of the connector line between this node and its parent.\n reverse: boolean;\n // Datasource used for the node's individual query.\n datasource: PrometheusDatasourceSelector;\n // The index of this node in its parent's children.\n // Used to render the node's individual query.\n childIdx: number;\n // Function to report the node state to the parent.\n // Used to render the node's individual query.\n reportNodeState?: (childIdx: number, state: NodeState) => void;\n}\n\nexport default function TreeNode({\n node,\n parentEl,\n reverse,\n datasource,\n childIdx,\n reportNodeState,\n}: TreeNodeProps): ReactElement {\n const theme = useTheme();\n const children = getNodeChildren(node);\n\n // A normal ref won't work properly here because the ref's `current` property\n // going from `null` to defined won't trigger a re-render of the child\n // component, since it's not a React state update. So we manually have to\n // create a state update using a callback ref. See also\n // https://tkdodo.eu/blog/avoiding-use-effect-with-callback-refs\n const [nodeEl, setNodeEl] = useState<HTMLDivElement | null>(null);\n const nodeRef = useCallback((node: HTMLDivElement) => setNodeEl(node), []);\n\n const [resultStats, setResultStats] = useState<{\n numSeries: number;\n labelExamples: Record<string, Array<{ value: string; count: number }>>;\n sortedLabelCards: Array<[string, number]>;\n }>({\n numSeries: 0,\n labelExamples: {},\n sortedLabelCards: [],\n });\n\n const [connectorStyle, setConnectorStyle] = useState({\n borderColor: theme.palette.grey['500'],\n borderLeftStyle: 'solid',\n borderLeftWidth: 2,\n width: connectorWidth,\n left: -connectorWidth,\n });\n\n const [childStates, setChildStates] = useState<NodeState[]>(children.map(() => 'waiting'));\n const mergedChildState = useMemo(() => mergeChildStates(childStates), [childStates]);\n\n // Optimize range vector selector fetches to give us the info we're looking for\n // more cheaply. E.g. 'foo[7w]' can be expensive to fully fetch, but wrapping it\n // in 'last_over_time(foo[7w])' is cheaper and also gives us all the info we\n // need (number of series and labels).\n let queryNode = node;\n if (queryNode.type === nodeType.matrixSelector) {\n queryNode = {\n type: nodeType.call,\n func: functionSignatures.last_over_time!,\n args: [node],\n };\n }\n\n // Individual query for the current node\n const {\n data: instantQueryResponse,\n isFetching,\n error,\n } = useInstantQuery(serializeNode(queryNode) ?? '', datasource, mergedChildState === 'success');\n\n // report the node state to the parent\n useEffect(() => {\n if (reportNodeState) {\n if (mergedChildState === 'error' || error) {\n reportNodeState(childIdx, 'error');\n } else if (isFetching) {\n reportNodeState(childIdx, 'running');\n }\n }\n }, [mergedChildState, error, isFetching, reportNodeState, childIdx]);\n\n // This function is passed down to the child nodes so they can report their state.\n const childReportNodeState = useCallback(\n (childIdx: number, state: NodeState) => {\n setChildStates((prev) => {\n const newStates = [...prev];\n newStates[childIdx] = state;\n return newStates;\n });\n },\n [setChildStates]\n );\n\n // Update the size and position of tree connector lines based on the node's and its parent's position.\n useLayoutEffect(() => {\n if (parentEl === undefined) {\n // We're the root node.\n return;\n }\n\n if (parentEl === null || nodeEl === null) {\n // Either of the two connected nodes hasn't been rendered yet.\n return;\n }\n\n const parentRect = parentEl.getBoundingClientRect();\n const nodeRect = nodeEl.getBoundingClientRect();\n if (reverse) {\n setConnectorStyle((prevStyle) => ({\n ...prevStyle,\n top: 'calc(50% - 1px)',\n bottom: nodeRect.bottom - parentRect.top,\n borderTopLeftRadius: 10,\n borderTopStyle: 'solid',\n borderBottomLeftRadius: undefined,\n }));\n } else {\n setConnectorStyle((prevStyle) => ({\n ...prevStyle,\n top: parentRect.bottom - nodeRect.top,\n bottom: 'calc(50% - 1px)',\n borderBottomLeftRadius: 10,\n borderBottomStyle: 'solid',\n borderTopLeftRadius: undefined,\n }));\n }\n }, [parentEl, nodeEl, reverse, nodeRef, setConnectorStyle]);\n\n // Update the node info state based on the query result.\n useEffect(() => {\n if (instantQueryResponse?.status !== 'success') {\n return;\n }\n\n if (reportNodeState) {\n reportNodeState(childIdx, 'success');\n }\n\n let resultSeries = 0;\n // labelValuesByName records the number of times each label value appears for each label name.\n const labelValuesByName: Record<string, Record<string, number>> = {};\n const { resultType, result } = instantQueryResponse.data;\n\n if (resultType === 'scalar' || resultType === 'string') {\n resultSeries = 1;\n } else if (result && result.length > 0) {\n resultSeries = result.length;\n result.forEach((s) => {\n Object.entries(s.metric).forEach(([ln, lv]) => {\n // TODO: If we ever want to include __name__ here again, we cannot use the\n // last_over_time(foo[7d]) optimization since that removes the metric name.\n if (ln !== '__name__') {\n labelValuesByName[ln] = labelValuesByName[ln] ?? {};\n labelValuesByName[ln]![lv] = (labelValuesByName[ln]![lv] ?? 0) + 1;\n }\n });\n });\n }\n\n // labelCardinalities records the number of unique label values for each label name.\n const labelCardinalities: Record<string, number> = {};\n // labelExamples records the most common label values for each label name.\n const labelExamples: Record<string, Array<{ value: string; count: number }>> = {};\n Object.entries(labelValuesByName).forEach(([ln, lvs]) => {\n labelCardinalities[ln] = Object.keys(lvs).length;\n // Sort label values by their number of occurrences within this label name.\n labelExamples[ln] = Object.entries(lvs)\n .sort(([, aCnt], [, bCnt]) => bCnt - aCnt)\n .slice(0, maxLabelValues)\n .map(([lv, cnt]) => ({ value: lv, count: cnt }));\n });\n\n setResultStats({\n numSeries: resultSeries,\n sortedLabelCards: Object.entries(labelCardinalities).sort((a, b) => b[1] - a[1]),\n labelExamples,\n });\n }, [instantQueryResponse, reportNodeState, childIdx]);\n\n const innerNode = (\n <Stack direction=\"row\" gap={2}>\n <Box\n ref={nodeRef}\n sx={{\n position: 'relative',\n display: 'inline-block',\n padding: 1,\n marginBottom: 1.5,\n borderRadius: 2,\n backgroundColor: theme.palette.background.code,\n }}\n >\n {parentEl !== undefined && (\n // Connector line between this node and its parent.\n <Box\n sx={{\n position: 'absolute',\n display: 'inline-block',\n ...connectorStyle,\n }}\n />\n )}\n {/* The node (visible box) itself. */}\n {formatNode(node, false, 1)}\n </Box>\n {/* The node's individual query: */}\n <QueryStatus\n mergedChildState={mergedChildState}\n isFetching={isFetching}\n error={error}\n resultStats={resultStats}\n responseTime={instantQueryResponse?.responseTime}\n />\n </Stack>\n );\n\n if (node.type === nodeType.binaryExpr) {\n return (\n <div>\n <Box ml={nodeIndent}>\n <TreeNode\n node={children[0]!}\n parentEl={nodeEl}\n reverse={true}\n datasource={datasource}\n childIdx={0}\n reportNodeState={childReportNodeState}\n />\n </Box>\n {innerNode}\n <Box ml={nodeIndent}>\n <TreeNode\n node={children[1]!}\n parentEl={nodeEl}\n reverse={false}\n datasource={datasource}\n childIdx={1}\n reportNodeState={childReportNodeState}\n />\n </Box>\n </div>\n );\n }\n\n return (\n <div>\n {innerNode}\n {children.map((child, idx) => (\n <Box ml={nodeIndent} key={idx}>\n <TreeNode\n node={child}\n parentEl={nodeEl}\n reverse={false}\n datasource={datasource}\n childIdx={idx}\n reportNodeState={childReportNodeState}\n />\n </Box>\n ))}\n </div>\n );\n}\n\ninterface QueryStatusProps {\n mergedChildState: NodeState;\n isFetching: boolean;\n error: StatusError | null;\n resultStats: {\n numSeries: number;\n labelExamples: Record<string, Array<{ value: string; count: number }>>;\n sortedLabelCards: Array<[string, number]>;\n };\n responseTime?: number;\n}\n\nfunction QueryStatus({\n mergedChildState,\n isFetching,\n error,\n resultStats,\n responseTime,\n}: QueryStatusProps): ReactElement {\n if (mergedChildState === 'waiting') {\n return <ProgressState text=\"Waiting for child query\" />;\n }\n\n if (mergedChildState === 'running') {\n return <ProgressState text=\"Running\" />;\n }\n\n if (mergedChildState === 'error') {\n return (\n <Stack>\n <AlertCircle />\n Blocked on child query error\n </Stack>\n );\n }\n\n if (isFetching) {\n return <ProgressState text=\"Loading\" />;\n }\n\n if (error) {\n return (\n <Box\n display=\"flex\"\n alignItems=\"center\"\n gap={1}\n sx={{ color: (theme) => theme.palette.error.main }}\n marginBottom={1.5}\n >\n <AlertCircle />\n <Typography variant=\"body2\">\n <strong>Error executing query:</strong> {error.message}\n </Typography>\n </Box>\n );\n }\n\n return (\n <Stack direction=\"row\" gap={1} alignItems=\"center\" marginBottom={1.5}>\n <Typography variant=\"body2\" component=\"span\" sx={{ color: (theme) => theme.palette.grey[500] }}>\n {resultStats.numSeries} result{resultStats.numSeries !== 1 && 's'}\n &nbsp;&nbsp;–&nbsp;&nbsp;\n {responseTime ? `${Math.round(responseTime)}ms` : '? ms'}\n {resultStats.sortedLabelCards.length > 0 && <>&nbsp;&nbsp;–</>}\n </Typography>\n {resultStats.sortedLabelCards.slice(0, maxLabelNames).map(([ln, cnt]) => (\n <Tooltip\n key={ln}\n title={\n <Box>\n <List dense>\n {resultStats.labelExamples[ln]?.map(({ value, count }) => (\n <ListItem\n key={value}\n sx={{\n display: 'flex',\n gap: 1,\n py: 0,\n px: 0.5,\n }}\n >\n <CircleIcon sx={{ fontSize: 8 }} />\n <Typography\n variant=\"body2\"\n component=\"span\"\n sx={{\n color: (theme) =>\n theme.palette.mode === 'dark' // TODO we shouldnt have to do that I guess..\n ? theme.palette.warning.dark\n : theme.palette.warning.main,\n fontFamily: 'monospace',\n whiteSpace: 'nowrap',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n flexGrow: 1,\n }}\n >\n {escapeString(value)}\n </Typography>\n <Typography\n variant=\"body2\"\n component=\"span\"\n sx={{\n whiteSpace: 'nowrap',\n flexShrink: 0,\n }}\n >\n ({count}x)\n </Typography>\n </ListItem>\n ))}\n {cnt > maxLabelValues && (\n <ListItem\n sx={{\n display: 'flex',\n gap: 1,\n py: 0,\n px: 0.5,\n }}\n >\n <CircleIcon sx={{ fontSize: 8 }} />\n <Typography variant=\"body2\">. . .</Typography>\n </ListItem>\n )}\n </List>\n </Box>\n }\n arrow\n >\n <span style={{ cursor: 'pointer', whiteSpace: 'nowrap' }}>\n <Typography\n variant=\"body2\"\n component=\"span\"\n sx={{ fontFamily: 'monospace', color: (theme) => theme.palette.success.main }}\n >\n {ln}\n </Typography>\n <Typography variant=\"body2\" component=\"span\" sx={{ color: (theme) => theme.palette.grey[500] }}>\n : {cnt}\n </Typography>\n </span>\n </Tooltip>\n ))}\n {resultStats.sortedLabelCards.length > maxLabelNames ? (\n <Typography variant=\"body2\">...{resultStats.sortedLabelCards.length - maxLabelNames} more...</Typography>\n ) : null}\n </Stack>\n );\n}\n\nfunction ProgressState({ text }: { text: string }): ReactElement {\n return (\n <Box display=\"flex\" alignItems=\"center\" gap={1} marginBottom={1.5}>\n <CircularProgress size={16} color=\"secondary\" />\n <Typography variant=\"body2\" color=\"text.secondary\">\n {text}...\n </Typography>\n </Box>\n );\n}\n"],"names":["Box","CircularProgress","List","ListItem","Stack","Tooltip","Typography","useTheme","CircleIcon","useCallback","useEffect","useLayoutEffect","useMemo","useState","AlertCircle","nodeType","escapeString","getNodeChildren","formatNode","serializeNode","functionSignatures","useInstantQuery","nodeIndent","connectorWidth","maxLabelNames","maxLabelValues","mergeChildStates","states","includes","TreeNode","node","parentEl","reverse","datasource","childIdx","reportNodeState","theme","children","nodeEl","setNodeEl","nodeRef","resultStats","setResultStats","numSeries","labelExamples","sortedLabelCards","connectorStyle","setConnectorStyle","borderColor","palette","grey","borderLeftStyle","borderLeftWidth","width","left","childStates","setChildStates","map","mergedChildState","queryNode","type","matrixSelector","call","func","last_over_time","args","data","instantQueryResponse","isFetching","error","childReportNodeState","state","prev","newStates","undefined","parentRect","getBoundingClientRect","nodeRect","prevStyle","top","bottom","borderTopLeftRadius","borderTopStyle","borderBottomLeftRadius","borderBottomStyle","status","resultSeries","labelValuesByName","resultType","result","length","forEach","s","Object","entries","metric","ln","lv","labelCardinalities","lvs","keys","sort","aCnt","bCnt","slice","cnt","value","count","a","b","innerNode","direction","gap","ref","sx","position","display","padding","marginBottom","borderRadius","backgroundColor","background","code","QueryStatus","responseTime","binaryExpr","div","ml","child","idx","ProgressState","text","alignItems","color","main","variant","strong","message","component","Math","round","title","dense","py","px","fontSize","mode","warning","dark","fontFamily","whiteSpace","overflow","textOverflow","flexGrow","flexShrink","arrow","span","style","cursor","success","size"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,oJAAoJ;;AAEpJ,SAASA,GAAG,EAAEC,gBAAgB,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,gBAAgB;AAC5G,OAAOC,gBAAgB,yBAAyB;AAChD,SAAuBC,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACjG,OAAOC,iBAAiB,8BAA8B;AAGtD,SAAkBC,QAAQ,QAAQ,eAAe;AACjD,SAASC,YAAY,EAAEC,eAAe,QAAQ,iBAAiB;AAC/D,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,OAAOC,mBAAmB,qBAAqB;AAC/C,SAASC,kBAAkB,QAAQ,8BAA8B;AACjE,SAASC,eAAe,QAAQ,UAAU;AAE1C,qDAAqD;AACrD,MAAMC,aAAa;AACnB,MAAMC,i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;;oBAMtCoB,KAAK;8BAEL,cAAA,MAACC;wBAAKC,OAAO;4BAAEC,QAAQ;4BAAWR,YAAY;wBAAS;;0CACrD,KAAChJ;gCACCiI,SAAQ;gCACRG,WAAU;gCACVxB,IAAI;oCAAEmC,YAAY;oCAAahB,OAAO,CAACjG,QAAUA,MAAMa,OAAO,CAAC8G,OAAO,CAACzB,IAAI;gCAAC;0CAE3EtC;;0CAEH,MAAC1F;gCAAWiI,SAAQ;gCAAQG,WAAU;gCAAOxB,IAAI;oCAAEmB,OAAO,CAACjG,QAAUA,MAAMa,OAAO,CAACC,IAAI,CAAC,IAAI;gCAAC;;oCAAG;oCAC3FuD;;;;;mBAvEFT;YA4ERvD,YAAYI,gBAAgB,CAAC6C,MAAM,GAAGlE,8BACrC,MAAClB;gBAAWiI,SAAQ;;oBAAQ;oBAAI9F,YAAYI,gBAAgB,CAAC6C,MAAM,GAAGlE;oBAAc;;iBAClF;;;AAGV;AAEA,SAAS0G,cAAc,EAAEC,IAAI,EAAoB;IAC/C,qBACE,MAACnI;QAAIoH,SAAQ;QAAOgB,YAAW;QAASpB,KAAK;QAAGM,cAAc;;0BAC5D,KAACrH;gBAAiB+J,MAAM;gBAAI3B,OAAM;;0BAClC,MAAC/H;gBAAWiI,SAAQ;gBAAQF,OAAM;;oBAC/BF;oBAAK;;;;;AAId"}
@@ -1 +1 @@
1
- {"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":"AAuBA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAYrC,OAAO,EACL,oCAAoC,EAIrC,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,GAAG,YAAY,CAgFzG"}
1
+ {"version":3,"file":"PrometheusTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"names":[],"mappings":"AAuBA,OAAO,EAAE,YAAY,EAAe,MAAM,OAAO,CAAC;AAYlD,OAAO,EACL,oCAAoC,EAIrC,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,wBAAgB,+BAA+B,CAAC,KAAK,EAAE,oCAAoC,GAAG,YAAY,CAuHzG"}
@@ -15,6 +15,7 @@ import { produce } from 'immer';
15
15
  import { DatasourceSelect, useDatasource, useDatasourceClient, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
16
16
  import { useId } from '@perses-dev/components';
17
17
  import { FormControl, Stack, TextField } from '@mui/material';
18
+ import { useCallback } from 'react';
18
19
  import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PROM_DATASOURCE_KIND } from '../../model';
19
20
  import { DEFAULT_SCRAPE_INTERVAL } from '../types';
20
21
  import { PromQLEditor } from '../../components';
@@ -22,8 +23,7 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
22
23
  /**
23
24
  * The options editor component for editing a PrometheusTimeSeriesQuery's spec.
24
25
  */ export function PrometheusTimeSeriesQueryEditor(props) {
25
- const { onChange, value } = props;
26
- const { datasource } = value;
26
+ const { onChange, value, value: { query, datasource }, queryHandlerSettings } = props;
27
27
  const datasourceSelectValue = datasource ?? DEFAULT_PROM;
28
28
  const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page
29
29
  const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, PROM_DATASOURCE_KIND);
@@ -36,15 +36,53 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
36
36
  const minStepPlaceholder = minStep ?? (datasourceResource && (datasourceResource?.plugin.spec).scrapeInterval) ?? DEFAULT_SCRAPE_INTERVAL;
37
37
  const handleDatasourceChange = (next)=>{
38
38
  if (isPrometheusDatasourceSelector(next)) {
39
- onChange(produce(value, (draft)=>{
39
+ /* Good to know: The usage of onchange here causes an immediate spec update which eventually updates the panel
40
+ This was probably intentional to allow for quick switching between datasources.
41
+ Could have been triggered only with Run Query button as well.
42
+ */ onChange(produce(value, (draft)=>{
40
43
  // If they're using the default, just omit the datasource prop (i.e. set to undefined)
41
44
  const nextDatasource = isDefaultPromSelector(next) ? undefined : next;
42
45
  draft.datasource = nextDatasource;
43
46
  }));
47
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
48
+ ...value,
49
+ datasource: next
50
+ });
44
51
  return;
45
52
  }
46
53
  throw new Error('Got unexpected non-Prometheus datasource selector');
47
54
  };
55
+ const handlePromQlEditorChanges = useCallback((e)=>{
56
+ handleQueryChange(e);
57
+ if (queryHandlerSettings?.watchQueryChanges) {
58
+ queryHandlerSettings?.watchQueryChanges(e);
59
+ }
60
+ }, [
61
+ queryHandlerSettings,
62
+ handleQueryChange
63
+ ]);
64
+ const handleLegendSpecChange = useCallback((e)=>{
65
+ handleFormatChange(e.target.value);
66
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
67
+ ...value,
68
+ seriesNameFormat: e.target.value
69
+ });
70
+ }, [
71
+ queryHandlerSettings,
72
+ handleFormatChange,
73
+ value
74
+ ]);
75
+ const handleMinStepSpecChange = useCallback((e)=>{
76
+ handleMinStepChange(e.target.value ? e.target.value : undefined);
77
+ if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
78
+ ...value,
79
+ minStep: e.target.value
80
+ });
81
+ }, [
82
+ queryHandlerSettings,
83
+ handleMinStepChange,
84
+ value
85
+ ]);
48
86
  return /*#__PURE__*/ _jsxs(Stack, {
49
87
  spacing: 2,
50
88
  children: [
@@ -66,10 +104,10 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
66
104
  url: promURL
67
105
  }
68
106
  },
69
- value: value.query,
107
+ value: query,
70
108
  datasource: selectedDatasource,
71
- onChange: handleQueryChange,
72
- onBlur: handleQueryBlur
109
+ onChange: handlePromQlEditorChanges,
110
+ onBlur: queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined
73
111
  }),
74
112
  /*#__PURE__*/ _jsxs(Stack, {
75
113
  direction: "row",
@@ -81,16 +119,16 @@ import { useQueryState, useFormatState, useMinStepState } from './query-editor-m
81
119
  placeholder: "Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...",
82
120
  helperText: "Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.",
83
121
  value: format ?? '',
84
- onChange: (e)=>handleFormatChange(e.target.value),
85
- onBlur: handleFormatBlur
122
+ onChange: handleLegendSpecChange,
123
+ onBlur: queryHandlerSettings?.runWithOnBlur ? handleFormatBlur : undefined
86
124
  }),
87
125
  /*#__PURE__*/ _jsx(TextField, {
88
126
  label: "Min Step",
89
127
  placeholder: minStepPlaceholder,
90
128
  helperText: "Lower bound for the step. If not provided, the scrape interval of the datasource is used.",
91
129
  value: minStep ?? '',
92
- onChange: (e)=>handleMinStepChange(e.target.value ? e.target.value : undefined),
93
- onBlur: handleMinStepBlur,
130
+ onChange: handleMinStepSpecChange,
131
+ onBlur: queryHandlerSettings?.runWithOnBlur ? handleMinStepBlur : undefined,
94
132
  sx: {
95
133
  width: '250px'
96
134
  }