@perses-dev/plugin-system 0.52.0 → 0.53.0-beta.0

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 (85) 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/Variables/VariableEditorForm/VariableEditorForm.js +25 -34
  4. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +33 -19
  5. package/dist/cjs/components/Variables/VariableEditorForm/index.js +1 -0
  6. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +47 -0
  7. package/dist/cjs/components/Variables/variable-model.js +3 -3
  8. package/dist/cjs/components/index.js +0 -1
  9. package/dist/cjs/context/index.js +0 -1
  10. package/dist/cjs/remote/remotePluginLoader.js +19 -4
  11. package/dist/cjs/runtime/UsageMetricsProvider.js +4 -3
  12. package/dist/cjs/runtime/time-series-queries.js +4 -4
  13. package/dist/cjs/test/mock-data.js +158 -0
  14. package/dist/components/{DatasourceSelect.d.ts → DatasourceSelect/DatasourceSelect.d.ts} +1 -1
  15. package/dist/components/DatasourceSelect/DatasourceSelect.d.ts.map +1 -0
  16. package/dist/components/{DatasourceSelect.js → DatasourceSelect/DatasourceSelect.js} +2 -2
  17. package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -0
  18. package/dist/components/DatasourceSelect/index.d.ts +2 -0
  19. package/dist/components/DatasourceSelect/index.d.ts.map +1 -0
  20. package/dist/components/DatasourceSelect/index.js +15 -0
  21. package/dist/components/DatasourceSelect/index.js.map +1 -0
  22. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  23. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +25 -34
  24. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  25. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts +2 -0
  26. package/dist/components/Variables/VariableEditorForm/VariablePreview.d.ts.map +1 -1
  27. package/dist/components/Variables/VariableEditorForm/VariablePreview.js +33 -19
  28. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  29. package/dist/components/Variables/VariableEditorForm/index.d.ts +1 -0
  30. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -1
  31. package/dist/components/Variables/VariableEditorForm/index.js +1 -0
  32. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
  33. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +6 -0
  34. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  35. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +44 -0
  36. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  37. package/dist/components/Variables/variable-model.js +3 -3
  38. package/dist/components/Variables/variable-model.js.map +1 -1
  39. package/dist/components/index.d.ts +0 -1
  40. package/dist/components/index.d.ts.map +1 -1
  41. package/dist/components/index.js +0 -1
  42. package/dist/components/index.js.map +1 -1
  43. package/dist/context/index.d.ts +0 -1
  44. package/dist/context/index.d.ts.map +1 -1
  45. package/dist/context/index.js +0 -1
  46. package/dist/context/index.js.map +1 -1
  47. package/dist/model/time-series-queries.d.ts +1 -1
  48. package/dist/model/time-series-queries.d.ts.map +1 -1
  49. package/dist/model/time-series-queries.js.map +1 -1
  50. package/dist/model/variables.d.ts +1 -1
  51. package/dist/model/variables.d.ts.map +1 -1
  52. package/dist/model/variables.js.map +1 -1
  53. package/dist/remote/remotePluginLoader.d.ts +18 -1
  54. package/dist/remote/remotePluginLoader.d.ts.map +1 -1
  55. package/dist/remote/remotePluginLoader.js +22 -4
  56. package/dist/remote/remotePluginLoader.js.map +1 -1
  57. package/dist/runtime/UsageMetricsProvider.d.ts +3 -1
  58. package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
  59. package/dist/runtime/UsageMetricsProvider.js +4 -3
  60. package/dist/runtime/UsageMetricsProvider.js.map +1 -1
  61. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  62. package/dist/runtime/time-series-queries.js +4 -4
  63. package/dist/runtime/time-series-queries.js.map +1 -1
  64. package/dist/test/mock-data.d.ts +134 -0
  65. package/dist/test/mock-data.d.ts.map +1 -1
  66. package/dist/test/mock-data.js +135 -0
  67. package/dist/test/mock-data.js.map +1 -1
  68. package/package.json +3 -3
  69. package/dist/cjs/components/ProjectSelect.js +0 -96
  70. package/dist/cjs/context/ProjectStoreProvider.js +0 -81
  71. package/dist/cjs/context/query-params.js +0 -49
  72. package/dist/components/DatasourceSelect.d.ts.map +0 -1
  73. package/dist/components/DatasourceSelect.js.map +0 -1
  74. package/dist/components/ProjectSelect.d.ts +0 -15
  75. package/dist/components/ProjectSelect.d.ts.map +0 -1
  76. package/dist/components/ProjectSelect.js +0 -91
  77. package/dist/components/ProjectSelect.js.map +0 -1
  78. package/dist/context/ProjectStoreProvider.d.ts +0 -16
  79. package/dist/context/ProjectStoreProvider.d.ts.map +0 -1
  80. package/dist/context/ProjectStoreProvider.js +0 -59
  81. package/dist/context/ProjectStoreProvider.js.map +0 -1
  82. package/dist/context/query-params.d.ts +0 -5
  83. package/dist/context/query-params.d.ts.map +0 -1
  84. package/dist/context/query-params.js +0 -41
  85. package/dist/context/query-params.js.map +0 -1
