@perses-dev/plugin-system 0.44.0 → 0.45.0-rc0

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 (122) hide show
  1. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +12 -3
  2. package/dist/cjs/components/{TimeSeriesQueryEditor/TimeSeriesQueryEditor.js → MultiQueryEditor/MultiQueryEditor.js} +35 -37
  3. package/dist/cjs/components/{TimeSeriesQueryEditor/TimeSeriesQueryInput.js → MultiQueryEditor/QueryEditorContainer.js} +22 -10
  4. package/dist/cjs/components/{TimeSeriesQueryEditor → MultiQueryEditor}/index.js +2 -2
  5. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +12 -46
  6. package/dist/cjs/components/PluginEditor/PluginEditor.js +6 -7
  7. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +43 -31
  8. package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +25 -5
  9. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +5 -3
  10. package/dist/cjs/components/PluginSpecEditor/PluginSpecEditor.js +1 -1
  11. package/dist/cjs/components/ProjectSelect.js +3 -2
  12. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +192 -0
  13. package/dist/cjs/components/{TraceQueryEditor → TimeRangeControls}/index.js +1 -1
  14. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +16 -4
  15. package/dist/cjs/components/index.js +2 -1
  16. package/dist/cjs/constants/user-interface-text.js +4 -1
  17. package/dist/cjs/runtime/DataQueriesProvider/model.js +6 -2
  18. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +8 -0
  19. package/dist/cjs/runtime/plugin-registry.js +7 -5
  20. package/dist/cjs/validation/resource.js +1 -1
  21. package/dist/cjs/validation/user.js +46 -0
  22. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
  23. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +12 -3
  24. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
  25. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts +16 -0
  26. package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -0
  27. package/dist/components/{TimeSeriesQueryEditor/TimeSeriesQueryEditor.js → MultiQueryEditor/MultiQueryEditor.js} +42 -37
  28. package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -0
  29. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts +28 -0
  30. package/dist/components/MultiQueryEditor/QueryEditorContainer.d.ts.map +1 -0
  31. package/dist/components/{TimeSeriesQueryEditor/TimeSeriesQueryInput.js → MultiQueryEditor/QueryEditorContainer.js} +32 -9
  32. package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -0
  33. package/dist/components/MultiQueryEditor/index.d.ts +2 -0
  34. package/dist/components/MultiQueryEditor/index.d.ts.map +1 -0
  35. package/dist/components/{TimeSeriesQueryEditor → MultiQueryEditor}/index.js +2 -2
  36. package/dist/components/{TraceQueryEditor → MultiQueryEditor}/index.js.map +1 -1
  37. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
  38. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +13 -47
  39. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  40. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  41. package/dist/components/PluginEditor/PluginEditor.js +6 -7
  42. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  43. package/dist/components/PluginEditor/plugin-editor-api.d.ts +15 -9
  44. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  45. package/dist/components/PluginEditor/plugin-editor-api.js +43 -31
  46. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  47. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +10 -4
  48. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
  49. package/dist/components/PluginKindSelect/PluginKindSelect.js +31 -8
  50. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  51. package/dist/components/PluginRegistry/PluginRegistry.js +5 -3
  52. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  53. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts +3 -3
  54. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
  55. package/dist/components/PluginSpecEditor/PluginSpecEditor.js +1 -1
  56. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  57. package/dist/components/ProjectSelect.js +3 -2
  58. package/dist/components/ProjectSelect.js.map +1 -1
  59. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts +13 -0
  60. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -0
  61. package/dist/components/TimeRangeControls/TimeRangeControls.js +168 -0
  62. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
  63. package/dist/components/TimeRangeControls/index.d.ts +2 -0
  64. package/dist/components/TimeRangeControls/index.d.ts.map +1 -0
  65. package/dist/components/{TraceQueryEditor → TimeRangeControls}/index.js +1 -1
  66. package/dist/components/TimeRangeControls/index.js.map +1 -0
  67. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  68. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +16 -4
  69. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  70. package/dist/components/index.d.ts +2 -1
  71. package/dist/components/index.d.ts.map +1 -1
  72. package/dist/components/index.js +2 -1
  73. package/dist/components/index.js.map +1 -1
  74. package/dist/constants/user-interface-text.d.ts +2 -0
  75. package/dist/constants/user-interface-text.d.ts.map +1 -1
  76. package/dist/constants/user-interface-text.js +4 -1
  77. package/dist/constants/user-interface-text.js.map +1 -1
  78. package/dist/model/panels.d.ts +7 -2
  79. package/dist/model/panels.d.ts.map +1 -1
  80. package/dist/model/panels.js.map +1 -1
  81. package/dist/model/plugin-base.d.ts +0 -1
  82. package/dist/model/plugin-base.d.ts.map +1 -1
  83. package/dist/model/plugin-base.js.map +1 -1
  84. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  85. package/dist/runtime/DataQueriesProvider/model.js +6 -2
  86. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  87. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +4 -0
  88. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
  89. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +8 -1
  90. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  91. package/dist/runtime/plugin-registry.d.ts +5 -5
  92. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  93. package/dist/runtime/plugin-registry.js +7 -5
  94. package/dist/runtime/plugin-registry.js.map +1 -1
  95. package/dist/validation/resource.js +1 -1
  96. package/dist/validation/resource.js.map +1 -1
  97. package/dist/validation/user.d.ts +93 -0
  98. package/dist/validation/user.d.ts.map +1 -0
  99. package/dist/validation/user.js +38 -0
  100. package/dist/validation/user.js.map +1 -0
  101. package/package.json +4 -4
  102. package/dist/cjs/components/TraceQueryEditor/TraceQueryEditor.js +0 -143
  103. package/dist/cjs/components/TraceQueryEditor/TraceQueryInput.js +0 -96
  104. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts +0 -7
  105. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts.map +0 -1
  106. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +0 -1
  107. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts +0 -12
  108. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts.map +0 -1
  109. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js.map +0 -1
  110. package/dist/components/TimeSeriesQueryEditor/index.d.ts +0 -2
  111. package/dist/components/TimeSeriesQueryEditor/index.d.ts.map +0 -1
  112. package/dist/components/TimeSeriesQueryEditor/index.js.map +0 -1
  113. package/dist/components/TraceQueryEditor/TraceQueryEditor.d.ts +0 -8
  114. package/dist/components/TraceQueryEditor/TraceQueryEditor.d.ts.map +0 -1
  115. package/dist/components/TraceQueryEditor/TraceQueryEditor.js +0 -130
  116. package/dist/components/TraceQueryEditor/TraceQueryEditor.js.map +0 -1
  117. package/dist/components/TraceQueryEditor/TraceQueryInput.d.ts +0 -12
  118. package/dist/components/TraceQueryEditor/TraceQueryInput.d.ts.map +0 -1
  119. package/dist/components/TraceQueryEditor/TraceQueryInput.js +0 -83
  120. package/dist/components/TraceQueryEditor/TraceQueryInput.js.map +0 -1
  121. package/dist/components/TraceQueryEditor/index.d.ts +0 -2
  122. package/dist/components/TraceQueryEditor/index.d.ts.map +0 -1
