@perses-dev/plugin-system 0.27.0 → 0.28.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 (104) hide show
  1. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +75 -0
  2. package/dist/cjs/components/PanelSpecEditor/index.js +28 -0
  3. package/dist/cjs/components/PluginEditor/PluginEditor.js +2 -2
  4. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +27 -6
  5. package/dist/cjs/components/{PluginKindSelect.js → PluginKindSelect/PluginKindSelect.js} +1 -1
  6. package/dist/cjs/components/PluginKindSelect/index.js +28 -0
  7. package/dist/cjs/components/{PluginSpecEditor.js → PluginSpecEditor/PluginSpecEditor.js} +2 -30
  8. package/dist/cjs/components/PluginSpecEditor/index.js +28 -0
  9. package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +142 -0
  10. package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js +94 -0
  11. package/dist/cjs/components/TimeSeriesQueryEditor/index.js +28 -0
  12. package/dist/cjs/components/index.js +1 -0
  13. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +88 -0
  14. package/dist/cjs/runtime/DataQueriesProvider/index.js +29 -0
  15. package/dist/cjs/runtime/DataQueriesProvider/model.js +16 -0
  16. package/dist/cjs/runtime/index.js +1 -0
  17. package/dist/cjs/test/test-plugins/bert/index.js +27 -20
  18. package/dist/cjs/test/test-plugins/ernie/index.js +37 -4
  19. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts +10 -0
  20. package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -0
  21. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +69 -0
  22. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -0
  23. package/dist/components/PanelSpecEditor/index.d.ts +2 -0
  24. package/dist/components/PanelSpecEditor/index.d.ts.map +1 -0
  25. package/dist/components/PanelSpecEditor/index.js +15 -0
  26. package/dist/components/PanelSpecEditor/index.js.map +1 -0
  27. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
  28. package/dist/components/PluginEditor/PluginEditor.js +2 -2
  29. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  30. package/dist/components/PluginEditor/plugin-editor-api.d.ts +4 -1
  31. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
  32. package/dist/components/PluginEditor/plugin-editor-api.js +27 -6
  33. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  34. package/dist/components/{PluginKindSelect.d.ts → PluginKindSelect/PluginKindSelect.d.ts} +1 -1
  35. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -0
  36. package/dist/components/{PluginKindSelect.js → PluginKindSelect/PluginKindSelect.js} +1 -1
  37. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -0
  38. package/dist/components/PluginKindSelect/index.d.ts +2 -0
  39. package/dist/components/PluginKindSelect/index.d.ts.map +1 -0
  40. package/dist/components/PluginKindSelect/index.js +15 -0
  41. package/dist/components/PluginKindSelect/index.js.map +1 -0
  42. package/dist/components/{PluginSpecEditor.d.ts → PluginSpecEditor/PluginSpecEditor.d.ts} +1 -1
  43. package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -0
  44. package/dist/components/{PluginSpecEditor.js → PluginSpecEditor/PluginSpecEditor.js} +3 -31
  45. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -0
  46. package/dist/components/PluginSpecEditor/index.d.ts +2 -0
  47. package/dist/components/PluginSpecEditor/index.d.ts.map +1 -0
  48. package/dist/components/PluginSpecEditor/index.js +15 -0
  49. package/dist/components/PluginSpecEditor/index.js.map +1 -0
  50. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts +8 -0
  51. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.d.ts.map +1 -0
  52. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +131 -0
  53. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +1 -0
  54. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts +13 -0
  55. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.d.ts.map +1 -0
  56. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js +83 -0
  57. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js.map +1 -0
  58. package/dist/components/TimeSeriesQueryEditor/index.d.ts +2 -0
  59. package/dist/components/TimeSeriesQueryEditor/index.d.ts.map +1 -0
  60. package/dist/components/TimeSeriesQueryEditor/index.js +15 -0
  61. package/dist/components/TimeSeriesQueryEditor/index.js.map +1 -0
  62. package/dist/components/index.d.ts +1 -0
  63. package/dist/components/index.d.ts.map +1 -1
  64. package/dist/components/index.js +1 -0
  65. package/dist/components/index.js.map +1 -1
  66. package/dist/model/panels.d.ts +6 -5
  67. package/dist/model/panels.d.ts.map +1 -1
  68. package/dist/model/panels.js.map +1 -1
  69. package/dist/model/plugin-base.d.ts +7 -0
  70. package/dist/model/plugin-base.d.ts.map +1 -1
  71. package/dist/model/plugin-base.js.map +1 -1
  72. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts +8 -0
  73. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -0
  74. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +74 -0
  75. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -0
  76. package/dist/runtime/DataQueriesProvider/index.d.ts +3 -0
  77. package/dist/runtime/DataQueriesProvider/index.d.ts.map +1 -0
  78. package/dist/runtime/DataQueriesProvider/index.js +16 -0
  79. package/dist/runtime/DataQueriesProvider/index.js.map +1 -0
  80. package/dist/runtime/DataQueriesProvider/model.d.ts +27 -0
  81. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -0
  82. package/dist/runtime/DataQueriesProvider/model.js +15 -0
  83. package/dist/runtime/DataQueriesProvider/model.js.map +1 -0
  84. package/dist/runtime/index.d.ts +1 -0
  85. package/dist/runtime/index.d.ts.map +1 -1
  86. package/dist/runtime/index.js +1 -0
  87. package/dist/runtime/index.js.map +1 -1
  88. package/dist/test/test-plugins/bert/index.d.ts.map +1 -1
  89. package/dist/test/test-plugins/bert/index.js +27 -20
  90. package/dist/test/test-plugins/bert/index.js.map +1 -1
  91. package/dist/test/test-plugins/ernie/index.d.ts +4 -1
  92. package/dist/test/test-plugins/ernie/index.d.ts.map +1 -1
  93. package/dist/test/test-plugins/ernie/index.js +28 -1
  94. package/dist/test/test-plugins/ernie/index.js.map +1 -1
  95. package/package.json +3 -3
  96. package/dist/cjs/components/TimeSeriesQueryEditor.js +0 -42
  97. package/dist/components/PluginKindSelect.d.ts.map +0 -1
  98. package/dist/components/PluginKindSelect.js.map +0 -1
  99. package/dist/components/PluginSpecEditor.d.ts.map +0 -1
  100. package/dist/components/PluginSpecEditor.js.map +0 -1
  101. package/dist/components/TimeSeriesQueryEditor.d.ts +0 -14
  102. package/dist/components/TimeSeriesQueryEditor.d.ts.map +0 -1
  103. package/dist/components/TimeSeriesQueryEditor.js +0 -38
  104. package/dist/components/TimeSeriesQueryEditor.js.map +0 -1
