@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
@@ -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,7 +32,7 @@ function _interop_require_default(obj) {
32
32
  default: obj
33
33
  };
34
34
  }
35
- function useDefaultQueryDefinition(queryTypes) {
35
+ function useDefaultQueryDefinition(queryTypes, filteredQueryPlugins) {
36
36
  // Build the default query plugin
37
37
  // This will be used only if the queries are empty, to open a starting query
38
38
  // Firs the default query type
@@ -41,7 +41,12 @@ function useDefaultQueryDefinition(queryTypes) {
41
41
  // Use as default the plugin kind explicitly set as default or the first in the list
42
42
  const { data: queryPlugins, isLoading } = (0, _runtime.useListPluginMetadata)(queryTypes);
43
43
  const { defaultPluginKinds } = (0, _runtime.usePluginRegistry)();
44
- const defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';
44
+ let defaultQueryKind = '';
45
+ if (filteredQueryPlugins?.length) {
46
+ defaultQueryKind = queryPlugins?.find((i)=>filteredQueryPlugins.includes(i.spec.name)).spec.name ?? '';
47
+ } else {
48
+ defaultQueryKind = defaultPluginKinds?.[defaultQueryType] ?? queryPlugins?.[0]?.spec.name ?? '';
49
+ }
45
50
  const { data: defaultQueryPlugin } = (0, _runtime.usePlugin)(defaultQueryType, defaultQueryKind, {
46
51
  useErrorBoundary: true,
47
52
  enabled: true
@@ -61,8 +66,8 @@ function useDefaultQueryDefinition(queryTypes) {
61
66
  };
62
67
  }
63
68
  const MultiQueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
64
- const { queryTypes, queries = [], onChange } = props;
65
- const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes);
69
+ const { queryTypes, queries = [], filteredQueryPlugins, onChange } = props;
70
+ const { defaultInitialQueryDefinition, isLoading } = useDefaultQueryDefinition(queryTypes, filteredQueryPlugins);
66
71
  // State for which queries are collapsed
67
72
  const [queriesCollapsed, setQueriesCollapsed] = (0, _react.useState)(queries.map(()=>false));
68
73
  // Query handlers
@@ -130,7 +135,8 @@ const MultiQueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
130
135
  isCollapsed: !!queriesCollapsed[i],
131
136
  onChange: handleQueryChange,
132
137
  onDelete: queries.length > 1 ? handleQueryDelete : undefined,
133
- onCollapseExpand: handleQueryCollapseExpand
138
+ onCollapseExpand: handleQueryCollapseExpand,
139
+ filteredQueryPlugins: filteredQueryPlugins
134
140
  }, i))
135
141
  }),
136
142
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
@@ -35,7 +35,7 @@ function _interop_require_default(obj) {
35
35
  };
36
36
  }
37
37
  const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
38
- const { queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
38
+ const { queryTypes, filteredQueryPlugins, index, query, isCollapsed, onDelete, onChange, onCollapseExpand } = props;
39
39
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
40
40
  spacing: 1,
41
41
  children: [
@@ -71,6 +71,7 @@ const QueryEditorContainer = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>
71
71
  ]
72
72
  }),
73
73
  !isCollapsed && /*#__PURE__*/ (0, _jsxruntime.jsx)(QueryEditor, {
74
+ filteredQueryPlugins: filteredQueryPlugins,
74
75
  ref: ref,
75
76
  queryTypes: queryTypes,
76
77
  value: query,
@@ -87,7 +88,7 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
87
88
  * @param props
88
89
  * @constructor
89
90
  */ const QueryEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
90
- const { value, onChange, queryTypes, ...others } = props;
91
+ const { value, onChange, queryTypes, filteredQueryPlugins, ...others } = props;
91
92
  const { refresh } = (0, _runtime.useTimeRange)();
92
93
  const handlePluginChange = (next)=>{
93
94
  onChange((0, _immer.produce)(value, (draft)=>{
@@ -111,7 +112,8 @@ QueryEditorContainer.displayName = 'QueryEditorContainer';
111
112
  },
112
113
  spec: value.spec.plugin.spec
113
114
  },
114
- onChange: handlePluginChange
115
+ onChange: handlePluginChange,
116
+ filteredQueryPlugins: filteredQueryPlugins
115
117
  })
116
118
  });
117
119
  });
@@ -34,7 +34,7 @@ function _interop_require_default(obj) {
34
34
  };
35
35
  }
36
36
  const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
37
- const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, postExecuteRunQuery: refresh, ...others } = props;
37
+ const { value, withRunQueryButton = true, pluginTypes, pluginKindLabel, onChange: _, isReadonly, postExecuteRunQuery: refresh, filteredQueryPlugins, ...others } = props;
38
38
  const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = (0, _plugineditorapi.usePluginEditor)(props);