@@ -324,13 +324,22 @@ function DatasourceEditorForm(props) {
324
324
  }),
325
325
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginEditor.PluginEditor, {
326
326
  width: "100%",
327
- pluginType: "Datasource",
327
+ pluginTypes: [
328
+ 'Datasource'
329
+ ],
328
330
  pluginKindLabel: "Source",
329
- value: state.spec.plugin,
331
+ value: {
332
+ selection: {
333
+ kind: state.spec.plugin.kind,
334
+ type: 'Datasource'
335
+ },
336
+ spec: state.spec.plugin.spec
337
+ },
330
338
  isReadonly: action === 'read',
331
339
  onChange: (v)=>{
332
340
  setState((draft)=>{
333
- draft.spec.plugin = v;
341
+ draft.spec.plugin.kind = v.selection.kind;
342
+ draft.spec.plugin.spec = v.spec;
334
343
  });
335
344
  }
336
345
  })
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -14,10 +14,10 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "TimeSeriesQueryEditor", {
17
+ Object.defineProperty(exports, "MultiQueryEditor", {
18
18
  enumerable: true,
19
19
  get: function() {
20
- return TimeSeriesQueryEditor;
20
+ return MultiQueryEditor;
21
21
  }
22
22
  });
23
23
  const _jsxruntime = require("react/jsx-runtime");
@@ -26,24 +26,42 @@ const _immer = require("immer");
26
26
  const _material = require("@mui/material");
27
27
  const _Plus = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/Plus"));
28
28
  const _runtime = require("../../runtime");
29
- const _TimeSeriesQueryInput = require("./TimeSeriesQueryInput");
29
+ const _QueryEditorContainer = require("./QueryEditorContainer");
30
30
  function _interop_require_default(obj) {
31
31
  return obj && obj.__esModule ? obj : {
32
32
  default: obj
33
33
  };
34
34
  }
35
- const DEFAULT_QUERY_PLUGIN_TYPE = 'TimeSeriesQuery';
36
- function TimeSeriesQueryEditor({ queries = [], onChange }) {
37
- const hasMoreThanOneQuery = queries.length > 1;
35
+ function useDefaultQueryDefinition(queryTypes) {
36
+ var _queryPlugins_;
37
+ // Build the default query plugin
38
+ // This will be used only if the queries are empty, to open a starting query
39
+ // Firs the default query type
40
+ const defaultQueryType = queryTypes[0];
41
+ // Then the default plugin kind
42
+ // Use as default the plugin kind explicitly set as default or the first in the list
43
+ const { data: queryPlugins } = (0, _runtime.useListPluginMetadata)(queryTypes);
38
44
  const { defaultPluginKinds } = (0, _runtime.usePluginRegistry)();
39
- var _defaultPluginKinds_DEFAULT_QUERY_PLUGIN_TYPE;
40
- const defaultTimeSeriesQueryKind = (_defaultPluginKinds_DEFAULT_QUERY_PLUGIN_TYPE = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[DEFAULT_QUERY_PLUGIN_TYPE]) !== null && _defaultPluginKinds_DEFAULT_QUERY_PLUGIN_TYPE !== void 0 ? _defaultPluginKinds_DEFAULT_QUERY_PLUGIN_TYPE : '';
41
- const { data: defaultQueryPlugin } = (0, _runtime.usePlugin)(DEFAULT_QUERY_PLUGIN_TYPE, defaultTimeSeriesQueryKind, {
45
+ var _defaultPluginKinds_defaultQueryType, _ref;
46
+ const defaultQueryKind = (_ref = (_defaultPluginKinds_defaultQueryType = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[defaultQueryType]) !== null && _defaultPluginKinds_defaultQueryType !== void 0 ? _defaultPluginKinds_defaultQueryType : queryPlugins === null || queryPlugins === void 0 ? void 0 : (_queryPlugins_ = queryPlugins[0]) === null || _queryPlugins_ === void 0 ? void 0 : _queryPlugins_.kind) !== null && _ref !== void 0 ? _ref : '';
47
+ const { data: defaultQueryPlugin } = (0, _runtime.usePlugin)(defaultQueryType, defaultQueryKind, {
42
48
  useErrorBoundary: true,
43
49
  enabled: true
44
50
  });
51
+ // This default query definition is used if no query is provided initially or when we add a new query
52
+ return {
53
+ kind: defaultQueryType,
54
+ spec: {
55
+ plugin: {
56
+ kind: defaultQueryKind,
57
+ spec: (defaultQueryPlugin === null || defaultQueryPlugin === void 0 ? void 0 : defaultQueryPlugin.createInitialOptions()) || {}
58
+ }
59
+ }
60
+ };
61
+ }
62
+ function MultiQueryEditor({ queryTypes, queries = [], onChange }) {
63
+ const defaultInitialQueryDefinition = useDefaultQueryDefinition(queryTypes);
45
64
  // State for which queries are collapsed
46
- // TODO: Would be easier if we had IDs for queries.
47
65
  const [queriesCollapsed, setQueriesCollapsed] = (0, _react.useState)(queries.map(()=>false));
48
66
  // Query handlers
49
67
  const handleQueryChange = (index, queryDef)=>{
@@ -58,23 +76,13 @@ function TimeSeriesQueryEditor({ queries = [], onChange }) {
58
76
  }));
59
77
  };
60
78
  const handleQueryAdd = ()=>{
61
- if (!defaultQueryPlugin) return;
62
79
  onChange((0, _immer.produce)(queries, (draft)=>{
63
- const queryDef = {
64
- kind: DEFAULT_QUERY_PLUGIN_TYPE,
65
- spec: {
66
- plugin: {
67
- kind: defaultTimeSeriesQueryKind,
68
- spec: defaultQueryPlugin.createInitialOptions()
69
- }
70
- }
71
- };
72
80
  if (draft) {
73
- draft.push(queryDef);
81
+ draft.push(defaultInitialQueryDefinition);
74
82
  } else {
75
83
  draft = [
76
84
  ...queries,
77
- queryDef
85
+ defaultInitialQueryDefinition
78
86
  ];
79
87
  }
80
88
  }));
@@ -104,31 +112,21 @@ function TimeSeriesQueryEditor({ queries = [], onChange }) {
104
112
  ];
105
113
  });
106
114
  };
107
- var _defaultPluginKinds_TimeSeriesQuery;
108
115
  // show one query input if queries is empty
109
116
  const queryDefinitions = queries.length ? queries : [
110
- {
111
- kind: 'TimeSeriesQuery',
112
- spec: {
113
- plugin: {
114
- kind: (_defaultPluginKinds_TimeSeriesQuery = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds['TimeSeriesQuery']) !== null && _defaultPluginKinds_TimeSeriesQuery !== void 0 ? _defaultPluginKinds_TimeSeriesQuery : '',
115
- spec: {
116
- query: ''
117
- }
118
- }
119
- }
120
- }
117
+ defaultInitialQueryDefinition
121
118
  ];
122
119
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
123
120
  children: [
124
121
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
125
122
  spacing: 1,
126
- children: queryDefinitions.map((query, i)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_TimeSeriesQueryInput.TimeSeriesQueryInput, {
123
+ children: queryDefinitions.map((query, i)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_QueryEditorContainer.QueryEditorContainer, {
124
+ queryTypes: queryTypes,
127
125
  index: i,
128
126
  query: query,
129
127
  isCollapsed: !!queriesCollapsed[i],
130
128
  onChange: handleQueryChange,
131
- onDelete: hasMoreThanOneQuery ? handleQueryDelete : undefined,
129
+ onDelete: queries.length > 1 ? handleQueryDelete : undefined,
132
130
  onCollapseExpand: handleQueryCollapseExpand
133
131
  }, i))
134
132
  }),
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -14,10 +14,10 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "TimeSeriesQueryInput", {
17
+ Object.defineProperty(exports, "QueryEditorContainer", {
18
18
  enumerable: true,
19
19
  get: function() {
20
- return TimeSeriesQueryInput;
20
+ return QueryEditorContainer;
21
21
  }
22
22
  });
23
23
  const _jsxruntime = require("react/jsx-runtime");
@@ -32,7 +32,7 @@ function _interop_require_default(obj) {
32
32
  default: obj
33
33
  };
34
34
  }
35
- const TimeSeriesQueryInput = ({ index, query, isCollapsed, onDelete, onChange, onCollapseExpand })=>{
35
+ const QueryEditorContainer = ({ queryTypes, index, query, isCollapsed, onDelete, onChange, onCollapseExpand })=>{
36
36
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
37
37
  spacing: 1,
38
38
  children: [
@@ -68,6 +68,7 @@ const TimeSeriesQueryInput = ({ index, query, isCollapsed, onDelete, onChange, o
68
68
  ]
69
69
  }),
70
70
  !isCollapsed && /*#__PURE__*/ (0, _jsxruntime.jsx)(QueryEditor, {
71
+ queryTypes: queryTypes,
71
72
  value: query,
72
73
  onChange: (next)=>onChange(index, next)
73
74
  })
@@ -75,21 +76,32 @@ const TimeSeriesQueryInput = ({ index, query, isCollapsed, onDelete, onChange, o
75
76
  }, index);
76
77
  };
77
78
  /**
78
- * Displays an editor for TimeSeriesQueryDefinition objects.
79
+ * Editor for a query definition. This component is responsible for rendering the plugin editor for the given query.
80
+ * This will allow user to select a plugin extending from the given supported query types, and then edit the plugin
81
+ * spec for this plugin.
82
+ * @param props
83
+ * @constructor
79
84
  */ function QueryEditor(props) {
80
- const { value, onChange, ...others } = props;
81
- const { spec: { plugin } } = value;
85
+ const { value, onChange, queryTypes, ...others } = props;
82
86
  const handlePluginChange = (next)=>{
83
87
  onChange((0, _immer.default)(value, (draft)=>{
84
- draft.spec.plugin = next;
88
+ draft.kind = next.selection.type;
89
+ draft.spec.plugin.kind = next.selection.kind;
90
+ draft.spec.plugin.spec = next.spec;
85
91
  }));
86
92
  };
87
93
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
88
94
  ...others,
89
95
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginEditor.PluginEditor, {
90
- pluginType: "TimeSeriesQuery",
96
+ pluginTypes: queryTypes,
91
97
  pluginKindLabel: "Query Type",
92
- value: plugin,
98
+ value: {
99
+ selection: {
100
+ kind: value.spec.plugin.kind,
101
+ type: value.kind
102
+ },
103
+ spec: value.spec.plugin.spec
104
+ },
93
105
  onChange: handlePluginChange
94
106
  })
95
107
  });