@@ -0,0 +1,75 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "PanelSpecEditor", {
18
+ enumerable: true,
19
+ get: ()=>PanelSpecEditor
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _components = require("@perses-dev/components");
23
+ const _runtime = require("../../runtime");
24
+ const _optionsEditorTabs = require("../OptionsEditorTabs");
25
+ const _timeSeriesQueryEditor = require("../TimeSeriesQueryEditor");
26
+ function PanelSpecEditor(props) {
27
+ const { panelDefinition , onJSONChange , onQueriesChange , onPluginSpecChange } = props;
28
+ const { kind } = panelDefinition.spec.plugin;
29
+ const { data: plugin , isLoading , error } = (0, _runtime.usePlugin)('Panel', kind);
30
+ if (error) {
31
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorAlert, {
32
+ error: error
33
+ });
34
+ }
35
+ // TODO: Proper loading indicator
36
+ if (isLoading) {
37
+ return null;
38
+ }
39
+ if (plugin === undefined) {
40
+ throw new Error(`Missing implementation for panel plugin with kind '${kind}'`);
41
+ }
42
+ const { panelOptionsEditorComponents , hideQueryEditor } = plugin;
43
+ let tabs = [];
44
+ if (!hideQueryEditor) {
45
+ var _queries;
46
+ // Since we only support TimeSeriesQuery for now, we will always show a TimeSeriesQueryEditor
47
+ tabs.push({
48
+ label: 'Query',
49
+ content: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeSeriesQueryEditor.TimeSeriesQueryEditor, {
50
+ queries: (_queries = panelDefinition.spec.queries) !== null && _queries !== void 0 ? _queries : [],
51
+ onChange: onQueriesChange
52
+ })
53
+ });
54
+ }
55
+ if (panelOptionsEditorComponents !== undefined) {
56
+ tabs = tabs.concat(panelOptionsEditorComponents.map(({ label , content: OptionsEditorComponent })=>({
57
+ label,
58
+ content: /*#__PURE__*/ (0, _jsxRuntime.jsx)(OptionsEditorComponent, {
59
+ value: panelDefinition.spec.plugin.spec,
60
+ onChange: onPluginSpecChange
61
+ })
62
+ })));
63
+ }
64
+ // always show json editor by default
65
+ tabs.push({
66
+ label: 'JSON',
67
+ content: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.JSONEditor, {
68
+ value: panelDefinition,
69
+ onChange: onJSONChange
70
+ })
71
+ });
72
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorTabs.OptionsEditorTabs, {
73
+ tabs: tabs
74
+ }, tabs.length);
75
+ }
@@ -0,0 +1,28 @@
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
+ _exportStar(require("./PanelSpecEditor"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -20,8 +20,8 @@ Object.defineProperty(exports, "PluginEditor", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
- const _pluginKindSelect = require("../PluginKindSelect");
24
- const _pluginSpecEditor = require("../PluginSpecEditor");
23
+ const _pluginKindSelect = require("../PluginKindSelect/PluginKindSelect");
24
+ const _pluginSpecEditor = require("../PluginSpecEditor/PluginSpecEditor");
25
25
  const _pluginEditorApi = require("./plugin-editor-api");
26
26
  function PluginEditor(props) {
27
27
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -23,9 +23,11 @@ const _react = require("react");
23
23
  const _immer = require("immer");
24
24
  const _runtime = require("../../runtime");
25
25
  function usePluginEditor(props) {
26
- const { pluginType , value } = props;
26
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
27
+ const { pluginType , value , onHideQueryEditorChange =()=>{} } = props; // setting onHideQueryEditorChange to empty function here because useEvent requires a function
27
28
  // Keep a stable reference so we don't run the effect below when we don't need to
28
29
  const onChange = (0, _core.useEvent)(props.onChange);
30
+ const onHideQuery = (0, _core.useEvent)(onHideQueryEditorChange);
29
31
  // The previous spec state for PluginType and kind and a helper function for remembering current values
30
32
  const prevSpecState = (0, _react.useRef)({
31
33
  [pluginType]: {
@@ -40,6 +42,10 @@ function usePluginEditor(props) {
40
42
  }
41
43
  byPluginType[value.kind] = value.spec;
42
44
  });
45
+ // The previous hide query state for each panel kind
46
+ const hideQueryState = (0, _react.useRef)({
47
+ [value.kind]: false
48
+ });
43
49
  const { defaultPluginKinds } = (0, _runtime.usePluginRegistry)();
44
50
  const defaultPluginKind = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[pluginType];
45
51
  const initPendingKind = !value.kind && defaultPluginKind ? defaultPluginKind : '';
@@ -58,12 +64,23 @@ function usePluginEditor(props) {
58
64
  kind: pendingKind,
59
65
  spec: plugin.createInitialOptions()
60
66
  });
67
+ if (pluginType === 'Panel') {
68
+ const panelPlugin = plugin;
69
+ hideQueryState.current[pendingKind] = !!panelPlugin.hideQueryEditor;
70
+ if (!!panelPlugin.hideQueryEditor !== hideQueryState.current[value.kind]) {
71
+ onHideQuery(!!panelPlugin.hideQueryEditor);
72
+ }
73
+ }
61
74
  setPendingKind('');
62
75
  }, [
63
76
  pendingKind,
64
77
  plugin,
65
78
  rememberCurrentSpecState,
66
- onChange
79
+ onChange,
80
+ onHideQuery,
81
+ hideQueryState,
82
+ pluginType,
83
+ value.kind
67
84
  ]);
68
85
  /**
69
86
  * When the user tries to change the plugin kind, make sure we have the correct spec for that plugin kind before we
@@ -79,10 +96,13 @@ function usePluginEditor(props) {
79
96
  kind: nextKind,
80
97
  spec: previousState
81
98
  });
82
- return;
99
+ } else {
100
+ // Otherwise, kick off the async loading process
101
+ setPendingKind(nextKind);
102
+ }
103
+ if (pluginType === 'Panel' && hideQueryState.current[nextKind] !== undefined && hideQueryState.current[value.kind] !== hideQueryState.current[nextKind]) {
104
+ onHideQuery(!!hideQueryState.current[nextKind]);
83
105
  }
84
- // Otherwise, kick off the async loading process
85
- setPendingKind(nextKind);
86
106
  };
87
107
  /**
88
108
  * Spec changes are independent and always just set the spec state.
@@ -96,6 +116,7 @@ function usePluginEditor(props) {
96
116
  isLoading: isFetching,
97
117
  error,
98
118
  onKindChange,
99
- onSpecChange
119
+ onSpecChange,
120
+ rememberCurrentSpecState
100
121
  };
101
122
  }
@@ -20,7 +20,7 @@ Object.defineProperty(exports, "PluginKindSelect", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
- const _runtime = require("../runtime");
23
+ const _runtime = require("../../runtime");
24
24
  function PluginKindSelect(props) {
25
25
  const { pluginType , value: propValue , ...others } = props;
26
26
  const { data , isLoading } = (0, _runtime.useListPluginMetadata)(pluginType);
@@ -0,0 +1,28 @@
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
+ _exportStar(require("./PluginKindSelect"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -20,8 +20,7 @@ Object.defineProperty(exports, "PluginSpecEditor", {
20
20
  });
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _components = require("@perses-dev/components");
23
- const _runtime = require("../runtime");
24
- const _optionsEditorTabs = require("./OptionsEditorTabs");
23
+ const _runtime = require("../../runtime");
25
24
  function PluginSpecEditor(props) {
26
25
  const { pluginType , pluginKind , ...others } = props;
27
26
  const { data: plugin , isLoading , error } = (0, _runtime.usePlugin)(pluginType, pluginKind);
@@ -38,34 +37,7 @@ function PluginSpecEditor(props) {
38
37
  throw new Error(`Missing implementation for ${pluginType} plugin with kind '${pluginKind}'`);
39
38
  }
40
39
  if (pluginType === 'Panel') {
41
- const { PanelQueryEditorComponent , panelOptionsEditorComponents } = plugin;
42
- let tabs = [];
43
- if (PanelQueryEditorComponent !== undefined) {
44
- tabs.push({
45
- label: 'Query',
46
- content: /*#__PURE__*/ (0, _jsxRuntime.jsx)(PanelQueryEditorComponent, {
47
- ...others
48
- })
49
- });
50
- }
51
- if (panelOptionsEditorComponents !== undefined) {
52
- tabs = tabs.concat(panelOptionsEditorComponents.map(({ label , content: OptionsEditorComponent })=>({
53
- label,
54
- content: /*#__PURE__*/ (0, _jsxRuntime.jsx)(OptionsEditorComponent, {
55
- ...others
56
- })
57
- })));
58
- }
59
- // always show json editor by default
60
- tabs.push({
61
- label: 'JSON',
62
- content: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.JSONEditor, {
63
- ...others
64
- })
65
- });
66
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_optionsEditorTabs.OptionsEditorTabs, {
67
- tabs: tabs
68
- });
40
+ throw new Error('This editor should not be used for panel type. Please use Panel Spec Editor instead.');
69
41
  }
