@perses-dev/plugin-system 0.52.0 → 0.53.0-beta.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 (138) hide show
  1. package/dist/cjs/components/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +2 -2
  2. package/dist/cjs/components/DatasourceSelect/index.js +30 -0
  3. package/dist/cjs/components/MultiQueryEditor/MultiQueryEditor.js +11 -5
  4. package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +5 -3
  5. package/dist/cjs/components/PluginEditor/PluginEditor.js +3 -2
  6. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +4 -4
  7. package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +9 -3
  8. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +2 -2
  9. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +2 -2
  10. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +5 -1
  11. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +25 -34
  12. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +33 -19
  13. package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -0
  14. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +47 -0
  15. package/dist/cjs/components/Variables/variable-model.js +3 -3
  16. package/dist/cjs/components/index.js +0 -1
  17. package/dist/cjs/context/index.js +0 -1
  18. package/dist/cjs/remote/remotePluginLoader.js +19 -4
  19. package/dist/cjs/runtime/UsageMetricsProvider.js +4 -3
  20. package/dist/cjs/runtime/time-series-queries.js +4 -4
  21. package/dist/cjs/runtime/trace-queries.js +0 -11
  22. package/dist/cjs/test/mock-data.js +158 -0
  23. package/dist/cjs/utils/event.js +30 -0
  24. package/dist/cjs/utils/index.js +1 -0
  25. package/dist/components/{DatasourceSelect.d.ts → DatasourceSelect/DatasourceSelect.d.ts} +1 -1
  26. package/dist/components/DatasourceSelect/DatasourceSelect.d.ts.map +1 -0
  27. package/dist/components/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +2 -2
  28. package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -0
  29. package/dist/components/DatasourceSelect/index.d.ts +2 -0
  30. package/dist/components/DatasourceSelect/index.d.ts.map +1 -0
  31. package/dist/components/DatasourceSelect/index.js +15 -0
  32. package/dist/components/DatasourceSelect/index.js.map +1 -0
  33. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +1 -0
  34. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
  35. package/dist/components/MultiQueryEditor/MultiQueryEditor.js +11 -5
  36. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
  37. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +1 -0
  38. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -1
  39. package/dist/components/MultiQueryEditor/QueryEditorContainer.js +5 -3
  40. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
  41. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  42. package/dist/components/PluginEditor/PluginEditor.js +3 -2
  43. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  44. package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
  45. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  46. package/dist/components/PluginEditor/plugin-editor-api.js +1 -1
  47. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  48. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +1 -0
  49. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
  50. package/dist/components/PluginKindSelect/PluginKindSelect.js +9 -3
  51. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  52. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
  53. package/dist/components/PluginRegistry/PluginRegistry.js +1 -1
  54. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  55. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
  56. package/dist/components/PluginRegistry/plugin-indexes.js +1 -1
  57. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  58. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  59. package/dist/components/TimeRangeControls/TimeRangeControls.js +5 -1
  60. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  61. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  62. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +25 -34
  63. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  64. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +2 -0
  65. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
  66. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +33 -19
  67. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  68. package/dist/components/Variables/VariableEditorForm/index.d.ts +1 -0
  69. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -1
  70. package/dist/components/Variables/VariableEditorForm/index.js +1 -0
  71. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
  72. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +6 -0
  73. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  74. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +44 -0
  75. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  76. package/dist/components/Variables/variable-model.js +3 -3
  77. package/dist/components/Variables/variable-model.js.map +1 -1
  78. package/dist/components/index.d.ts +0 -1
  79. package/dist/components/index.d.ts.map +1 -1
  80. package/dist/components/index.js +0 -1
  81. package/dist/components/index.js.map +1 -1
  82. package/dist/context/index.d.ts +0 -1
  83. package/dist/context/index.d.ts.map +1 -1
  84. package/dist/context/index.js +0 -1
  85. package/dist/context/index.js.map +1 -1
  86. package/dist/model/time-series-queries.d.ts +1 -1
  87. package/dist/model/time-series-queries.d.ts.map +1 -1
  88. package/dist/model/time-series-queries.js.map +1 -1
  89. package/dist/model/variables.d.ts +1 -1
  90. package/dist/model/variables.d.ts.map +1 -1
  91. package/dist/model/variables.js.map +1 -1
  92. package/dist/remote/remotePluginLoader.d.ts +18 -1
  93. package/dist/remote/remotePluginLoader.d.ts.map +1 -1
  94. package/dist/remote/remotePluginLoader.js +22 -4
  95. package/dist/remote/remotePluginLoader.js.map +1 -1
  96. package/dist/runtime/UsageMetricsProvider.d.ts +3 -1
  97. package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
  98. package/dist/runtime/UsageMetricsProvider.js +4 -3
  99. package/dist/runtime/UsageMetricsProvider.js.map +1 -1
  100. package/dist/runtime/profile-queries.d.ts.map +1 -1
  101. package/dist/runtime/profile-queries.js.map +1 -1
  102. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  103. package/dist/runtime/time-series-queries.js +4 -4
  104. package/dist/runtime/time-series-queries.js.map +1 -1
  105. package/dist/runtime/trace-queries.d.ts +1 -5
  106. package/dist/runtime/trace-queries.d.ts.map +1 -1
  107. package/dist/runtime/trace-queries.js +0 -8
  108. package/dist/runtime/trace-queries.js.map +1 -1
  109. package/dist/test/mock-data.d.ts +134 -0
  110. package/dist/test/mock-data.d.ts.map +1 -1
  111. package/dist/test/mock-data.js +135 -0
  112. package/dist/test/mock-data.js.map +1 -1
  113. package/dist/utils/event.d.ts +8 -0
  114. package/dist/utils/event.d.ts.map +1 -0
  115. package/dist/utils/event.js +27 -0
  116. package/dist/utils/event.js.map +1 -0
  117. package/dist/utils/index.d.ts +1 -0
  118. package/dist/utils/index.d.ts.map +1 -1
  119. package/dist/utils/index.js +1 -0
  120. package/dist/utils/index.js.map +1 -1
  121. package/package.json +3 -3
  122. package/dist/cjs/components/ProjectSelect.js +0 -96
  123. package/dist/cjs/context/ProjectStoreProvider.js +0 -81
  124. package/dist/cjs/context/query-params.js +0 -49
  125. package/dist/components/DatasourceSelect.d.ts.map +0 -1
  126. package/dist/components/DatasourceSelect.js.map +0 -1
  127. package/dist/components/ProjectSelect.d.ts +0 -15
  128. package/dist/components/ProjectSelect.d.ts.map +0 -1
  129. package/dist/components/ProjectSelect.js +0 -91
  130. package/dist/components/ProjectSelect.js.map +0 -1
  131. package/dist/context/ProjectStoreProvider.d.ts +0 -16
  132. package/dist/context/ProjectStoreProvider.d.ts.map +0 -1
  133. package/dist/context/ProjectStoreProvider.js +0 -59
  134. package/dist/context/ProjectStoreProvider.js.map +0 -1
  135. package/dist/context/query-params.d.ts +0 -5
  136. package/dist/context/query-params.d.ts.map +0 -1
  137. package/dist/context/query-params.js +0 -41
  138. package/dist/context/query-params.js.map +0 -1