@@ -47,8 +47,8 @@ const _jsxruntime = require("react/jsx-runtime");
47
47
  const _react = require("react");
48
48
  const _OpenInNew = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/OpenInNew"));
49
49
  const _material = require("@mui/material");
50
- const _runtime = require("../runtime");
51
- const _utils = require("../utils");
50
+ const _runtime = require("../../runtime");
51
+ const _utils = require("../../utils");
52
52
  function _interop_require_default(obj) {
53
53
  return obj && obj.__esModule ? obj : {
54
54
  default: obj
@@ -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
+ _export_star(require("./DatasourceSelect"), exports);
18
+ function _export_star(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
21
+ Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ }
28
+ });
29
+ return from;
30
+ }
@@ -32,6 +32,7 @@ const _context = require("../../../context");
32
32
  const _variablemodel = require("../variable-model");
33
33
  const _runtime = require("../../../runtime");
34
34
  const _VariablePreview = require("./VariablePreview");
35
+ const _variableeditorformmodel = require("./variable-editor-form-model");
35
36
  function FallbackPreview() {
36
37
  return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
37
38
  children: "Error previewing values"
@@ -117,6 +118,10 @@ function ListVariableEditorForm({ action, control }) {
117
118
  control: control,
118
119
  name: 'spec.allowAllValue'
119
120
  });
121
+ const sortMethod = (0, _reacthookform.useWatch)({
122
+ control: control,
123
+ name: 'spec.sort'
124
+ });
120
125
  // When variable kind is selected we need to provide default values
121
126
  // TODO: check if react-hook-form has a better way to do this
122
127
  const values = form.getValues();
@@ -126,6 +131,15 @@ function ListVariableEditorForm({ action, control }) {
126
131
  if (values.spec.allowMultiple === undefined) {
127
132
  form.setValue('spec.allowMultiple', false);
128
133
  }
134
+ if (!values.spec.plugin) {
135
+ form.setValue('spec.plugin', {
136
+ kind: 'StaticListVariable',
137
+ spec: {}
138
+ });
139
+ }
140
+ if (!values.spec.sort) {
141
+ form.setValue('spec.sort', 'none');
142
+ }
129
143
  const { refresh } = (0, _runtime.useTimeRange)();
130
144
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
131
145
  children: [
@@ -138,18 +152,17 @@ function ListVariableEditorForm({ action, control }) {
138
152
  spacing: 2,
139
153
  mb: 2,
140
154
  children: [
141
- kind ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
155
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
142
156
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorBoundary, {
143
157
  FallbackComponent: FallbackPreview,
144
158
  resetKeys: [
145
159
  previewSpec
146
160
  ],
147
161
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_VariablePreview.VariableListPreview, {
162
+ sortMethod: sortMethod,
148
163
  definition: previewSpec
149
164
  })
150
165
  })
151
- }) : /*#__PURE__*/ (0, _jsxruntime.jsx)(_VariablePreview.VariablePreview, {
152
- isLoading: true
153
166
  }),