70
42
  const { OptionsEditorComponent } = plugin;
71
43
  if (OptionsEditorComponent !== undefined) {
@@ -0,0 +1,28 @@
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
+ _exportStar(require("./PluginSpecEditor"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -0,0 +1,142 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TimeSeriesQueryEditor", {
18
+ enumerable: true,
19
+ get: ()=>TimeSeriesQueryEditor
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _immer = require("immer");
24
+ const _material = require("@mui/material");
25
+ const _plus = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Plus"));
26
+ const _runtime = require("../../runtime");
27
+ const _timeSeriesQueryInput = require("./TimeSeriesQueryInput");
28
+ function _interopRequireDefault(obj) {
29
+ return obj && obj.__esModule ? obj : {
30
+ default: obj
31
+ };
32
+ }
33
+ const DEFAULT_QUERY_PLUGIN_TYPE = 'TimeSeriesQuery';
34
+ function TimeSeriesQueryEditor({ queries =[] , onChange }) {
35
+ const hasMoreThanOneQuery = queries.length > 1;
36
+ const { defaultPluginKinds } = (0, _runtime.usePluginRegistry)();
37
+ var ref;
38
+ const defaultTimeSeriesQueryKind = (ref = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds[DEFAULT_QUERY_PLUGIN_TYPE]) !== null && ref !== void 0 ? ref : '';
39
+ const { data: defaultQueryPlugin } = (0, _runtime.usePlugin)(DEFAULT_QUERY_PLUGIN_TYPE, defaultTimeSeriesQueryKind, {
40
+ useErrorBoundary: true,
41
+ enabled: true
42
+ });
43
+ // State for which queries are collapsed
44
+ // TODO: Would be easier if we had IDs for queries.
45
+ const [queriesCollapsed, setQueriesCollapsed] = (0, _react.useState)(queries.map(()=>false));
46
+ // Query handlers
47
+ const handleQueryChange = (index, queryDef)=>{
48
+ onChange((0, _immer.produce)(queries, (draft)=>{
49
+ if (draft) {
50
+ draft[index] = queryDef;
51
+ } else {
52
+ draft = [
53
+ queryDef
54
+ ];
55
+ }
56
+ }));
57
+ };
58
+ const handleQueryAdd = ()=>{
59
+ if (!defaultQueryPlugin) return;
60
+ onChange((0, _immer.produce)(queries, (draft)=>{
61
+ const queryDef = {
62
+ kind: DEFAULT_QUERY_PLUGIN_TYPE,
63
+ spec: {
64
+ plugin: {
65
+ kind: defaultTimeSeriesQueryKind,
66
+ spec: defaultQueryPlugin.createInitialOptions()
67
+ }
68
+ }
69
+ };
70
+ if (draft) {
71
+ draft.push(queryDef);
72
+ } else {
73
+ draft = [
74
+ ...queries,
75
+ queryDef
76
+ ];
77
+ }
78
+ }));
79
+ setQueriesCollapsed((queriesCollapsed)=>{
80
+ queriesCollapsed.push(false);
81
+ return [
82
+ ...queriesCollapsed
83
+ ];
84
+ });
85
+ };
86
+ const handleQueryDelete = (index)=>{
87
+ onChange((0, _immer.produce)(queries, (draft)=>{
88
+ draft.splice(index, 1);
89
+ }));
90
+ setQueriesCollapsed((queriesCollapsed)=>{
91
+ queriesCollapsed.splice(index, 1);
92
+ return [
93
+ ...queriesCollapsed
94
+ ];
95
+ });
96
+ };
97
+ const handleQueryCollapseExpand = (index)=>{
98
+ setQueriesCollapsed((queriesCollapsed)=>{
99
+ queriesCollapsed[index] = !queriesCollapsed[index];
100
+ return [
101
+ ...queriesCollapsed
102
+ ];
103
+ });
104
+ };
105
+ var ref1;
106
+ // show one query input if queries is empty
107
+ const queryDefinitions = queries.length ? queries : [
108
+ {
109
+ kind: 'TimeSeriesQuery',
110
+ spec: {
111
+ plugin: {
112
+ kind: (ref1 = defaultPluginKinds === null || defaultPluginKinds === void 0 ? void 0 : defaultPluginKinds['TimeSeriesQuery']) !== null && ref1 !== void 0 ? ref1 : '',
113
+ spec: {
114
+ query: ''
115
+ }
116
+ }
117
+ }
118
+ }
119
+ ];
120
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
121
+ spacing: 1,
122
+ children: [
123
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
124
+ variant: "contained",
125
+ startIcon: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_plus.default, {}),
126
+ sx: {
127
+ marginLeft: 'auto'
128
+ },
129
+ onClick: handleQueryAdd,
130
+ children: "Add Query"
131
+ }),
132
+ queryDefinitions.map((query, i)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeSeriesQueryInput.TimeSeriesQueryInput, {
133
+ index: i,
134
+ query: query,
135
+ isCollapsed: !!queriesCollapsed[i],
136
+ onChange: handleQueryChange,
137
+ onDelete: hasMoreThanOneQuery ? handleQueryDelete : undefined,
138
+ onCollapseExpand: handleQueryCollapseExpand
139
+ }, i))
140
+ ]
141
+ });
142
+ }
@@ -0,0 +1,94 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TimeSeriesQueryInput", {
18
+ enumerable: true,
19
+ get: ()=>TimeSeriesQueryInput
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _immer = /*#__PURE__*/ _interopRequireDefault(require("immer"));
23
+ const _material = require("@mui/material");
24
+ const _deleteOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/DeleteOutline"));
25
+ const _chevronDown = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/ChevronDown"));
26
+ const _chevronRight = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/ChevronRight"));
27
+ const _pluginEditor = require("../PluginEditor");
28
+ function _interopRequireDefault(obj) {
29
+ return obj && obj.__esModule ? obj : {
30
+ default: obj
31
+ };
32
+ }
33
+ const TimeSeriesQueryInput = ({ index , query , isCollapsed , onDelete , onChange , onCollapseExpand })=>{
34
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
35
+ spacing: 1,
36
+ children: [
37
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
38
+ direction: "row",
39
+ alignItems: "center",
40
+ borderBottom: 1,
41
+ borderColor: (theme)=>theme.palette.divider,
42
+ children: [
43
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
44
+ size: "small",
45
+ onClick: ()=>onCollapseExpand(index),
46
+ children: isCollapsed ? /*#__PURE__*/ (0, _jsxRuntime.jsx)(_chevronRight.default, {}) : /*#__PURE__*/ (0, _jsxRuntime.jsx)(_chevronDown.default, {})
47
+ }),
48
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Typography, {
49
+ variant: "overline",
50
+ component: "h4",
51
+ children: [
52
+ "Query ",
53
+ index + 1
54
+ ]
55
+ }),
56
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
57
+ size: "small",
58
+ // Use `visibility` to ensure that the row has the same height when delete button is visible or not visible
59
+ sx: {
60
+ marginLeft: 'auto',
61
+ visibility: `${onDelete ? 'visible' : 'hidden'}`
62
+ },
63
+ onClick: ()=>onDelete && onDelete(index),
64
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_deleteOutline.default, {})
65
+ })
66
+ ]
67
+ }),
68
+ !isCollapsed && /*#__PURE__*/ (0, _jsxRuntime.jsx)(QueryEditor, {
69
+ value: query,
70
+ onChange: (next)=>onChange(index, next)
71
+ })
72
+ ]
73
+ }, index);
74
+ };
75
+ /**
76
+ * Displays an editor for TimeSeriesQueryDefinition objects.
77
+ */ function QueryEditor(props) {
78
+ const { value , onChange , ...others } = props;
79
+ const { spec: { plugin } , } = value;
80
+ const handlePluginChange = (next)=>{
81
+ onChange((0, _immer.default)(value, (draft)=>{
82
+ draft.spec.plugin = next;
83
+ }));
84
+ };
85
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
86
+ ...others,
87
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginEditor.PluginEditor, {
88
+ pluginType: "TimeSeriesQuery",
89
+ pluginKindLabel: "Query Type",
90
+ value: plugin,
91
+ onChange: handlePluginChange
92
+ })
93
+ });
94
+ }
@@ -0,0 +1,28 @@
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
+ _exportStar(require("./TimeSeriesQueryEditor"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -17,6 +17,7 @@ Object.defineProperty(exports, "__esModule", {
17
17
  _exportStar(require("./CalculationSelector"), exports);
18
18
  _exportStar(require("./DatasourceSelect"), exports);
19
19
  _exportStar(require("./OptionsEditorTabs"), exports);
20
+ _exportStar(require("./PanelSpecEditor"), exports);
20
21
  _exportStar(require("./PluginEditor"), exports);
21
22
  _exportStar(require("./PluginKindSelect"), exports);
22
23
  _exportStar(require("./PluginRegistry"), exports);
@@ -0,0 +1,88 @@
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
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ useDataQueries: ()=>useDataQueries,
25
+ DataQueriesContext: ()=>DataQueriesContext,
26
+ useDataQueriesContext: ()=>useDataQueriesContext,
27
+ DataQueriesProvider: ()=>DataQueriesProvider
28
+ });
29
+ const _jsxRuntime = require("react/jsx-runtime");
30
+ const _react = require("react");
31
+ const _timeSeriesQueries = require("../time-series-queries");
32
+ function useDataQueries() {
33
+ const ctx = useDataQueriesContext();
34
+ return ctx;
35
+ }
36
+ const DataQueriesContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
37
+ function useDataQueriesContext() {
38
+ const ctx = (0, _react.useContext)(DataQueriesContext);
39
+ if (ctx === undefined) {
40
+ throw new Error('No DataQueriesContext found. Did you forget a Provider?');
41
+ }
42
+ return ctx;
43
+ }
44
+ function DataQueriesProvider(props) {
45
+ const { definitions , options , children } = props;
46
+ // For now we will map each query plugin definition to TimeSeriesQueryDefinition
47
+ // Later on when we add support for other query types,
48
+ // we will have to map each query maps to the correct QueryDefinition
49
+ const timeSeriesQueries = definitions.map((definition)=>({
50
+ kind: 'TimeSeriesQuery',
51
+ spec: {
52
+ plugin: definition
53
+ }
54
+ }));
55
+ const results = (0, _timeSeriesQueries.useTimeSeriesQueries)(timeSeriesQueries, options);
56
+ const data = results.map(({ data , isFetching , isLoading , refetch , error }, i)=>{
57
+ return {
58
+ definition: definitions[i],
59
+ data,
60
+ isFetching,
61
+ isLoading,
62
+ refetch,
63
+ error
64
+ };
65
+ });
66
+ const refetchAll = (0, _react.useCallback)(()=>{
67
+ results.forEach((result)=>result.refetch());
68
+ }, [
69
+ results
70
+ ]);
71
+ const ctx = (0, _react.useMemo)(()=>{
72
+ return {
73
+ queryResults: data,
74
+ isFetching: results.some((result)=>result.isFetching),
75
+ isLoading: results.some((result)=>result.isLoading),
76
+ refetchAll,
77
+ errors: results.map((result)=>result.error)
78
+ };
79
+ }, [
80
+ data,
81
+ results,
82
+ refetchAll
83
+ ]);
84
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(DataQueriesContext.Provider, {
85
+ value: ctx,
86
+ children: children
87
+ });
88
+ }