@@ -1,4 +1,4 @@
1
- // Copyright 2023 The Perses Authors
1
+ // Copyright 2024 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -14,7 +14,7 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _export_star(require("./TimeSeriesQueryEditor"), exports);
17
+ _export_star(require("./MultiQueryEditor"), exports);
18
18
  function _export_star(from, to) {
19
19
  Object.keys(from).forEach(function(k) {
20
20
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -24,8 +24,7 @@ const _jsxruntime = require("react/jsx-runtime");
24
24
  const _components = require("@perses-dev/components");
25
25
  const _runtime = require("../../runtime");
26
26
  const _OptionsEditorTabs = require("../OptionsEditorTabs");
27
- const _TimeSeriesQueryEditor = require("../TimeSeriesQueryEditor");
28
- const _TraceQueryEditor = require("../TraceQueryEditor");
27
+ const _MultiQueryEditor = require("../MultiQueryEditor");
29
28
  function PanelSpecEditor(props) {
30
29
  const { panelDefinition, onJSONChange, onQueriesChange, onPluginSpecChange } = props;
31
30
  const { kind } = panelDefinition.spec.plugin;
@@ -42,54 +41,17 @@ function PanelSpecEditor(props) {
42
41
  if (plugin === undefined) {
43
42
  throw new Error(`Missing implementation for panel plugin with kind '${kind}'`);
44
43
  }
45
- const getQueryType = ()=>{
46
- var _panelDefinition_spec, _queriesList_;
47
- const queriesList = panelDefinition === null || panelDefinition === void 0 ? void 0 : (_panelDefinition_spec = panelDefinition.spec) === null || _panelDefinition_spec === void 0 ? void 0 : _panelDefinition_spec.queries;
48
- if (queriesList === undefined) {
49
- return '';
50
- }
51
- const queryType = (_queriesList_ = queriesList[0]) === null || _queriesList_ === void 0 ? void 0 : _queriesList_.kind;
52
- return queryType;
53
- };
54
- // Get the corresponding queryEditor depending on the queryType
55
- const getQueryEditorComponent = ()=>{
56
- const queryType = getQueryType();
57
- // default case handles cause where there is no queryType yet (e.g. UI > 'editing' mode > 'Add Panel')
58
- switch(queryType){
59
- case 'TimeSeriesQuery':
60
- var _panelDefinition_spec_queries;
61
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TimeSeriesQueryEditor.TimeSeriesQueryEditor, {
62
- queries: (_panelDefinition_spec_queries = panelDefinition.spec.queries) !== null && _panelDefinition_spec_queries !== void 0 ? _panelDefinition_spec_queries : [],
63
- onChange: onQueriesChange
64
- });
65
- case 'TraceQuery':
66
- var _panelDefinition_spec_queries1;
67
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TraceQueryEditor.TraceQueryEditor, {
68
- queries: (_panelDefinition_spec_queries1 = panelDefinition.spec.queries) !== null && _panelDefinition_spec_queries1 !== void 0 ? _panelDefinition_spec_queries1 : [],
69
- onChange: onQueriesChange
70
- });
71
- default:
72
- // ScatterChart only handles trace queries for now
73
- if (kind === 'ScatterChart') {
74
- var _panelDefinition_spec_queries2;
75
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TraceQueryEditor.TraceQueryEditor, {
76
- queries: (_panelDefinition_spec_queries2 = panelDefinition.spec.queries) !== null && _panelDefinition_spec_queries2 !== void 0 ? _panelDefinition_spec_queries2 : [],
77
- onChange: onQueriesChange
78
- });
79
- }
80
- var _panelDefinition_spec_queries3;
81
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_TimeSeriesQueryEditor.TimeSeriesQueryEditor, {
82
- queries: (_panelDefinition_spec_queries3 = panelDefinition.spec.queries) !== null && _panelDefinition_spec_queries3 !== void 0 ? _panelDefinition_spec_queries3 : [],
83
- onChange: onQueriesChange
84
- });
85
- }
86
- };
87
44
  const { panelOptionsEditorComponents, hideQueryEditor } = plugin;
88
45
  let tabs = [];
89
46
  if (!hideQueryEditor) {
47
+ var _plugin_supportedQueryTypes, _panelDefinition_spec_queries;
90
48
  tabs.push({
91
49
  label: 'Query',
92
- content: getQueryEditorComponent()
50
+ content: /*#__PURE__*/ (0, _jsxruntime.jsx)(_MultiQueryEditor.MultiQueryEditor, {
51
+ queryTypes: (_plugin_supportedQueryTypes = plugin.supportedQueryTypes) !== null && _plugin_supportedQueryTypes !== void 0 ? _plugin_supportedQueryTypes : [],
52
+ queries: (_panelDefinition_spec_queries = panelDefinition.spec.queries) !== null && _panelDefinition_spec_queries !== void 0 ? _panelDefinition_spec_queries : [],
53
+ onChange: onQueriesChange
54
+ })
93
55
  });
94
56
  }
95
57
  if (panelOptionsEditorComponents !== undefined) {
@@ -101,7 +63,7 @@ function PanelSpecEditor(props) {
101
63
  })
102
64
  })));