154
167
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
155
168
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorBoundary, {
@@ -215,7 +228,7 @@ function ListVariableEditorForm({ action, control }) {
215
228
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reacthookform.Controller, {
216
229
  control: control,
217
230
  name: "spec.sort",
218
- render: ({ field, fieldState })=>/*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.TextField, {
231
+ render: ({ field, fieldState })=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.TextField, {
219
232
  select: true,
220
233
  ...field,
221
234
  fullWidth: true,
@@ -232,36 +245,14 @@ function ListVariableEditorForm({ action, control }) {
232
245
  onChange: (event)=>{
233
246
  field.onChange(event);
234
247
  },
235
- children: [
236
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
237
- value: "none",
238
- children: "None"
239
- }),
240
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
241
- value: "alphabetical-asc",
242
- children: "Alphabetical, asc"
243
- }),
244
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
245
- value: "alphabetical-desc",
246
- children: "Alphabetical, desc"
247
- }),
248
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
249
- value: "numerical-asc",
250
- children: "Numerical, asc"
251
- }),
252
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
253
- value: "numerical-desc",
254
- children: "Numerical, desc"
255
- }),
256
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
257
- value: "alphabetical-ci-asc",
258
- children: "Alphabetical, case-insensitive, asc"
259
- }),
260
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
261
- value: "alphabetical-ci-desc",
262
- children: "Alphabetical, case-insensitive, desc"
263
- })
264
- ]
248
+ children: Object.keys(_variableeditorformmodel.SORT_METHODS).map((key)=>{
249
+ if (!_variableeditorformmodel.SORT_METHODS[key]) return null;
250
+ const { label } = _variableeditorformmodel.SORT_METHODS[key];
251
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
252
+ value: key,
253
+ children: label
254
+ }, key);
255
+ })
265
256
  })
266
257
  })
267
258
  })
@@ -35,6 +35,7 @@ const _components = require("@perses-dev/components");
35
35
  const _ClipboardOutline = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/ClipboardOutline"));
36
36
  const _constants = require("../../../constants");
37
37
  const _variablemodel = require("../variable-model");
38
+ const _variableeditorformmodel = require("./variable-editor-form-model");
38
39
  function _interop_require_default(obj) {
39
40
  return obj && obj.__esModule ? obj : {
40
41
  default: obj
@@ -93,6 +94,33 @@ function VariablePreview(props) {
93
94
  if (values && values?.length > 0 && maxValues) {
94
95
  notShown = values.length - maxValues;
95
96
  }
97
+ const variablePreviewState = (0, _react.useMemo)(()=>{
98
+ if (isLoading) {
99
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
100
+ width: "100%",
101
+ sx: {
102
+ alignItems: 'center',
103
+ justifyContent: 'center'
104
+ },
105
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.CircularProgress, {})
106
+ });
107
+ } else if (error) {
108
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Alert, {
109
+ severity: "error",
110
+ children: error
111
+ });
112
+ } else if (!values?.length) {
113
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Alert, {
114
+ severity: "info",
115
+ children: "No results"
116
+ });
117
+ }
118
+ return null;
119
+ }, [
120
+ error,
121
+ isLoading,
122
+ values
123
+ ]);
96
124
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
97
125
  children: [
98
126
  /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
@@ -130,22 +158,7 @@ function VariablePreview(props) {
130
158
  m: 2
131
159
  },
132
160
  children: [
133
- error && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Alert, {
134
- severity: "error",
135
- children: error
136
- }),
137
- values?.length === 0 && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Alert, {
138
- severity: "info",
139
- children: "No results"
140
- }),
141
- isLoading && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
142
- width: "100%",
143
- sx: {
144
- alignItems: 'center',
145
- justifyContent: 'center'
146
- },
147
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.CircularProgress, {})
148
- }),
161
+ variablePreviewState,
149
162
  values?.slice(0, maxValues).map((val, index)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Chip, {
150
163
  size: "small",
151
164
  label: val
@@ -163,17 +176,18 @@ function VariablePreview(props) {
163
176
  });
164
177
  }
165
178
  function VariableListPreview(props) {
166
- const { definition } = props;
179
+ const { definition, sortMethod } = props;
167
180
  const { data, isFetching, error } = (0, _variablemodel.useListVariablePluginValues)(definition);
168
181
  const errorMessage = error?.message;
182
+ const result = !sortMethod || sortMethod === 'none' || !data ? data : _variableeditorformmodel.SORT_METHODS[sortMethod].sort(data);
169
183
  const variablePreview = (0, _react.useMemo)(()=>/*#__PURE__*/ (0, _jsxruntime.jsx)(VariablePreview, {
170
- values: data?.map((val)=>val.value) || [],
184
+ values: result?.map((val)=>val.label || val.value),
171
185
  isLoading: isFetching,
172
186
  error: errorMessage
173
187
  }), [
174
188
  errorMessage,
175
189
  isFetching,
176
- data
190
+ result
177
191
  ]);
178
192
  return variablePreview;
179
193
  }
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  _export_star(require("./VariableEditorForm"), exports);
18
18
  _export_star(require("./VariablePreview"), exports);
19
+ _export_star(require("./variable-editor-form-model"), exports);
19
20
  function _export_star(from, to) {
20
21
  Object.keys(from).forEach(function(k) {
21
22
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -21,6 +21,9 @@ function _export(target, all) {
21
21
  });
22
22
  }
23
23
  _export(exports, {
24
+ SORT_METHODS: function() {
25
+ return SORT_METHODS;
26
+ },
24
27
  getInitialState: function() {
25
28
  return getInitialState;
26
29
  },
@@ -28,6 +31,50 @@ _export(exports, {
28
31
  return getVariableDefinitionFromState;
29
32
  }
30
33
  });
34
+ const SORT_METHODS = {
35
+ none: {
36
+ label: 'None',
37
+ sort: (input)=>{
38
+ return input.slice();
39
+ }
40
+ },
41
+ 'alphabetical-asc': {
42
+ label: 'Alphabetical, asc',
43
+ sort: (input)=>{
44
+ return input.slice().sort((a, b)=>a.label > b.label ? 1 : -1);
45
+ }
46
+ },
47
+ 'alphabetical-desc': {
48
+ label: 'Alphabetical, desc',
49
+ sort: (input)=>{
50
+ return input.slice().sort((a, b)=>a.label > b.label ? -1 : 1);
51
+ }
52
+ },
53
+ 'numerical-asc': {
54
+ label: 'Numerical, asc',
55
+ sort: (input)=>{
56
+ return input.slice().sort((a, b)=>parseInt(a.label) > parseInt(b.label) ? 1 : -1);
57
+ }
58
+ },
59
+ 'numerical-desc': {
60
+ label: 'Numerical, desc',
61
+ sort: (input)=>{
62
+ return input.slice().sort((a, b)=>parseInt(a.label) < parseInt(b.label) ? 1 : -1);
63
+ }
64
+ },
65
+ 'alphabetical-ci-asc': {
66
+ label: 'Alphabetical, case-insensitive, asc',
67
+ sort: (input)=>{
68
+ return input.slice().sort((a, b)=>a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1);
69
+ }
70
+ },
71
+ 'alphabetical-ci-desc': {
72
+ label: 'Alphabetical, case-insensitive, desc',
73
+ sort: (input)=>{
74
+ return input.slice().sort((a, b)=>a.label.toLowerCase() > b.label.toLowerCase() ? -1 : 1);
75
+ }
76
+ }
77
+ };
31
78
  function getInitialState(initialVariableDefinition) {
32
79
  const textVariableFields = {
33
80
  value: initialVariableDefinition.spec.value ?? '',
@@ -93,13 +93,13 @@ function useListVariablePluginValues(definition) {
93
93
  timeRange,
94
94
  refreshKey
95
95
  ],
96
- queryFn: async ()=>{
96
+ queryFn: async ({ signal })=>{
97
97
  const resp = await variablePlugin?.getVariableOptions(spec, {
98
98
  datasourceStore,
99
99
  variables,
100
100
  timeRange
101
- });
102
- if (resp === undefined) {
101
+ }, signal);
102
+ if (!resp?.data?.length) {
103
103
  return [];
104
104
  }
105
105
  if (!capturingRegexp) {
@@ -29,7 +29,6 @@ _export_star(require("./PluginRegistry"), exports);
29
29
  _export_star(require("./PluginSpecEditor"), exports);
30
30
  _export_star(require("./TimeRangeControls"), exports);
31
31
  _export_star(require("./Variables"), exports);
32
- _export_star(require("./ProjectSelect"), exports);
33
32
  _export_star(require("./MetricLabelInput"), exports);
34
33
  function _export_star(from, to) {
35
34
  Object.keys(from).forEach(function(k) {
@@ -14,7 +14,6 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _export_star(require("./ProjectStoreProvider"), exports);
18
17
  _export_star(require("./ValidationProvider"), exports);
19
18
  function _export_star(from, to) {
20
19
  Object.keys(from).forEach(function(k) {
@@ -27,10 +27,25 @@ const isPluginMetadata = (plugin)=>{
27
27
  const isPluginModuleResource = (pluginModule)=>{
28
28
  return typeof pluginModule === 'object' && pluginModule !== null && 'metadata' in pluginModule && 'spec' in pluginModule && typeof pluginModule.spec === 'object' && pluginModule.spec !== null && 'plugins' in pluginModule.spec && Array.isArray(pluginModule.spec.plugins) && pluginModule.spec.plugins.every(isPluginMetadata);
29
29
  };
30
- const remotePluginLoader = (baseURL)=>{
30
+ const DEFAULT_PLUGINS_API_PATH = '/api/v1/plugins';
31
+ const DEFAULT_PLUGINS_ASSETS_PATH = '/plugins';
32
+ const paramToOptions = (options)=>{
33
+ if (options === undefined) {
34
+ return {
35
+ pluginsApiPath: DEFAULT_PLUGINS_API_PATH,
36
+ pluginsAssetsPath: DEFAULT_PLUGINS_ASSETS_PATH
37
+ };
38
+ }
39
+ return {
40
+ pluginsApiPath: `${options?.apiPrefix ?? ''}${DEFAULT_PLUGINS_API_PATH}`,
41
+ pluginsAssetsPath: `${options?.baseURL ?? ''}${DEFAULT_PLUGINS_ASSETS_PATH}`
42
+ };
43
+ };
44
+ function remotePluginLoader(options) {
45
+ const { pluginsApiPath, pluginsAssetsPath } = paramToOptions(options);
31
46
  return {
32
47
  getInstalledPlugins: async ()=>{
33
- const pluginsResponse = await fetch(`${baseURL ? baseURL : ''}/api/v1/plugins`);
48
+ const pluginsResponse = await fetch(pluginsApiPath);
34
49
  const plugins = await pluginsResponse.json();
35
50
  let pluginModules = [];
36
51
  if (Array.isArray(plugins)) {
@@ -47,7 +62,7 @@ const remotePluginLoader = (baseURL)=>{
47
62
  const pluginModuleName = resource.metadata.name;
48
63
  const pluginModule = {};
49
64
  for (const plugin of resource.spec.plugins){
50
- const remotePluginModule = await (0, _PluginRuntime.loadPlugin)(pluginModuleName, plugin.spec.name);
65
+ const remotePluginModule = await (0, _PluginRuntime.loadPlugin)(pluginModuleName, plugin.spec.name, pluginsAssetsPath);
51
66
  const remotePlugin = remotePluginModule?.[plugin.spec.name];
52
67
  if (remotePlugin) {
53
68
  pluginModule[plugin.spec.name] = remotePlugin;
@@ -58,4 +73,4 @@ const remotePluginLoader = (baseURL)=>{
58
73
  return pluginModule;
59
74
  }
60
75
  };
61
- };
76
+ }
@@ -70,7 +70,7 @@ const useUsageMetrics = ()=>{
70
70
  };
71
71
  };
72
72
  const submitMetrics = async (stats)=>{
73
- await (0, _core.fetch)('/api/v1/view', {
73
+ await (0, _core.fetch)(`${stats.apiPrefix ?? ''}/api/v1/view`, {
74
74
  method: 'POST',
75
75
  headers: {
76
76
  'Content-Type': 'application/json'
@@ -83,14 +83,15 @@ const submitMetrics = async (stats)=>{
83
83
  })
84
84
  });
85
85
  };
86
- const UsageMetricsProvider = ({ project, dashboard, children })=>{
86
+ const UsageMetricsProvider = ({ apiPrefix, project, dashboard, children })=>{
87
87
  const ctx = {
88
88
  project: project,
89
89
  dashboard: dashboard,
90
90
  renderErrorCount: 0,
91
91
  startRenderTime: Date.now(),
92
92
  renderDurationMs: 0,
93
- pendingQueries: new Map()
93
+ pendingQueries: new Map(),
94
+ apiPrefix
94
95
  };
95
96
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(UsageMetricsContext.Provider, {
96
97
  value: ctx,
@@ -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
  };
@@ -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
+ };
@@ -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 = {