39
39
  /*
40
40
  We could technically merge the watchedQuery, watchedOtherSpecs into a single watched-object,
@@ -104,7 +104,8 @@ const PluginEditor = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
104
104
  },
105
105
  error: !!error,
106
106
  helperText: error?.message,
107
- onChange: onSelectionChange
107
+ onChange: onSelectionChange,
108
+ filteredQueryPlugins: filteredQueryPlugins
108
109
  }),
109
110
  withRunQueryButton && !isLoading && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
110
111
  "data-testid": "run_query_button",
@@ -20,23 +20,23 @@ Object.defineProperty(exports, "usePluginEditor", {
20
20
  return usePluginEditor;
21
21
  }
22
22
  });
23
- const _core = require("@perses-dev/core");
24
23
  const _react = require("react");
25
24
  const _immer = require("immer");
26
25
  const _runtime = require("../../runtime");
26
+ const _utils = require("../../utils");
27
27
  function usePluginEditor(props) {
28
28
  // eslint-disable-next-line @typescript-eslint/no-empty-function
29
29
  const { pluginTypes, value, onHideQueryEditorChange = ()=>{} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function
30
30
  // Keep a stable reference, so we don't run the effect below when we don't need to
31
- const onChange = (0, _core.useEvent)(props.onChange);
32
- const onHideQuery = (0, _core.useEvent)(onHideQueryEditorChange);
31
+ const onChange = (0, _utils.useEvent)(props.onChange);
32
+ const onHideQuery = (0, _utils.useEvent)(onHideQueryEditorChange);
33
33
  // The previous spec state for PluginType and kind and a helper function for remembering current values
34
34
  const prevSpecState = (0, _react.useRef)({
35
35
  [value.selection.type]: {
36
36
  [value.selection.kind]: value.spec
37
37
  }
38
38
  });
39
- const rememberCurrentSpecState = (0, _core.useEvent)(()=>{
39
+ const rememberCurrentSpecState = (0, _utils.useEvent)(()=>{
40
40
  let byPluginType = prevSpecState.current[value.selection.type];
41
41
  if (byPluginType === undefined) {
42
42
  byPluginType = {};
@@ -25,10 +25,16 @@ const _material = require("@mui/material");
25
25
  const _react = require("react");
26
26
  const _runtime = require("../../runtime");
27
27
  const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
28
- const { pluginTypes, value: propValue, onChange, ...others } = props;
28
+ const { pluginTypes, value: propValue, onChange, filteredQueryPlugins, ...others } = props;
29
29
  const { data, isLoading } = (0, _runtime.useListPluginMetadata)(pluginTypes);
30
- const sortedData = (0, _react.useMemo)(()=>data?.sort((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name)), [
31
- data
30
+ const sortedData = (0, _react.useMemo)(()=>{
31
+ if (filteredQueryPlugins?.length) {
32
+ return data?.filter((i)=>filteredQueryPlugins.includes(i.spec.name))?.sort((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name));
33
+ }
34
+ return data?.sort((a, b)=>a.spec.display.name.localeCompare(b.spec.display.name));
35
+ }, [
36
+ data,
37
+ filteredQueryPlugins
32
38
  ]);
33
39
  // Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
34
40
  const value = !propValue || isLoading ? '' : selectionToOptionValue(propValue);
@@ -21,9 +21,9 @@ Object.defineProperty(exports, "PluginRegistry", {
21
21
  }
22
22
  });
23
23
  const _jsxruntime = require("react/jsx-runtime");
24
- const _core = require("@perses-dev/core");
25
24
  const _react = require("react");
26
25
  const _runtime = require("../../runtime");
26
+ const _utils = require("../../utils");
27
27
  const _pluginindexes = require("./plugin-indexes");
28
28
  function PluginRegistry(props) {
29
29
  const { pluginLoader: { getInstalledPlugins, importPluginModule }, children, defaultPluginKinds } = props;
@@ -32,7 +32,7 @@ function PluginRegistry(props) {
32
32
  const importCache = (0, _react.useRef)(new Map());
33
33
  // Do useEvent here since this accesses the importPluginModule prop and we want a stable reference to it for the
34
34
  // callback below
35
- const loadPluginModule = (0, _core.useEvent)((resource)=>{
35
+ const loadPluginModule = (0, _utils.useEvent)((resource)=>{
36
36
  let request = importCache.current.get(resource);
37
37
  if (request === undefined) {
38
38
  request = importPluginModule(resource);
@@ -28,12 +28,12 @@ _export(exports, {
28
28
  return usePluginIndexes;
29
29
  }
30
30
  });
31
- const _core = require("@perses-dev/core");
32
31
  const _react = require("react");
32
+ const _utils = require("../../utils");
33
33
  function usePluginIndexes(getInstalledPlugins) {
34
34
  // Creates indexes from the installed plugins data (does useEvent because this accesses the getInstalledPlugins prop
35
35
  // and we want a stable reference for the callback below)
36
- const createPluginIndexes = (0, _core.useEvent)(async ()=>{
36
+ const createPluginIndexes = (0, _utils.useEvent)(async ()=>{
37
37
  const installedPlugins = await getInstalledPlugins();
38
38
  // Create the two indexes from the installed plugins
39
39
  const pluginResourcesByNameAndKind = new Map();
@@ -211,7 +211,11 @@ function TimeRangeControls({ heightPx, showTimeRangeSelector = true, showRefresh
211
211
  description: _constants.TOOLTIP_TEXT.refreshInterval,
212
212
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.RefreshIntervalPicker, {
213
213
  timeOptions: DEFAULT_REFRESH_INTERVAL_OPTIONS,
214
- value: refreshInterval,
214
+ value: /* TODO: There is a bug here which should be fixed in a proper way. (This is only a quick remedy)
215
+ display: 1m has the pastDuration of 60s. Initially (if the persisted value is 1m) when the page is loaded, instead of 60s, 1m is passed down.
216
+ This only happens for 1m, because for other items the display and the pastDuration are the same. Example 30s-30s
217
+ HERE The value MUST always be pastDuration, otherwise the component would not work as expected.
218
+ */ DEFAULT_REFRESH_INTERVAL_OPTIONS.some((i)=>i.value.pastDuration === refreshInterval) ? refreshInterval : DEFAULT_REFRESH_INTERVAL_OPTIONS.find((i)=>i.display === refreshInterval)?.value.pastDuration,
215
219
  onChange: handleRefreshIntervalChange,
216
220
  height: height
217
221
  })
@@ -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,