103
65
  }
104
- // always show json editor by default
66
+ // always show json editor and links editor by default
105
67
  tabs.push({
106
68
  label: 'JSON',
107
69
  content: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.JSONEditor, {
@@ -110,6 +72,10 @@ function PanelSpecEditor(props) {
110
72
  onChange: onJSONChange
111
73
  })
112
74
  });
75
+ tabs.push({
76
+ label: 'Links',
77
+ content: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.LinksEditor, {})
78
+ });
113
79
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_OptionsEditorTabs.OptionsEditorTabs, {
114
80
  tabs: tabs
115
81
  }, tabs.length);
@@ -27,8 +27,8 @@ const _PluginSpecEditor = require("../PluginSpecEditor");
27
27
  const _plugineditorapi = require("./plugin-editor-api");
28
28
  function PluginEditor(props) {
29
29
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
30
- const { value, pluginType, pluginKindLabel, onChange: _, isReadonly, ...others } = props;
31
- const { pendingKind, isLoading, error, onKindChange, onSpecChange } = (0, _plugineditorapi.usePluginEditor)(props);
30
+ const { value, pluginTypes, pluginKindLabel, onChange: _, isReadonly, ...others } = props;
31
+ const { pendingSelection, isLoading, error, onSelectionChange, onSpecChange } = (0, _plugineditorapi.usePluginEditor)(props);
32
32
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
33
33
  ...others,
34
34
  children: [
@@ -40,19 +40,18 @@ function PluginEditor(props) {
40
40
  },
41
41
  margin: "dense",
42
42
  label: pluginKindLabel,
43
- pluginType: pluginType,
43
+ pluginTypes: pluginTypes,
44
44
  disabled: isLoading,
45
- value: pendingKind !== '' ? pendingKind : value.kind,
45
+ value: pendingSelection ? pendingSelection : value.selection,
46
46
  InputProps: {
47
47
  readOnly: isReadonly
48
48
  },
49
49
  error: !!error,
50
50
  helperText: error === null || error === void 0 ? void 0 : error.message,
51
- onChange: onKindChange
51
+ onChange: onSelectionChange
52
52
  }),