@@ -82,7 +82,7 @@ const useTimeSeriesQuery = (definition, options, queryOptions)=>{
82
82
  return (0, _reactquery.useQuery)({
83
83
  enabled: (queryOptions?.enabled ?? true) || queryEnabled,
84
84
  queryKey: queryKey,
85
- queryFn: ()=>{
85
+ queryFn: ({ signal })=>{
86
86
  // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking
87
87
  if (plugin === undefined) {
88
88
  throw new Error('Expected plugin to be loaded');
@@ -92,7 +92,7 @@ const useTimeSeriesQuery = (definition, options, queryOptions)=>{
92
92
  ...context,
93
93
  suggestedStepMs: options?.suggestedStepMs
94
94
  };
95
- return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
95
+ return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx, signal);
96
96
  }
97
97
  });
98
98
  };
@@ -118,14 +118,14 @@ function useTimeSeriesQueries(definitions, options, queryOptions) {
118
118
  ...queryOptions,
119
119
  enabled: (queryOptions?.enabled ?? true) && queryEnabled,
120
120
  queryKey: queryKey,
121
- queryFn: async ()=>{
121
+ queryFn: async ({ signal })=>{
122
122
  const ctx = {
123
123
  ...context,
124
124
  // Keep suggested step changes out of the query key, so we don´t have to run again query when it changes
125
125
  suggestedStepMs: options?.suggestedStepMs
126
126
  };
127
127
  const plugin = await getPlugin(TIME_SERIES_QUERY_KEY, definition.spec.plugin.kind);
128
- const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
128
+ const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx, signal);
129
129
  return data;
130
130
  }
131
131
  };
@@ -24,14 +24,10 @@ _export(exports, {
24
24
  TRACE_QUERY_KEY: function() {
25
25
  return TRACE_QUERY_KEY;
26
26
  },
27
- getUnixTimeRange: function() {
28
- return getUnixTimeRange;
29
- },
30
27
  useTraceQueries: function() {
31
28
  return useTraceQueries;
32
29
  }
33
30
  });
34
- const _datefns = require("date-fns");
35
31
  const _reactquery = require("@tanstack/react-query");
36
32
  const _datasources = require("./datasources");
37
33
  const _pluginregistry = require("./plugin-registry");
@@ -39,13 +35,6 @@ const _TimeRangeProvider = require("./TimeRangeProvider");
39
35
  const _variables = require("./variables");
40
36
  const _utils = require("./utils");
41
37
  const TRACE_QUERY_KEY = 'TraceQuery';
42
- function getUnixTimeRange(timeRange) {
43
- const { start, end } = timeRange;
44
- return {
45
- start: Math.ceil((0, _datefns.getUnixTime)(start)),
46
- end: Math.ceil((0, _datefns.getUnixTime)(end))
47
- };
48
- }
49
38
  function useTraceQueries(definitions) {
50
39
  const { getPlugin } = (0, _pluginregistry.usePluginRegistry)();
51
40
  const context = useTraceQueryContext();
@@ -21,17 +21,41 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
+ MOCK_EMPTY_PLUGIN_MODULE: function() {
25
+ return MOCK_EMPTY_PLUGIN_MODULE;
26
+ },
27
+ MOCK_INVALID_PLUGIN_MODULE: function() {
28
+ return MOCK_INVALID_PLUGIN_MODULE;
29
+ },
24
30
  MOCK_LOG_DATA: function() {
25
31
  return MOCK_LOG_DATA;
26
32
  },
33
+ MOCK_MIXED_VALIDITY_PLUGIN_MODULES: function() {
34
+ return MOCK_MIXED_VALIDITY_PLUGIN_MODULES;
35
+ },
36
+ MOCK_MULTI_PLUGIN_MODULE: function() {
37
+ return MOCK_MULTI_PLUGIN_MODULE;
38
+ },
39
+ MOCK_PARTIAL_FAILURE_MODULE: function() {
40
+ return MOCK_PARTIAL_FAILURE_MODULE;
41
+ },
27
42
  MOCK_PROFILE_DATA: function() {
28
43
  return MOCK_PROFILE_DATA;
29
44
  },
45
+ MOCK_REMOTE_PLUGIN_MODULE: function() {
46
+ return MOCK_REMOTE_PLUGIN_MODULE;
47
+ },
30
48
  MOCK_TIME_SERIES_DATA: function() {
31
49
  return MOCK_TIME_SERIES_DATA;
32
50
  },
33
51
  MOCK_TRACE_DATA: function() {
34
52
  return MOCK_TRACE_DATA;
53
+ },
54
+ MOCK_VALID_PLUGIN_METADATA: function() {
55
+ return MOCK_VALID_PLUGIN_METADATA;
56
+ },
57
+ MOCK_VALID_PLUGIN_MODULE_RESOURCE: function() {
58
+ return MOCK_VALID_PLUGIN_MODULE_RESOURCE;
35
59
  }
36
60
  });
37
61
  const MOCK_TIME_SERIES_DATA = {
@@ -146,3 +170,137 @@ const MOCK_PROFILE_DATA = {
146
170
  name: 'cpu'
147
171
  }
148
172
  };
173
+ const MOCK_VALID_PLUGIN_METADATA = {
174
+ kind: 'Panel',
175
+ spec: {
176
+ name: 'testPlugin',
177
+ display: {
178
+ name: 'Test Plugin',
179
+ description: 'A test plugin for unit testing'
180
+ }
181
+ }
182
+ };
183
+ const MOCK_VALID_PLUGIN_MODULE_RESOURCE = {
184
+ kind: 'PluginModule',
185
+ metadata: {
186
+ name: 'test-module',
187
+ version: '1.0.0'
188
+ },
189
+ spec: {
190
+ plugins: [
191
+ MOCK_VALID_PLUGIN_METADATA
192
+ ]
193
+ }
194
+ };
195
+ const MOCK_INVALID_PLUGIN_MODULE = {
196
+ // Missing required fields
197
+ metadata: {
198
+ name: 'invalid-module'
199
+ },
200
+ spec: {
201
+ plugins: [
202
+ {
203
+ // Missing required fields
204
+ kind: 'Panel'
205
+ }
206
+ ]
207
+ }
208
+ };
209
+ const MOCK_MIXED_VALIDITY_PLUGIN_MODULES = [
210
+ MOCK_VALID_PLUGIN_MODULE_RESOURCE,
211
+ MOCK_INVALID_PLUGIN_MODULE,
212
+ {
213
+ kind: 'PluginModule',
214
+ metadata: {
215
+ name: 'another-valid-module',
216
+ version: '2.0.0'
217
+ },
218
+ spec: {
219
+ plugins: [
220
+ {
221
+ kind: 'Variable',
222
+ spec: {
223
+ name: 'anotherPlugin',
224
+ display: {
225
+ name: 'Another Plugin'
226
+ }
227
+ }
228
+ }
229
+ ]
230
+ }
231
+ }
232
+ ];
233
+ const MOCK_REMOTE_PLUGIN_MODULE = {
234
+ testPlugin: {
235
+ component: ()=>null,
236
+ createDefaultOptions: ()=>({})
237
+ }
238
+ };
239
+ const MOCK_MULTI_PLUGIN_MODULE = {
240
+ kind: 'PluginModule',
241
+ metadata: {
242
+ name: 'multi-plugin-module',
243
+ version: '1.0.0'
244
+ },
245
+ spec: {
246
+ plugins: [
247
+ {
248
+ kind: 'Panel',
249
+ spec: {
250
+ name: 'plugin1',
251
+ display: {
252
+ name: 'Plugin 1'
253
+ }
254
+ }
255
+ },
256
+ {
257
+ kind: 'Variable',
258
+ spec: {
259
+ name: 'plugin2',
260
+ display: {
261
+ name: 'Plugin 2'
262
+ }
263
+ }
264
+ }
265
+ ]
266
+ }
267
+ };
268
+ const MOCK_PARTIAL_FAILURE_MODULE = {
269
+ kind: 'PluginModule',
270
+ metadata: {
271
+ name: 'partial-failure-module',
272
+ version: '1.0.0'
273
+ },
274
+ spec: {
275
+ plugins: [
276
+ {
277
+ kind: 'Panel',
278
+ spec: {
279
+ name: 'workingPlugin',
280
+ display: {
281
+ name: 'Working Plugin'
282
+ }
283
+ }
284
+ },
285
+ {
286
+ kind: 'Variable',
287
+ spec: {
288
+ name: 'failingPlugin',
289
+ display: {
290
+ name: 'Failing Plugin'
291
+ }
292
+ }
293
+ }
294
+ ]
295
+ }
296
+ };
297
+ const MOCK_EMPTY_PLUGIN_MODULE = {
298
+ kind: 'PluginModule',
299
+ metadata: {
300
+ name: 'empty-module',
301
+ version: '1.0.0'
302
+ },
303
+ spec: {
304
+ plugins: []
305
+ }
306
+ };
@@ -0,0 +1,30 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "useEvent", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return useEvent;
21
+ }
22
+ });
23
+ const _react = require("react");
24
+ function useEvent(handler) {
25
+ const handlerRef = (0, _react.useRef)(handler);
26
+ (0, _react.useLayoutEffect)(()=>{
27
+ handlerRef.current = handler;
28
+ });
29
+ return (0, _react.useCallback)((...args)=>handlerRef.current(...args), []);
30
+ }
@@ -15,6 +15,7 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _export_star(require("./action"), exports);
18
+ _export_star(require("./event"), exports);
18
19
  _export_star(require("./variables"), exports);