53
53
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginSpecEditor.PluginSpecEditor, {
54
- pluginType: pluginType,
55
- pluginKind: value.kind,
54
+ pluginSelection: value.selection,
56
55
  value: value.spec,
57
56
  onChange: onSpecChange,
58
57
  isReadonly: isReadonly
@@ -26,84 +26,96 @@ const _immer = require("immer");
26
26
  const _runtime = require("../../runtime");
27
27
  function usePluginEditor(props) {
28
28
  // eslint-disable-next-line @typescript-eslint/no-empty-function
29
- const { pluginType, value, onHideQueryEditorChange = ()=>{} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function
30
- // Keep a stable reference so we don't run the effect below when we don't need to
29
+ const { pluginTypes, value, onHideQueryEditorChange = ()=>{} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function
30
+ // Keep a stable reference, so we don't run the effect below when we don't need to
31
31
  const onChange = (0, _core.useEvent)(props.onChange);
32
32
  const onHideQuery = (0, _core.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
- [pluginType]: {
36
- [value.kind]: value.spec
35
+ [value.selection.type]: {
36
+ [value.selection.kind]: value.spec
37
37
  }
38
38
  });
39
39
  const rememberCurrentSpecState = (0, _core.useEvent)(()=>{
40
- let byPluginType = prevSpecState.current[pluginType];
40
+ let byPluginType = prevSpecState.current[value.selection.type];
41
41
  if (byPluginType === undefined) {
42
42
  byPluginType = {};
43
- prevSpecState.current[pluginType] = byPluginType;
43
+ prevSpecState.current[value.selection.type] = byPluginType;
44
44
  }
45
- byPluginType[value.kind] = value.spec;
45
+ byPluginType[value.selection.kind] = value.spec;
46
46
  });
47
47
  // The previous hide query state for each panel kind
48
48
  const hideQueryState = (0, _react.useRef)({
49
- [value.kind]: false
49
+ [value.selection.kind]: false
50
50
  });
51
51
  const { defaultPluginKinds } = (0, _runtime.usePluginRegistry)();
52
- const defaultPluginKind = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[pluginType];
53
- const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';
52
+ const defaultPluginType = pluginTypes[0];
53
+ const defaultPluginKind = defaultPluginType ? defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[defaultPluginType] : undefined;
54
+ const defaultPluginSelection = defaultPluginType && defaultPluginKind ? {
55
+ type: defaultPluginType,
56
+ kind: defaultPluginKind
57
+ } : undefined;
58
+ const initPendingSelection = !value.selection && defaultPluginSelection ? defaultPluginSelection : undefined;
54
59
  // When kind changes and we haven't loaded that plugin before, we will need to enter a "pending" state so that we
55
60
  // can generate proper initial spec values that match the new plugin kind
56
- const [pendingKind, setPendingKind] = (0, _react.useState)(initPendingKind);
57
- const { data: plugin, isFetching, error } = (0, _runtime.usePlugin)(pluginType, pendingKind);
61
+ const [pendingSelection, setPendingSelection] = (0, _react.useState)(initPendingSelection);
62
+ // Take a default kind in case user write explicitly an empty kind in the initial value
63
+ (0, _react.useEffect)(()=>{
64
+ if (value.selection.kind === '') {
65
+ value.selection.kind = defaultPluginKind || '';
66
+ }
67
+ }, [
68
+ value.selection,
69
+ defaultPluginKind
70
+ ]);
71
+ const { data: plugin, isFetching, error } = (0, _runtime.usePlugin)(pendingSelection === null || pendingSelection === void 0 ? void 0 : pendingSelection.type, (pendingSelection === null || pendingSelection === void 0 ? void 0 : pendingSelection.kind) || '');
58
72
  (0, _react.useEffect)(()=>{
59
73
  // Nothing to do if no new plugin kind is pending
60
- if (pendingKind === '') return;
74
+ if (!pendingSelection) return;
61
75
  // Can't get spec value until we have a plugin
62
76
  if (plugin === undefined) return;
63
77
  // Fire an onChange to change to the pending kind with initial values from the plugin
64
78
  rememberCurrentSpecState();
65
79
  onChange({
66
- kind: pendingKind,
80
+ selection: pendingSelection,
67
81
  spec: plugin.createInitialOptions()
68
82
  });
69
- if (pluginType === 'Panel') {
83
+ if (pendingSelection.type === 'Panel') {
70
84
  const panelPlugin = plugin;
71
- hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;
72
- if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {
85
+ hideQueryState.current[pendingSelection.kind] = !!panelPlugin.hideQueryEditor;
86
+ if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.selection.kind]) {
73
87
  onHideQuery(!!panelPlugin.hideQueryEditor);
74
88
  }
75
89
  }
76
- setPendingKind('');
90
+ setPendingSelection(undefined);
77
91
  }, [
78
- pendingKind,
92
+ pendingSelection,
79
93
  plugin,
80
94
  rememberCurrentSpecState,
81
95
  onChange,
82
96
  onHideQuery,
83
97
  hideQueryState,
84
- pluginType,
85
- value.kind
98
+ value.selection
86
99
  ]);
87
100
  /**
88
101
  * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we
89
102
  * make the switch.
90
- */ const onKindChange = (e)=>{
91
- var _prevSpecState_current_pluginType;
92
- const nextKind = e.target.value;
103
+ */ const onSelectionChange = (nextSelection)=>{
104
+ var _prevSpecState_current_nextSelection_type;
93
105
  // If we already have state for this plugin type/kind from a previous selection, just use it
94
- const previousState = (_prevSpecState_current_pluginType = prevSpecState.current[pluginType]) === null || _prevSpecState_current_pluginType === void 0 ? void 0 : _prevSpecState_current_pluginType[nextKind];
106
+ const previousState = (_prevSpecState_current_nextSelection_type = prevSpecState.current[nextSelection.type]) === null || _prevSpecState_current_nextSelection_type === void 0 ? void 0 : _prevSpecState_current_nextSelection_type[nextSelection.kind];
95
107
  if (previousState !== undefined) {
96
108
  rememberCurrentSpecState();
97
109
  onChange({
98
- kind: nextKind,
110
+ selection: nextSelection,
99
111
  spec: previousState
100
112
  });
101
113
  } else {
102
114
  // Otherwise, kick off the async loading process
103
- setPendingKind(nextKind);
115
+ setPendingSelection(nextSelection);
104
116
  }
105
- if (pluginType === 'Panel' && hideQueryState.current[nextKind] !== undefined && hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]) {
106
- onHideQuery(!!hideQueryState.current[nextKind]);
117
+ if (nextSelection.type === 'Panel' && hideQueryState.current[nextSelection.kind] !== undefined && hideQueryState.current[value.selection.kind] !== hideQueryState.current[nextSelection.kind]) {
118
+ onHideQuery(!!hideQueryState.current[nextSelection.kind]);
107
119
  }
108
120
  };
109
121
  /**
@@ -114,10 +126,10 @@ function usePluginEditor(props) {
114
126
  }));
115
127
  };
116
128
  return {
117
- pendingKind,
129
+ pendingSelection,
118
130
  isLoading: isFetching,
119
131
  error,
120
- onKindChange,
132
+ onSelectionChange,
121
133
  onSpecChange,
122
134
  rememberCurrentSpecState
123
135
  };
@@ -25,16 +25,33 @@ 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 { pluginType, value: propValue, ...others } = props;
29
- const { data, isLoading } = (0, _runtime.useListPluginMetadata)(pluginType);
28
+ const { pluginTypes, value: propValue, onChange, ...others } = props;
29
+ const { data, isLoading } = (0, _runtime.useListPluginMetadata)(pluginTypes);
30
30
  // Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
31
- const value = propValue !== '' && isLoading ? '' : propValue;
31
+ const value = propValue && isLoading ? '' : JSON.stringify(propValue);
32
+ const handleChange = (event)=>{
33
+ onChange === null || onChange === void 0 ? void 0 : onChange(JSON.parse(event.target.value));
34
+ };
35
+ const renderValue = (0, _react.useCallback)((selected)=>{
36
+ var _data_find;
37
+ const selectedValue = JSON.parse(selected);
38
+ if (!selectedValue.kind) {
39
+ return '';
40
+ }
41
+ return data === null || data === void 0 ? void 0 : (_data_find = data.find((v)=>v.pluginType === selectedValue.type && v.kind === selectedValue.kind)) === null || _data_find === void 0 ? void 0 : _data_find.display.name;
42
+ }, [
43
+ data
44
+ ]);
32
45
  // TODO: Does this need a loading indicator of some kind?
33
46
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.TextField, {
34
47
  select: true,
35
48
  inputRef: ref,
36
49
  ...others,
37
50
  value: value,
51
+ onChange: handleChange,
52
+ SelectProps: {
53
+ renderValue
54
+ },
38
55
  "data-testid": "plugin-kind-select",
39
56
  children: [
40
57
  isLoading && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
@@ -43,9 +60,12 @@ const PluginKindSelect = /*#__PURE__*/ (0, _react.forwardRef)((props, ref)=>{
43
60
  }),
44
61
  data === null || data === void 0 ? void 0 : data.map((metadata)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
45
62
  "data-testid": "option",
46
- value: metadata.kind,
63
+ value: JSON.stringify({
64
+ type: metadata.pluginType,
65
+ kind: metadata.kind
66
+ }),
47
67
  children: metadata.display.name
48
- }, metadata.kind))
68
+ }, metadata.pluginType + metadata.kind))
49
69
  ]
50
70
  });
51
71
  });
@@ -63,10 +63,12 @@ function PluginRegistry(props) {
63
63
  getPluginIndexes,
64
64
  loadPluginModule
65
65
  ]);
66
- const listPluginMetadata = (0, _react.useCallback)(async (pluginType)=>{
66
+ const listPluginMetadata = (0, _react.useCallback)(async (pluginTypes)=>{
67
67
  const pluginIndexes = await getPluginIndexes();
68
- var _pluginIndexes_pluginMetadataByType_get;
69
- return (_pluginIndexes_pluginMetadataByType_get = pluginIndexes.pluginMetadataByType.get(pluginType)) !== null && _pluginIndexes_pluginMetadataByType_get !== void 0 ? _pluginIndexes_pluginMetadataByType_get : [];
68
+ return pluginTypes.flatMap((type)=>{
69
+ var _pluginIndexes_pluginMetadataByType_get;
70
+ return (_pluginIndexes_pluginMetadataByType_get = pluginIndexes.pluginMetadataByType.get(type)) !== null && _pluginIndexes_pluginMetadataByType_get !== void 0 ? _pluginIndexes_pluginMetadataByType_get : [];
71
+ });
70
72
  }, [
71
73
  getPluginIndexes
72
74
  ]);
@@ -24,7 +24,7 @@ const _jsxruntime = require("react/jsx-runtime");
24
24
  const _components = require("@perses-dev/components");
25
25
  const _runtime = require("../../runtime");
26
26
  function PluginSpecEditor(props) {
27
- const { pluginType, pluginKind, ...others } = props;
27
+ const { pluginSelection: { type: pluginType, kind: pluginKind }, ...others } = props;
28
28
  const { data: plugin, isLoading, error } = (0, _runtime.usePlugin)(pluginType, pluginKind);
29
29
  if (error) {
30
30
  return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorAlert, {
@@ -44,7 +44,7 @@ function ProjectSelect(props) {
44
44
  onChange: handleChange,
45
45
  children: [
46
46
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
47
- value: 'none',
47
+ value: "none",
48
48
  children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
49
49
  direction: "row",
50
50
  alignItems: "center",
@@ -91,6 +91,7 @@ function ProjectSelect(props) {
91
91
  kind: 'Project',
92
92
  metadata: {
93
93
  name: optionValue
94
- }
94
+ },
95
+ spec: {}
95
96
  };
96
97
  }