19
20
  function _export_star(from, to) {
20
21
  Object.keys(from).forEach(function(k) {
@@ -1,7 +1,7 @@
1
1
  import { OutlinedSelectProps, BaseSelectProps } from '@mui/material';
2
2
  import { DatasourceSelector, VariableName } from '@perses-dev/core';
3
3
  import { ReactElement } from 'react';
4
- import { DatasourceSelectItemGroup, DatasourceSelectItemSelector, VariableStateMap } from '../runtime';
4
+ import { DatasourceSelectItemGroup, DatasourceSelectItemSelector, VariableStateMap } from '../../runtime';
5
5
  type OmittedMuiProps = 'children' | 'value' | 'onChange';
6
6
  export type DatasourceSelectValue<T = DatasourceSelector> = T | VariableName;
7
7
  export interface DatasourceSelectProps extends Omit<OutlinedSelectProps & BaseSelectProps<string>, OmittedMuiProps> {
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatasourceSelect.d.ts","sourceRoot":"","sources":["../../../src/components/DatasourceSelect/DatasourceSelect.tsx"],"names":[],"mappings":"AAcA,OAAO,EAML,mBAAmB,EACnB,eAAe,EAGhB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAC9C,OAAO,EAEL,yBAAyB,EACzB,4BAA4B,EAG5B,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAOvB,KAAK,eAAe,GAAG,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAWzD,MAAM,MAAM,qBAAqB,CAAC,CAAC,GAAG,kBAAkB,IAAI,CAAC,GAAG,YAAY,CAAC;AAE7E,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CAAC,mBAAmB,GAAG,eAAe,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;IACjH,KAAK,EAAE,qBAAqB,CAAC;IAC7B,QAAQ,EAAE,CAAC,IAAI,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAChD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,GAAG,YAAY,CAkH3E;AAED,wBAAgB,cAAc,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,YAAY,CAahH;AAKD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,4BAA4B,GAAG,YAAY,GAAG,MAAM,CAKnG;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,MAAM,GAAG,qBAAqB,CAehF;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,qBAAqB,GAAG,SAAS,GAAG,KAAK,IAAI,YAAY,CAEpG;AAED,eAAO,MAAM,+BAA+B,UACnC,qBAAqB,GAAG,SAAS,aAC7B,gBAAgB,8BACC,yBAAyB,EAAE,GAAG,SAAS,KAClE,kBAAkB,GAAG,SA4BvB,CAAC;AAEF,eAAO,MAAM,kCAAkC,UACtC,qBAAqB,wBACN,MAAM,KAC3B,kBAQF,CAAC"}
@@ -15,8 +15,8 @@ import { createElement as _createElement } from "react";
15
15
  import OpenInNewIcon from 'mdi-material-ui/OpenInNew';
16
16
  import { Stack, ListItemText, Chip, IconButton, Box, Autocomplete, TextField } from '@mui/material';
17
17
  import { useMemo } from 'react';
18
- import { useListDatasourceSelectItems, useVariableValues } from '../runtime';
19
- import { parseVariables } from '../utils';
18
+ import { useListDatasourceSelectItems, useVariableValues } from '../../runtime';
19
+ import { parseVariables } from '../../utils';
20
20
  const DATASOURCE_VARIABLE_VALUE_PREFIX = '__DATASOURCE_VARIABLE_VALUE__';
21
21
  const VARIABLE_IDENTIFIER = '$';
22
22
  const emptyDatasourceOption = {
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/DatasourceSelect/DatasourceSelect.tsx"],"sourcesContent":["// Copyright 2023 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 OpenInNewIcon from 'mdi-material-ui/OpenInNew';\nimport {\n Stack,\n ListItemText,\n Chip,\n IconButton,\n Box,\n OutlinedSelectProps,\n BaseSelectProps,\n Autocomplete,\n TextField,\n} from '@mui/material';\nimport { DatasourceSelector, VariableName } from '@perses-dev/core';\nimport { ReactElement, useMemo } from 'react';\nimport {\n DatasourceSelectItem,\n DatasourceSelectItemGroup,\n DatasourceSelectItemSelector,\n useListDatasourceSelectItems,\n useVariableValues,\n VariableStateMap,\n} from '../../runtime';\nimport { parseVariables } from '../../utils';\n\nconst DATASOURCE_VARIABLE_VALUE_PREFIX = '__DATASOURCE_VARIABLE_VALUE__';\nconst VARIABLE_IDENTIFIER = '$';\n// Props on MUI Select that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\n\ntype DataSourceOption = {\n groupEditLink?: string;\n groupLabel?: string;\n value: string;\n} & Omit<DatasourceSelectItem, 'selector'> &\n Omit<DatasourceSelectItem['selector'], 'kind'>;\n\nconst emptyDatasourceOption: DataSourceOption = { name: '', value: '' };\n\nexport type DatasourceSelectValue<T = DatasourceSelector> = T | VariableName;\n\nexport interface DatasourceSelectProps extends Omit<OutlinedSelectProps & BaseSelectProps<string>, OmittedMuiProps> {\n value: DatasourceSelectValue;\n onChange: (next: DatasourceSelectValue) => void;\n datasourcePluginKind: string;\n project?: string;\n}\n\n/**\n * Displays a MUI input for selecting a Datasource of a particular kind. Note: The 'value' and `onChange` handler for\n * the input deal with a `DatasourceSelector`.\n */\nexport function DatasourceSelect(props: DatasourceSelectProps): ReactElement {\n const { datasourcePluginKind, value, project, readOnly, onChange, ...others } = props;\n const { data, isLoading } = useListDatasourceSelectItems(datasourcePluginKind, project);\n const variables = useVariableValues();\n\n const defaultValue = useMemo<VariableName | DatasourceSelectItemSelector>(() => {\n if (isVariableDatasource(value)) {\n return value;\n }\n\n const group = (data ?? [])\n .flatMap((itemGroup) => itemGroup.items)\n .find((item) => {\n return value.kind === item.selector.kind && value.name === item.selector.name && !item.overridden;\n })?.selector.group;\n return { ...value, group };\n }, [value, data]);\n\n const options = useMemo<DataSourceOption[]>(() => {\n const datasourceOptions = (data || []).flatMap<DataSourceOption>((itemGroup) =>\n itemGroup.items.map<DataSourceOption>((item) => ({\n groupLabel: itemGroup.group,\n groupEditLink: itemGroup.editLink,\n name: item.name,\n overriding: item.overriding,\n overridden: item.overridden,\n saved: item.saved ?? true,\n group: item.selector.group,\n value: selectorToOptionValue(item.selector),\n }))\n );\n\n const datasourceOptionsMap = new Map(datasourceOptions.map((option) => [option.name, option]));\n\n const variableOptions = Object.entries(variables).flatMap<DataSourceOption>(([name, variable]) => {\n if (Array.isArray(variable.value)) return [];\n\n const associatedDatasource = datasourceOptionsMap.get(variable.value ?? '');\n if (!associatedDatasource) return [];\n\n return {\n groupLabel: 'Variables',\n name: `${VARIABLE_IDENTIFIER}${name}`,\n saved: true,\n value: `${DATASOURCE_VARIABLE_VALUE_PREFIX}${VARIABLE_IDENTIFIER}${name}`,\n };\n });\n\n return [...datasourceOptions, ...variableOptions];\n }, [data, variables]);\n\n // While loading available values, just use an empty datasource option so MUI select doesn't warn about values out of range\n const optionValue = isLoading\n ? emptyDatasourceOption\n : options.find((option) => option.value === selectorToOptionValue(defaultValue));\n\n // When the user makes a selection, convert the string option value back to a DatasourceSelector\n const handleChange = (selectedOption: DataSourceOption | null): void => {\n if (selectedOption) {\n const next = optionValueToSelector(selectedOption?.value || '');\n onChange(next);\n } else {\n onChange({ kind: datasourcePluginKind });\n }\n };\n\n // We use a fake action event when we click on the action of the chip (hijack the \"delete\" feature).\n // This is because the href link action is on the `deleteIcon` property already, but the `onDelete` property\n // controls its visibility.\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const fakeActionEvent = (): void => {};\n\n return (\n <Autocomplete<DataSourceOption>\n readOnly={readOnly}\n options={options}\n renderInput={(params) => <TextField {...params} label={others.label} placeholder=\"\" />}\n groupBy={(option) => option.groupLabel || 'No group'}\n getOptionLabel={(option) => {\n return option.name;\n }}\n onChange={(_, v) => handleChange(v)}\n value={optionValue}\n renderOption={(props, option) => {\n return (\n <li {...props} key={option.value}>\n <Stack direction=\"row\" alignItems=\"center\" justifyContent=\"space-between\" width=\"100%\">\n <ListItemText>\n <DatasourceName name={option.name} overridden={option.overridden} overriding={option.overriding} />\n </ListItemText>\n {!option.saved && <ListItemText>Save the dashboard to enable this datasource</ListItemText>}\n <ListItemText style={{ textAlign: 'right' }}>\n {option.groupLabel && option.groupLabel.length > 0 && (\n <Chip\n disabled={false}\n label={option.groupLabel}\n size=\"small\"\n onDelete={option.groupEditLink ? fakeActionEvent : undefined}\n deleteIcon={\n option.groupEditLink ? (\n <IconButton href={option.groupEditLink} target=\"_blank\">\n <OpenInNewIcon fontSize=\"small\" />\n </IconButton>\n ) : undefined\n }\n />\n )}\n </ListItemText>\n </Stack>\n </li>\n );\n }}\n />\n );\n}\n\nexport function DatasourceName(props: { name: string; overridden?: boolean; overriding?: boolean }): ReactElement {\n const { name, overridden, overriding } = props;\n return (\n <>\n {`${name} `}\n {!overridden && overriding && (\n <Box display=\"inline\" fontWeight=\"normal\" color={(theme) => theme.palette.primary.main}>\n (overriding)\n </Box>\n )}\n {overridden && '(overridden)'}\n </>\n );\n}\n\n// Delimiter used to stringify/parse option values\nconst OPTION_VALUE_DELIMITER = '_____';\n\n/**\n * Given a DatasourceSelectItemSelector,\n * returns a string value like `{kind}_____{group}_____{name}` that can be used as a Select input value.\n * @param selector\n */\nexport function selectorToOptionValue(selector: DatasourceSelectItemSelector | VariableName): string {\n if (isVariableDatasource(selector)) {\n return `${DATASOURCE_VARIABLE_VALUE_PREFIX}${selector}`;\n }\n return [selector.kind, selector.group ?? '', selector.name ?? ''].join(OPTION_VALUE_DELIMITER);\n}\n\n/**\n * Given an option value name like `{kind}_____{group}_____{name}`,\n * returns a DatasourceSelector to be used by the query data model.\n * @param optionValue\n */\nexport function optionValueToSelector(optionValue: string): DatasourceSelectValue {\n if (optionValue.startsWith(DATASOURCE_VARIABLE_VALUE_PREFIX)) {\n return optionValue.split(DATASOURCE_VARIABLE_VALUE_PREFIX)[1]!;\n }\n\n const words = optionValue.split(OPTION_VALUE_DELIMITER);\n const kind = words[0];\n const name = words[2];\n if (kind === undefined || name === undefined) {\n throw new Error('Invalid optionValue string');\n }\n return {\n kind,\n name: name === '' ? undefined : name,\n };\n}\n\nexport function isVariableDatasource(value: DatasourceSelectValue | undefined): value is VariableName {\n return typeof value === 'string' && value.startsWith(VARIABLE_IDENTIFIER);\n}\n\nexport const datasourceSelectValueToSelector = (\n value: DatasourceSelectValue | undefined,\n variables: VariableStateMap,\n datasourceSelectItemGroups: DatasourceSelectItemGroup[] | undefined\n): DatasourceSelector | undefined => {\n if (!isVariableDatasource(value)) {\n return value;\n }\n\n const [variableName] = parseVariables(value);\n const variable = variables[variableName ?? ''];\n\n // If the variable is not defined or if its value is an array, we cannot determine a selector and return undefined\n if (!variable || Array.isArray(variable.value)) {\n return undefined;\n }\n\n const associatedDatasource = (datasourceSelectItemGroups || [])\n .flatMap((itemGroup) => itemGroup.items)\n .find((datasource) => datasource.name === variable.value);\n\n // If the variable value is not a datasource, we cannot determine a selector and return undefined\n if (associatedDatasource === undefined) {\n return undefined;\n }\n\n const datasourceSelector: DatasourceSelector = {\n kind: associatedDatasource.selector.kind,\n name: associatedDatasource.selector.name,\n };\n\n return datasourceSelector;\n};\n\nexport const useDatasourceSelectValueToSelector = (\n value: DatasourceSelectValue,\n datasourcePluginKind: string\n): DatasourceSelector => {\n const { data } = useListDatasourceSelectItems(datasourcePluginKind);\n const variables = useVariableValues();\n if (!isVariableDatasource(value)) {\n return value;\n }\n\n return datasourceSelectValueToSelector(value, variables, data) ?? { kind: datasourcePluginKind };\n};\n"],"names":["OpenInNewIcon","Stack","ListItemText","Chip","IconButton","Box","Autocomplete","TextField","useMemo","useListDatasourceSelectItems","useVariableValues","parseVariables","DATASOURCE_VARIABLE_VALUE_PREFIX","VARIABLE_IDENTIFIER","emptyDatasourceOption","name","value","DatasourceSelect","props","datasourcePluginKind","project","readOnly","onChange","others","data","isLoading","variables","defaultValue","isVariableDatasource","group","flatMap","itemGroup","items","find","item","kind","selector","overridden","options","datasourceOptions","map","groupLabel","groupEditLink","editLink","overriding","saved","selectorToOptionValue","datasourceOptionsMap","Map","option","variableOptions","Object","entries","variable","Array","isArray","associatedDatasource","get","optionValue","handleChange","selectedOption","next","optionValueToSelector","fakeActionEvent","renderInput","params","label","placeholder","groupBy","getOptionLabel","_","v","renderOption","li","key","direction","alignItems","justifyContent","width","DatasourceName","style","textAlign","length","disabled","size","onDelete","undefined","deleteIcon","href","target","fontSize","display","fontWeight","color","theme","palette","primary","main","OPTION_VALUE_DELIMITER","join","startsWith","split","words","Error","datasourceSelectValueToSelector","datasourceSelectItemGroups","variableName","datasource","datasourceSelector","useDatasourceSelectValueToSelector"],"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,mBAAmB,4BAA4B;AACtD,SACEC,KAAK,EACLC,YAAY,EACZC,IAAI,EACJC,UAAU,EACVC,GAAG,EAGHC,YAAY,EACZC,SAAS,QACJ,gBAAgB;AAEvB,SAAuBC,OAAO,QAAQ,QAAQ;AAC9C,SAIEC,4BAA4B,EAC5BC,iBAAiB,QAEZ,gBAAgB;AACvB,SAASC,cAAc,QAAQ,cAAc;AAE7C,MAAMC,mCAAmC;AACzC,MAAMC,sBAAsB;AAY5B,MAAMC,wBAA0C;IAAEC,MAAM;IAAIC,OAAO;AAAG;AAWtE;;;CAGC,GACD,OAAO,SAASC,iBAAiBC,KAA4B;IAC3D,MAAM,EAAEC,oBAAoB,EAAEH,KAAK,EAAEI,OAAO,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGC,QAAQ,GAAGL;IAChF,MAAM,EAAEM,IAAI,EAAEC,SAAS,EAAE,GAAGhB,6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qBAAqBZ,QAAQ;QAChC,OAAOA;IACT;IAEA,OAAOwF,gCAAgCxF,OAAOU,WAAWF,SAAS;QAAEW,MAAMhB;IAAqB;AACjG,EAAE"}
@@ -0,0 +1,2 @@
1
+ export * from './DatasourceSelect';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/DatasourceSelect/index.ts"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './DatasourceSelect';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/DatasourceSelect/index.ts"],"sourcesContent":["// Copyright 2023 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\nexport * from './DatasourceSelect';\n"],"names":[],"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,cAAc,qBAAqB"}
@@ -3,6 +3,7 @@ import { QueryDefinition, QueryPluginType } from '@perses-dev/core';
3
3
  import { PluginEditorRef } from '../PluginEditor';
4
4
  export interface MultiQueryEditorProps {
5
5
  queryTypes: QueryPluginType[];
6
+ filteredQueryPlugins?: string[];
6
7
  queries?: QueryDefinition[];
7
8
  onChange: (queries: QueryDefinition[]) => void;
8
9
  }
@@ -1 +1 @@
1
- {"version":3,"file":"MultiQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CAChD;AAmCD;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB,mHAmF3B,CAAC"}
1
+ {"version":3,"file":"MultiQueryEditor.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"names":[],"mappings":";AAiBA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEpE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGlD,MAAM,WAAW,qBAAqB;IACpC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,eAAe,EAAE,CAAC;IAC5B,QAAQ,EAAE,CAAC,OAAO,EAAE,eAAe,EAAE,KAAK,IAAI,CAAC;CAChD;AA4CD;;;;;;;GAOG;AAEH,eAAO,MAAM,gBAAgB,mHAoF3B,CAAC"}
@@ -17,7 +17,7 @@ import { Button, Stack } from '@mui/material';
17
17
  import AddIcon from 'mdi-material-ui/Plus';
18
18
  import { useListPluginMetadata, usePlugin, usePluginRegistry } from '../../runtime';
19
19
  import { QueryEditorContainer } from './QueryEditorContainer';
20
- function useDefaultQueryDefinition(queryTypes) {
20
+ function useDefaultQueryDefinition(queryTypes, filteredQueryPlugins) {
21
21
  // Build the default query plugin
22
22
  // This will be used only if the queries are empty, to open a starting query
23
23
  // Firs the default query type
@@ -26,7 +26,12 @@ function useDefaultQueryDefinition(queryTypes) {
26
26
  // Use as default the plugin kind explicitly set as default or the first in the list
27
27
  const { data: queryPlugins, isLoading } = useListPluginMetadata(queryTypes);
28
28
  const { defaultPluginKinds } = usePluginRegistry();
29
- const defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';
29
+ let defaultQueryKind = '';
30
+ if (filteredQueryPlugins?.length) {
31
+ defaultQueryKind = queryPlugins?.find((i)=>filteredQueryPlugins.includes(i.spec.name)).spec.name ?? '';
32
+ } else {
33
+ defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';
34
+ }
30
35
  const { data: defaultQueryPlugin } = usePlugin(defaultQueryType, defaultQueryKind, {
31
36
  useErrorBoundary: true,
32
37
  enabled: true
@@ -53,8 +58,8 @@ function useDefaultQueryDefinition(queryTypes) {
53
58
  * @param onChange The callback to call when the queries are modified
54
59
  * @constructor
55
60
  */ export const MultiQueryEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
56
- const { queryTypes, queries = [], onChange } = props;
57
- const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);
61
+ const { queryTypes, queries = [], filteredQueryPlugins, onChange } = props;
62
+ const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes, filteredQueryPlugins);
58
63
  // State for which queries are collapsed
59
64
  const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(()=>false));
60
65
  // Query handlers
@@ -122,7 +127,8 @@ function useDefaultQueryDefinition(queryTypes) {
122
127
  isCollapsed: !!queriesCollapsed[i],
123
128
  onChange: handleQueryChange,
124
129
  onDelete: queries.length > 1 ? handleQueryDelete : undefined,
125
- onCollapseExpand: handleQueryCollapseExpand
130
+ onCollapseExpand: handleQueryCollapseExpand,
131
+ filteredQueryPlugins: filteredQueryPlugins
126
132
  }, i))
127
133
  }),
128
134
  /*#__PURE__*/ _jsx(Button, {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"sourcesContent":["// Copyright 2024 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 { forwardRef, ReactElement, useState } from 'react';\nimport { produce } from 'immer';\nimport { Button, Stack } from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { QueryDefinition, QueryPluginType } from '@perses-dev/core';\nimport { useListPluginMetadata, usePlugin, usePluginRegistry } from '../../runtime';\nimport { PluginEditorRef } from '../PluginEditor';\nimport { QueryEditorContainer } from './QueryEditorContainer';\n\nexport interface MultiQueryEditorProps {\n queryTypes: QueryPluginType[];\n queries?: QueryDefinition[];\n onChange: (queries: QueryDefinition[]) => void;\n}\n\nfunction useDefaultQueryDefinition(queryTypes: QueryPluginType[]): {\n defaultInitialQueryDefinition: QueryDefinition;\n isLoading: boolean;\n} {\n // Build the default query plugin\n // This will be used only if the queries are empty, to open a starting query\n\n // Firs the default query type\n const defaultQueryType = queryTypes[0]!;\n\n // Then the default plugin kind\n // Use as default the plugin kind explicitly set as default or the first in the list\n const { data: queryPlugins, isLoading } = useListPluginMetadata(queryTypes);\n const { defaultPluginKinds } = usePluginRegistry();\n const defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';\n\n const { data: defaultQueryPlugin } = usePlugin(defaultQueryType, defaultQueryKind, {\n useErrorBoundary: true,\n enabled: true,\n });\n\n // This default query definition is used if no query is provided initially or when we add a new query\n return {\n defaultInitialQueryDefinition: {\n kind: defaultQueryType,\n spec: {\n plugin: { kind: defaultQueryKind, spec: defaultQueryPlugin?.createInitialOptions() || {} },\n },\n },\n isLoading,\n };\n}\n\n/**\n * A component render a list of {@link QueryEditorContainer} for the given query definitions.\n * It allows adding, removing and editing queries.\n * @param queryTypes The list of query types that the underlying editor will propose\n * @param queries The list of query definitions to render\n * @param onChange The callback to call when the queries are modified\n * @constructor\n */\n\nexport const MultiQueryEditor = forwardRef<PluginEditorRef, MultiQueryEditorProps>((props, ref): ReactElement => {\n const { queryTypes, queries = [], onChange } = props;\n const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);\n // State for which queries are collapsed\n const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(() => false));\n\n // Query handlers\n const handleQueryChange = (index: number, queryDef: QueryDefinition): void => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft[index] = queryDef;\n } else {\n draft = [queryDef];\n }\n })\n );\n };\n\n const handleQueryAdd = (): void => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft.push(defaultInitialQueryDefinition);\n } else {\n draft = [...queries, defaultInitialQueryDefinition];\n }\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.push(false);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryDelete = (index: number): void => {\n onChange(\n produce(queries, (draft) => {\n draft.splice(index, 1);\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.splice(index, 1);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryCollapseExpand = (index: number): void => {\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed[index] = !queriesCollapsed[index];\n return [...queriesCollapsed];\n });\n };\n\n // show one query input if queries is empty\n const queryDefinitions: QueryDefinition[] = queries.length\n ? queries\n : !isLoading\n ? [defaultInitialQueryDefinition]\n : [];\n\n return (\n <>\n <Stack spacing={1}>\n {queryDefinitions.map((query: QueryDefinition, i: number) => (\n <QueryEditorContainer\n ref={ref}\n queryTypes={queryTypes}\n key={i}\n index={i}\n query={query}\n isCollapsed={!!queriesCollapsed[i]}\n onChange={handleQueryChange}\n onDelete={queries.length > 1 ? handleQueryDelete : undefined}\n onCollapseExpand={handleQueryCollapseExpand}\n />\n ))}\n </Stack>\n <Button variant=\"contained\" startIcon={<AddIcon />} sx={{ marginTop: 1 }} onClick={handleQueryAdd}>\n Add Query\n </Button>\n </>\n );\n});\n\nMultiQueryEditor.displayName = 'MultiQueryEditor';\n"],"names":["forwardRef","useState","produce","Button","Stack","AddIcon","useListPluginMetadata","usePlugin","usePluginRegistry","QueryEditorContainer","useDefaultQueryDefinition","queryTypes","defaultQueryType","data","queryPlugins","isLoading","defaultPluginKinds","defaultQueryKind","spec","name","defaultQueryPlugin","useErrorBoundary","enabled","defaultInitialQueryDefinition","kind","plugin","createInitialOptions","MultiQueryEditor","props","ref","queries","onChange","queriesCollapsed","setQueriesCollapsed","map","handleQueryChange","index","queryDef","draft","handleQueryAdd","push","handleQueryDelete","splice","handleQueryCollapseExpand","queryDefinitions","length","spacing","query","i","isCollapsed","onDelete","undefined","onCollapseExpand","variant","startIcon","sx","marginTop","onClick","displayName"],"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,SAASA,UAAU,EAAgBC,QAAQ,QAAQ,Q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AE;gBAAGC,SAASlB;0BAAgB;;;;AAKzG,GAAG;AAEHZ,iBAAiB+B,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../src/components/MultiQueryEditor/MultiQueryEditor.tsx"],"sourcesContent":["// Copyright 2024 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 { forwardRef, ReactElement, useState } from 'react';\nimport { produce } from 'immer';\nimport { Button, Stack } from '@mui/material';\nimport AddIcon from 'mdi-material-ui/Plus';\nimport { QueryDefinition, QueryPluginType } from '@perses-dev/core';\nimport { useListPluginMetadata, usePlugin, usePluginRegistry } from '../../runtime';\nimport { PluginEditorRef } from '../PluginEditor';\nimport { QueryEditorContainer } from './QueryEditorContainer';\n\nexport interface MultiQueryEditorProps {\n queryTypes: QueryPluginType[];\n filteredQueryPlugins?: string[];\n queries?: QueryDefinition[];\n onChange: (queries: QueryDefinition[]) => void;\n}\n\nfunction useDefaultQueryDefinition(\n queryTypes: QueryPluginType[],\n filteredQueryPlugins?: string[]\n): {\n defaultInitialQueryDefinition: QueryDefinition;\n isLoading: boolean;\n} {\n // Build the default query plugin\n // This will be used only if the queries are empty, to open a starting query\n\n // Firs the default query type\n const defaultQueryType = queryTypes[0]!;\n // Then the default plugin kind\n // Use as default the plugin kind explicitly set as default or the first in the list\n const { data: queryPlugins, isLoading } = useListPluginMetadata(queryTypes);\n const { defaultPluginKinds } = usePluginRegistry();\n\n let defaultQueryKind: string = '';\n\n if (filteredQueryPlugins?.length) {\n defaultQueryKind = queryPlugins?.find((i) => filteredQueryPlugins.includes(i.spec.name))!.spec.name ?? '';\n } else {\n defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';\n }\n\n const { data: defaultQueryPlugin } = usePlugin(defaultQueryType, defaultQueryKind, {\n useErrorBoundary: true,\n enabled: true,\n });\n\n // This default query definition is used if no query is provided initially or when we add a new query\n return {\n defaultInitialQueryDefinition: {\n kind: defaultQueryType,\n spec: {\n plugin: { kind: defaultQueryKind, spec: defaultQueryPlugin?.createInitialOptions() || {} },\n },\n },\n isLoading,\n };\n}\n\n/**\n * A component render a list of {@link QueryEditorContainer} for the given query definitions.\n * It allows adding, removing and editing queries.\n * @param queryTypes The list of query types that the underlying editor will propose\n * @param queries The list of query definitions to render\n * @param onChange The callback to call when the queries are modified\n * @constructor\n */\n\nexport const MultiQueryEditor = forwardRef<PluginEditorRef, MultiQueryEditorProps>((props, ref): ReactElement => {\n const { queryTypes, queries = [], filteredQueryPlugins, onChange } = props;\n const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes, filteredQueryPlugins);\n // State for which queries are collapsed\n const [queriesCollapsed, setQueriesCollapsed] = useState(queries.map(() => false));\n\n // Query handlers\n const handleQueryChange = (index: number, queryDef: QueryDefinition): void => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft[index] = queryDef;\n } else {\n draft = [queryDef];\n }\n })\n );\n };\n\n const handleQueryAdd = (): void => {\n onChange(\n produce(queries, (draft) => {\n if (draft) {\n draft.push(defaultInitialQueryDefinition);\n } else {\n draft = [...queries, defaultInitialQueryDefinition];\n }\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.push(false);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryDelete = (index: number): void => {\n onChange(\n produce(queries, (draft) => {\n draft.splice(index, 1);\n })\n );\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed.splice(index, 1);\n return [...queriesCollapsed];\n });\n };\n\n const handleQueryCollapseExpand = (index: number): void => {\n setQueriesCollapsed((queriesCollapsed) => {\n queriesCollapsed[index] = !queriesCollapsed[index];\n return [...queriesCollapsed];\n });\n };\n\n // show one query input if queries is empty\n const queryDefinitions: QueryDefinition[] = queries.length\n ? queries\n : !isLoading\n ? [defaultInitialQueryDefinition]\n : [];\n\n return (\n <>\n <Stack spacing={1}>\n {queryDefinitions.map((query: QueryDefinition, i: number) => (\n <QueryEditorContainer\n ref={ref}\n queryTypes={queryTypes}\n key={i}\n index={i}\n query={query}\n isCollapsed={!!queriesCollapsed[i]}\n onChange={handleQueryChange}\n onDelete={queries.length > 1 ? handleQueryDelete : undefined}\n onCollapseExpand={handleQueryCollapseExpand}\n filteredQueryPlugins={filteredQueryPlugins}\n />\n ))}\n </Stack>\n <Button variant=\"contained\" startIcon={<AddIcon />} sx={{ marginTop: 1 }} onClick={handleQueryAdd}>\n Add Query\n </Button>\n </>\n );\n});\n\nMultiQueryEditor.displayName = 'MultiQueryEditor';\n"],"names":["forwardRef","useState","produce","Button","Stack","AddIcon","useListPluginMetadata","usePlugin","usePluginRegistry","QueryEditorContainer","useDefaultQueryDefinition","queryTypes","filteredQueryPlugins","defaultQueryType","data","queryPlugins","isLoading","defaultPluginKinds","defaultQueryKind","length","find","i","includes","spec","name","defaultQueryPlugin","useErrorBoundary","enabled","defaultInitialQueryDefinition","kind","plugin","createInitialOptions","MultiQueryEditor","props","ref","queries","onChange","queriesCollapsed","setQueriesCollapsed","map","handleQueryChange","index","queryDef","draft","handleQueryAdd","push","handleQueryDelete","splice","handleQueryCollapseExpand","queryDefinitions","spacing","query","isCollapsed","onDelete","undefined","onCollapseExpand","variant","startIcon","sx","marginTop","onClick","displayName"],"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,SAASA,UAAU,EAAgBC,QAAQ,QAAQ,QAAQ;AAC3D,SAASC,OAA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B,EAAE;wBAClCe,UAAUI;wBACVa,UAAUlB,QAAQhB,MAAM,GAAG,IAAI2B,oBAAoBQ;wBACnDC,kBAAkBP;wBAClBpC,sBAAsBA;uBAPjBS;;0BAWX,KAAClB;gBAAOqD,SAAQ;gBAAYC,yBAAW,KAACpD;gBAAYqD,IAAI;oBAAEC,WAAW;gBAAE;gBAAGC,SAAShB;0BAAgB;;;;AAKzG,GAAG;AAEHZ,iBAAiB6B,WAAW,GAAG"}
@@ -8,6 +8,7 @@ interface QueryEditorContainerProps {
8
8
  queryTypes: QueryPluginType[];
9
9
  index: number;
10
10
  query: QueryDefinition;
11
+ filteredQueryPlugins?: string[];
11
12
  onChange: (index: number, query: QueryDefinition) => void;
12
13
  onCollapseExpand: (index: number) => void;
13
14
  isCollapsed?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"QueryEditorContainer.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMpE,OAAO,EAAmC,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGnF;;GAEG;AACH,UAAU,yBAAyB;IACjC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC1D,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,oBAAoB,uHA2BhC,CAAC"}
1
+ {"version":3,"file":"QueryEditorContainer.d.ts","sourceRoot":"","sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAMpE,OAAO,EAAmC,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAGnF;;GAEG;AACH,UAAU,yBAAyB;IACjC,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,eAAe,CAAC;IACvB,oBAAoB,CAAC,EAAE,MAAM,EAAE,CAAC;IAChC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAC1D,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC1C,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,oBAAoB,uHAiChC,CAAC"}
@@ -31,7 +31,7 @@ import { useTimeRange } from '../../runtime';
31
31
  * @param onCollapseExpand callback when the query is collapsed or expanded
32
32
  * @constructor
33
33
  */ export const QueryEditorContainer = /*#__PURE__*/ forwardRef((props, ref)=>{
34
- const { queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
34
+ const { queryTypes, filteredQueryPlugins, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
35
35
  return /*#__PURE__*/ _jsxs(Stack, {
36
36
  spacing: 1,
37
37
  children: [
@@ -67,6 +67,7 @@ import { useTimeRange } from '../../runtime';
67
67
  ]
68
68
  }),
69
69
  !isCollapsed && /*#__PURE__*/ _jsx(QueryEditor, {
70
+ filteredQueryPlugins: filteredQueryPlugins,
70
71
  ref: ref,
71
72
  queryTypes: queryTypes,
72
73
  value: query,
@@ -83,7 +84,7 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
83
84
  * @param props
84
85
  * @constructor
85
86
  */ const QueryEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
86
- const { value, onChange, queryTypes, ...others } = props;
87
+ const { value, onChange, queryTypes, filteredQueryPlugins, ...others } = props;
87
88
  const { refresh } = useTimeRange();
88
89
  const handlePluginChange = (next)=>{
89
90
  onChange(produce(value, (draft)=>{
@@ -107,7 +108,8 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
107
108
  },
108
109
  spec: value.spec.plugin.spec
109
110
  },
110
- onChange: handlePluginChange
111
+ onChange: handlePluginChange,
112
+ filteredQueryPlugins: filteredQueryPlugins
111
113
  })
112
114
  });
113
115
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.tsx"],"sourcesContent":["// Copyright 2024 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 { produce } from 'immer';\nimport { QueryDefinition, QueryPluginType } from '@perses-dev/core';\nimport { Stack, IconButton, Typography, BoxProps, Box } from '@mui/material';\nimport DeleteIcon from 'mdi-material-ui/DeleteOutline';\nimport ChevronDown from 'mdi-material-ui/ChevronDown';\nimport ChevronRight from 'mdi-material-ui/ChevronRight';\nimport { forwardRef, ReactElement } from 'react';\nimport { PluginEditor, PluginEditorProps, PluginEditorRef } from '../PluginEditor';\nimport { useTimeRange } from '../../runtime';\n\n/**\n * Properties for {@link QueryEditorContainer}\n */\ninterface QueryEditorContainerProps {\n queryTypes: QueryPluginType[];\n index: number;\n query: QueryDefinition;\n onChange: (index: number, query: QueryDefinition) => void;\n onCollapseExpand: (index: number) => void;\n isCollapsed?: boolean;\n onDelete?: (index: number) => void;\n}\n\n/**\n * Container for a query editor. This component is responsible for rendering the query editor, and make it collapsible\n * to not take too much space.\n * @param queryTypes the supported query types\n * @param index the index of the query in the list\n * @param query the query definition\n * @param isCollapsed whether the query editor is collapsed or not\n * @param onDelete callback when the query is deleted\n * @param onChange callback when the query is changed\n * @param onCollapseExpand callback when the query is collapsed or expanded\n * @constructor\n */\n\nexport const QueryEditorContainer = forwardRef<PluginEditorRef, QueryEditorContainerProps>(\n (props, ref): ReactElement => {\n const { queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;\n return (\n <Stack key={index} spacing={1}>\n <Stack direction=\"row\" alignItems=\"center\" borderBottom={1} borderColor={(theme) => theme.palette.divider}>\n <IconButton size=\"small\" onClick={() => onCollapseExpand(index)}>\n {isCollapsed ? <ChevronRight /> : <ChevronDown />}\n </IconButton>\n <Typography variant=\"overline\" component=\"h4\">\n Query #{index + 1}\n </Typography>\n <IconButton\n size=\"small\"\n // Use `visibility` to ensure that the row has the same height when delete button is visible or not visible\n sx={{ marginLeft: 'auto', visibility: `${onDelete ? 'visible' : 'hidden'}` }}\n onClick={() => onDelete && onDelete(index)}\n >\n <DeleteIcon />\n </IconButton>\n </Stack>\n {!isCollapsed && (\n <QueryEditor ref={ref} queryTypes={queryTypes} value={query} onChange={(next) => onChange(index, next)} />\n )}\n </Stack>\n );\n }\n);\n\nQueryEditorContainer.displayName = 'QueryEditorContainer';\n\n// Props on MUI Box that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\ninterface QueryEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n queryTypes: QueryPluginType[];\n value: QueryDefinition;\n onChange: (next: QueryDefinition) => void;\n}\n\n/**\n * Editor for a query definition. This component is responsible for rendering the plugin editor for the given query.\n * This will allow user to select a plugin extending from the given supported query types, and then edit the plugin\n * spec for this plugin.\n * @param props\n * @constructor\n */\n\nconst QueryEditor = forwardRef<PluginEditorRef, QueryEditorProps>((props, ref): ReactElement => {\n const { value, onChange, queryTypes, ...others } = props;\n const { refresh } = useTimeRange();\n const handlePluginChange: PluginEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.kind = next.selection.type;\n draft.spec.plugin.kind = next.selection.kind;\n draft.spec.plugin.spec = next.spec;\n })\n );\n };\n\n return (\n <Box {...others}>\n <PluginEditor\n postExecuteRunQuery={refresh}\n ref={ref}\n withRunQueryButton\n pluginTypes={queryTypes}\n pluginKindLabel=\"Query Type\"\n value={{\n selection: {\n kind: value.spec.plugin.kind,\n type: value.kind,\n },\n spec: value.spec.plugin.spec,\n }}\n onChange={handlePluginChange}\n />\n </Box>\n );\n});\n\nQueryEditor.displayName = 'QueryEditor';\n"],"names":["produce","Stack","IconButton","Typography","Box","DeleteIcon","ChevronDown","ChevronRight","forwardRef","PluginEditor","useTimeRange","QueryEditorContainer","props","ref","queryTypes","index","query","isCollapsed","onDelete","onChange","onCollapseExpand","spacing","direction","alignItems","borderBottom","borderColor","theme","palette","divider","size","onClick","variant","component","sx","marginLeft","visibility","QueryEditor","value","next","displayName","others","refresh","handlePluginChange","draft","kind","selection","type","spec","plugin","postExecuteRunQuery","withRunQueryButton","pluginTypes","pluginKindLabel"],"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,SAASA,OAAO,QAAQ,QAAQ;AAEhC,SAASC,KAAK,EAAEC,UAAU,EAAEC,UAAU,EAAYC,GAAG,QAAQ,gBAAgB;AAC7E,OAAOC,gBAAgB,gCAAgC;AACvD,OAAOC,iBAAiB,8BAA8B;AACtD,OAAOC,kBAAkB,+BAA+B;AACxD,SAASC,UAAU,QAAsB,QAAQ;AACjD,SAASC,YAAY,QAA4C,kBAAkB;A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CAACC,MAAM,CAACJ,IAAI,GAAGN,KAAKO,SAAS,CAACD,IAAI;YAC5CD,MAAMI,IAAI,CAACC,MAAM,CAACD,IAAI,GAAGT,KAAKS,IAAI;QACpC;IAEJ;IAEA,qBACE,KAAC3C;QAAK,GAAGoC,MAAM;kBACb,cAAA,KAAC/B;YACCwC,qBAAqBR;YACrB5B,KAAKA;YACLqC,kBAAkB;YAClBC,aAAarC;YACbsC,iBAAgB;YAChBf,OAAO;gBACLQ,WAAW;oBACTD,MAAMP,MAAMU,IAAI,CAACC,MAAM,CAACJ,IAAI;oBAC5BE,MAAMT,MAAMO,IAAI;gBAClB;gBACAG,MAAMV,MAAMU,IAAI,CAACC,MAAM,CAACD,IAAI;YAC9B;YACA5B,UAAUuB;;;AAIlB;AAEAN,YAAYG,WAAW,GAAG"}
1
+ {"version":3,"sources":["../../../src/components/MultiQueryEditor/QueryEditorContainer.tsx"],"sourcesContent":["// Copyright 2024 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 { produce } from 'immer';\nimport { QueryDefinition, QueryPluginType } from '@perses-dev/core';\nimport { Stack, IconButton, Typography, BoxProps, Box } from '@mui/material';\nimport DeleteIcon from 'mdi-material-ui/DeleteOutline';\nimport ChevronDown from 'mdi-material-ui/ChevronDown';\nimport ChevronRight from 'mdi-material-ui/ChevronRight';\nimport { forwardRef, ReactElement } from 'react';\nimport { PluginEditor, PluginEditorProps, PluginEditorRef } from '../PluginEditor';\nimport { useTimeRange } from '../../runtime';\n\n/**\n * Properties for {@link QueryEditorContainer}\n */\ninterface QueryEditorContainerProps {\n queryTypes: QueryPluginType[];\n index: number;\n query: QueryDefinition;\n filteredQueryPlugins?: string[];\n onChange: (index: number, query: QueryDefinition) => void;\n onCollapseExpand: (index: number) => void;\n isCollapsed?: boolean;\n onDelete?: (index: number) => void;\n}\n\n/**\n * Container for a query editor. This component is responsible for rendering the query editor, and make it collapsible\n * to not take too much space.\n * @param queryTypes the supported query types\n * @param index the index of the query in the list\n * @param query the query definition\n * @param isCollapsed whether the query editor is collapsed or not\n * @param onDelete callback when the query is deleted\n * @param onChange callback when the query is changed\n * @param onCollapseExpand callback when the query is collapsed or expanded\n * @constructor\n */\n\nexport const QueryEditorContainer = forwardRef<PluginEditorRef, QueryEditorContainerProps>(\n (props, ref): ReactElement => {\n const { queryTypes, filteredQueryPlugins, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;\n return (\n <Stack key={index} spacing={1}>\n <Stack direction=\"row\" alignItems=\"center\" borderBottom={1} borderColor={(theme) => theme.palette.divider}>\n <IconButton size=\"small\" onClick={() => onCollapseExpand(index)}>\n {isCollapsed ? <ChevronRight /> : <ChevronDown />}\n </IconButton>\n <Typography variant=\"overline\" component=\"h4\">\n Query #{index + 1}\n </Typography>\n <IconButton\n size=\"small\"\n // Use `visibility` to ensure that the row has the same height when delete button is visible or not visible\n sx={{ marginLeft: 'auto', visibility: `${onDelete ? 'visible' : 'hidden'}` }}\n onClick={() => onDelete && onDelete(index)}\n >\n <DeleteIcon />\n </IconButton>\n </Stack>\n {!isCollapsed && (\n <QueryEditor\n filteredQueryPlugins={filteredQueryPlugins}\n ref={ref}\n queryTypes={queryTypes}\n value={query}\n onChange={(next) => onChange(index, next)}\n />\n )}\n </Stack>\n );\n }\n);\n\nQueryEditorContainer.displayName = 'QueryEditorContainer';\n\n// Props on MUI Box that we don't want people to pass because we're either redefining them or providing them in\n// this component\ntype OmittedMuiProps = 'children' | 'value' | 'onChange';\ninterface QueryEditorProps extends Omit<BoxProps, OmittedMuiProps> {\n queryTypes: QueryPluginType[];\n filteredQueryPlugins?: string[];\n value: QueryDefinition;\n onChange: (next: QueryDefinition) => void;\n}\n\n/**\n * Editor for a query definition. This component is responsible for rendering the plugin editor for the given query.\n * This will allow user to select a plugin extending from the given supported query types, and then edit the plugin\n * spec for this plugin.\n * @param props\n * @constructor\n */\n\nconst QueryEditor = forwardRef<PluginEditorRef, QueryEditorProps>((props, ref): ReactElement => {\n const { value, onChange, queryTypes, filteredQueryPlugins, ...others } = props;\n const { refresh } = useTimeRange();\n const handlePluginChange: PluginEditorProps['onChange'] = (next) => {\n onChange(\n produce(value, (draft) => {\n draft.kind = next.selection.type;\n draft.spec.plugin.kind = next.selection.kind;\n draft.spec.plugin.spec = next.spec;\n })\n );\n };\n\n return (\n <Box {...others}>\n <PluginEditor\n postExecuteRunQuery={refresh}\n ref={ref}\n withRunQueryButton\n pluginTypes={queryTypes}\n pluginKindLabel=\"Query Type\"\n value={{\n selection: {\n kind: value.spec.plugin.kind,\n type: value.kind,\n },\n spec: value.spec.plugin.spec,\n }}\n onChange={handlePluginChange}\n filteredQueryPlugins={filteredQueryPlugins}\n />\n </Box>\n );\n});\n\nQueryEditor.displayName = 'QueryEditor';\n"],"names":["produce","Stack","IconButton","Typography","Box","DeleteIcon","ChevronDown","ChevronRight","forwardRef","PluginEditor","useTimeRange","QueryEditorContainer","props","ref","queryTypes","filteredQueryPlugins","index","query","isCollapsed","onDelete","onChange","onCollapseExpand","spacing","direction","alignItems","borderBottom","borderColor","theme","palette","divider","size","onClick","variant","component","sx","marginLeft","visibility","QueryEditor","value","next","displayName","others","refresh","handlePluginChange","draft","kind","selection","type","spec","plugin","postExecuteRunQuery","withRunQueryButton","pluginTypes","pluginKindLabel"],"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,SAASA,OAAO,QAAQ,QAAQ;AAE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E,MAAM,EAAEyB,KAAK,EAAElB,QAAQ,EAAEN,UAAU,EAAEC,oBAAoB,EAAE,GAAG0B,QAAQ,GAAG7B;IACzE,MAAM,EAAE8B,OAAO,EAAE,GAAGhC;IACpB,MAAMiC,qBAAoD,CAACJ;QACzDnB,SACEpB,QAAQsC,OAAO,CAACM;YACdA,MAAMC,IAAI,GAAGN,KAAKO,SAAS,CAACC,IAAI;YAChCH,MAAMI,IAAI,CAACC,MAAM,CAACJ,IAAI,GAAGN,KAAKO,SAAS,CAACD,IAAI;YAC5CD,MAAMI,IAAI,CAACC,MAAM,CAACD,IAAI,GAAGT,KAAKS,IAAI;QACpC;IAEJ;IAEA,qBACE,KAAC5C;QAAK,GAAGqC,MAAM;kBACb,cAAA,KAAChC;YACCyC,qBAAqBR;YACrB7B,KAAKA;YACLsC,kBAAkB;YAClBC,aAAatC;YACbuC,iBAAgB;YAChBf,OAAO;gBACLQ,WAAW;oBACTD,MAAMP,MAAMU,IAAI,CAACC,MAAM,CAACJ,IAAI;oBAC5BE,MAAMT,MAAMO,IAAI;gBAClB;gBACAG,MAAMV,MAAMU,IAAI,CAACC,MAAM,CAACD,IAAI;YAC9B;YACA5B,UAAUuB;YACV5B,sBAAsBA;;;AAI9B;AAEAsB,YAAYG,WAAW,GAAG"}
@@ -1 +1 @@
1
- {"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAoBA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAmB,MAAM,qBAAqB,CAAC;AAE1F;;;;;;;GAOG;AAEH,eAAO,MAAM,YAAY,4HAwFvB,CAAC"}
1
+ {"version":3,"file":"PluginEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PluginEditor/PluginEditor.tsx"],"names":[],"mappings":";AAoBA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAmB,MAAM,qBAAqB,CAAC;AAE1F;;;;;;;GAOG;AAEH,eAAO,MAAM,YAAY,4HA0FvB,CAAC"}
@@ -26,7 +26,7 @@ import { usePluginEditor } from './plugin-editor-api';
26
26
  * previous plugin's spec state. If you just want this behavior, but in a different UI layout from this, try the
27
27
  * `usePluginEditor` hook that powers this component.
28
28
  */ export const PluginEditor = /*#__PURE__*/ forwardRef((props, ref)=>{
29
- const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, postExecuteRunQuery: refresh, ...others } = props;
29
+ const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, postExecuteRunQuery: refresh, filteredQueryPlugins, ...others } = props;
30
30
  const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = usePluginEditor(props);
31
31
  /*
32
32
  We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,
@@ -96,7 +96,8 @@ import { usePluginEditor } from './plugin-editor-api';
96
96
  },
97
97
  error: !!error,
98
98
  helperText: error?.message,
99
- onChange: onSelectionChange
99
+ onChange: onSelectionChange,
100
+ filteredQueryPlugins: filteredQueryPlugins
100
101
  }),
101
102
  withRunQueryButton && !isLoading && /*#__PURE__*/ _jsx(Button, {
102
103
  "data-testid": "run_query_button",