@perses-dev/plugin-system 0.0.0-snapshot-time-range-height-80d08fc

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 (242) hide show
  1. package/LICENSE +201 -0
  2. package/dist/cjs/components/CalculationSelector/CalculationSelector.js +52 -0
  3. package/dist/cjs/components/CalculationSelector/CalculationSelector.test.js +65 -0
  4. package/dist/cjs/components/CalculationSelector/index.js +28 -0
  5. package/dist/cjs/components/DatasourceSelect.js +76 -0
  6. package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.js +102 -0
  7. package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.test.js +167 -0
  8. package/dist/cjs/components/OptionsEditorTabs/TabPanel.js +37 -0
  9. package/dist/cjs/components/OptionsEditorTabs/index.js +28 -0
  10. package/dist/cjs/components/PluginEditor/PluginEditor.js +67 -0
  11. package/dist/cjs/components/PluginEditor/PluginEditor.test.js +150 -0
  12. package/dist/cjs/components/PluginEditor/index.js +29 -0
  13. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +101 -0
  14. package/dist/cjs/components/PluginKindSelect.js +41 -0
  15. package/dist/cjs/components/PluginKindSelect.test.js +86 -0
  16. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +85 -0
  17. package/dist/cjs/components/PluginRegistry/PluginRegistry.test.js +144 -0
  18. package/dist/cjs/components/PluginRegistry/index.js +28 -0
  19. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +78 -0
  20. package/dist/cjs/components/PluginSpecEditor.js +43 -0
  21. package/dist/cjs/components/PluginSpecEditor.test.js +70 -0
  22. package/dist/cjs/components/TimeSeriesQueryEditor.js +42 -0
  23. package/dist/cjs/components/index.js +35 -0
  24. package/dist/cjs/index.js +31 -0
  25. package/dist/cjs/model/calculations.js +77 -0
  26. package/dist/cjs/model/datasource.js +16 -0
  27. package/dist/cjs/model/index.js +35 -0
  28. package/dist/cjs/model/panels.js +16 -0
  29. package/dist/cjs/model/plugin-base.js +22 -0
  30. package/dist/cjs/model/plugin-loading.js +38 -0
  31. package/dist/cjs/model/plugins.js +16 -0
  32. package/dist/cjs/model/time-series-queries.js +16 -0
  33. package/dist/cjs/model/variables.js +16 -0
  34. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +118 -0
  35. package/dist/cjs/runtime/TimeRangeProvider/index.js +29 -0
  36. package/dist/cjs/runtime/TimeRangeProvider/query-params.js +161 -0
  37. package/dist/cjs/runtime/datasources.js +44 -0
  38. package/dist/cjs/runtime/index.js +32 -0
  39. package/dist/cjs/runtime/plugin-registry.js +75 -0
  40. package/dist/cjs/runtime/template-variables.js +57 -0
  41. package/dist/cjs/runtime/time-series-queries.js +140 -0
  42. package/dist/cjs/test/index.js +28 -0
  43. package/dist/cjs/test/render.js +52 -0
  44. package/dist/cjs/test/setup-tests.js +20 -0
  45. package/dist/cjs/test/test-plugins/bert/index.js +77 -0
  46. package/dist/cjs/test/test-plugins/ernie/index.js +58 -0
  47. package/dist/cjs/test/test-plugins/index.js +77 -0
  48. package/dist/cjs/test-utils/index.js +28 -0
  49. package/dist/cjs/test-utils/mock-plugin-registry.js +68 -0
  50. package/dist/components/CalculationSelector/CalculationSelector.d.ts +8 -0
  51. package/dist/components/CalculationSelector/CalculationSelector.d.ts.map +1 -0
  52. package/dist/components/CalculationSelector/CalculationSelector.js +46 -0
  53. package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -0
  54. package/dist/components/CalculationSelector/CalculationSelector.test.d.ts +2 -0
  55. package/dist/components/CalculationSelector/CalculationSelector.test.d.ts.map +1 -0
  56. package/dist/components/CalculationSelector/CalculationSelector.test.js +58 -0
  57. package/dist/components/CalculationSelector/CalculationSelector.test.js.map +1 -0
  58. package/dist/components/CalculationSelector/index.d.ts +2 -0
  59. package/dist/components/CalculationSelector/index.d.ts.map +1 -0
  60. package/dist/components/CalculationSelector/index.js +15 -0
  61. package/dist/components/CalculationSelector/index.js.map +1 -0
  62. package/dist/components/DatasourceSelect.d.ts +16 -0
  63. package/dist/components/DatasourceSelect.d.ts.map +1 -0
  64. package/dist/components/DatasourceSelect.js +73 -0
  65. package/dist/components/DatasourceSelect.js.map +1 -0
  66. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.d.ts +34 -0
  67. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.d.ts.map +1 -0
  68. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js +96 -0
  69. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -0
  70. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.d.ts +2 -0
  71. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.d.ts.map +1 -0
  72. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.js +160 -0
  73. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.test.js.map +1 -0
  74. package/dist/components/OptionsEditorTabs/TabPanel.d.ts +9 -0
  75. package/dist/components/OptionsEditorTabs/TabPanel.d.ts.map +1 -0
  76. package/dist/components/OptionsEditorTabs/TabPanel.js +31 -0
  77. package/dist/components/OptionsEditorTabs/TabPanel.js.map +1 -0
  78. package/dist/components/OptionsEditorTabs/index.d.ts +2 -0
  79. package/dist/components/OptionsEditorTabs/index.d.ts.map +1 -0
  80. package/dist/components/OptionsEditorTabs/index.js +15 -0
  81. package/dist/components/OptionsEditorTabs/index.js.map +1 -0
  82. package/dist/components/PluginEditor/PluginEditor.d.ts +12 -0
  83. package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -0
  84. package/dist/components/PluginEditor/PluginEditor.js +68 -0
  85. package/dist/components/PluginEditor/PluginEditor.js.map +1 -0
  86. package/dist/components/PluginEditor/PluginEditor.test.d.ts +2 -0
  87. package/dist/components/PluginEditor/PluginEditor.test.d.ts.map +1 -0
  88. package/dist/components/PluginEditor/PluginEditor.test.js +143 -0
  89. package/dist/components/PluginEditor/PluginEditor.test.js.map +1 -0
  90. package/dist/components/PluginEditor/index.d.ts +3 -0
  91. package/dist/components/PluginEditor/index.d.ts.map +1 -0
  92. package/dist/components/PluginEditor/index.js +16 -0
  93. package/dist/components/PluginEditor/index.js.map +1 -0
  94. package/dist/components/PluginEditor/plugin-editor-api.d.ts +30 -0
  95. package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -0
  96. package/dist/components/PluginEditor/plugin-editor-api.js +100 -0
  97. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -0
  98. package/dist/components/PluginKindSelect.d.ts +12 -0
  99. package/dist/components/PluginKindSelect.d.ts.map +1 -0
  100. package/dist/components/PluginKindSelect.js +38 -0
  101. package/dist/components/PluginKindSelect.js.map +1 -0
  102. package/dist/components/PluginKindSelect.test.d.ts +2 -0
  103. package/dist/components/PluginKindSelect.test.d.ts.map +1 -0
  104. package/dist/components/PluginKindSelect.test.js +79 -0
  105. package/dist/components/PluginKindSelect.test.js.map +1 -0
  106. package/dist/components/PluginRegistry/PluginRegistry.d.ts +13 -0
  107. package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -0
  108. package/dist/components/PluginRegistry/PluginRegistry.js +82 -0
  109. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -0
  110. package/dist/components/PluginRegistry/PluginRegistry.test.d.ts +2 -0
  111. package/dist/components/PluginRegistry/PluginRegistry.test.d.ts.map +1 -0
  112. package/dist/components/PluginRegistry/PluginRegistry.test.js +137 -0
  113. package/dist/components/PluginRegistry/PluginRegistry.test.js.map +1 -0
  114. package/dist/components/PluginRegistry/index.d.ts +2 -0
  115. package/dist/components/PluginRegistry/index.d.ts.map +1 -0
  116. package/dist/components/PluginRegistry/index.js +15 -0
  117. package/dist/components/PluginRegistry/index.js.map +1 -0
  118. package/dist/components/PluginRegistry/plugin-indexes.d.ts +14 -0
  119. package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -0
  120. package/dist/components/PluginRegistry/plugin-indexes.js +70 -0
  121. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -0
  122. package/dist/components/PluginSpecEditor.d.ts +9 -0
  123. package/dist/components/PluginSpecEditor.d.ts.map +1 -0
  124. package/dist/components/PluginSpecEditor.js +37 -0
  125. package/dist/components/PluginSpecEditor.js.map +1 -0
  126. package/dist/components/PluginSpecEditor.test.d.ts +2 -0
  127. package/dist/components/PluginSpecEditor.test.d.ts.map +1 -0
  128. package/dist/components/PluginSpecEditor.test.js +63 -0
  129. package/dist/components/PluginSpecEditor.test.js.map +1 -0
  130. package/dist/components/TimeSeriesQueryEditor.d.ts +14 -0
  131. package/dist/components/TimeSeriesQueryEditor.d.ts.map +1 -0
  132. package/dist/components/TimeSeriesQueryEditor.js +38 -0
  133. package/dist/components/TimeSeriesQueryEditor.js.map +1 -0
  134. package/dist/components/index.d.ts +9 -0
  135. package/dist/components/index.d.ts.map +1 -0
  136. package/dist/components/index.js +22 -0
  137. package/dist/components/index.js.map +1 -0
  138. package/dist/index.d.ts +5 -0
  139. package/dist/index.d.ts.map +1 -0
  140. package/dist/index.js +18 -0
  141. package/dist/index.js.map +1 -0
  142. package/dist/model/calculations.d.ts +21 -0
  143. package/dist/model/calculations.d.ts.map +1 -0
  144. package/dist/model/calculations.js +64 -0
  145. package/dist/model/calculations.js.map +1 -0
  146. package/dist/model/datasource.d.ts +12 -0
  147. package/dist/model/datasource.d.ts.map +1 -0
  148. package/dist/model/datasource.js +15 -0
  149. package/dist/model/datasource.js.map +1 -0
  150. package/dist/model/index.d.ts +9 -0
  151. package/dist/model/index.d.ts.map +1 -0
  152. package/dist/model/index.js +22 -0
  153. package/dist/model/index.js.map +1 -0
  154. package/dist/model/panels.d.ts +20 -0
  155. package/dist/model/panels.d.ts.map +1 -0
  156. package/dist/model/panels.js +15 -0
  157. package/dist/model/panels.js.map +1 -0
  158. package/dist/model/plugin-base.d.ts +22 -0
  159. package/dist/model/plugin-base.d.ts.map +1 -0
  160. package/dist/model/plugin-base.js +15 -0
  161. package/dist/model/plugin-base.js.map +1 -0
  162. package/dist/model/plugin-loading.d.ts +22 -0
  163. package/dist/model/plugin-loading.d.ts.map +1 -0
  164. package/dist/model/plugin-loading.js +35 -0
  165. package/dist/model/plugin-loading.js.map +1 -0
  166. package/dist/model/plugins.d.ts +54 -0
  167. package/dist/model/plugins.d.ts.map +1 -0
  168. package/dist/model/plugins.js +15 -0
  169. package/dist/model/plugins.js.map +1 -0
  170. package/dist/model/time-series-queries.d.ts +42 -0
  171. package/dist/model/time-series-queries.d.ts.map +1 -0
  172. package/dist/model/time-series-queries.js +15 -0
  173. package/dist/model/time-series-queries.js.map +1 -0
  174. package/dist/model/variables.d.ts +35 -0
  175. package/dist/model/variables.d.ts.map +1 -0
  176. package/dist/model/variables.js +15 -0
  177. package/dist/model/variables.js.map +1 -0
  178. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts +25 -0
  179. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -0
  180. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +69 -0
  181. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -0
  182. package/dist/runtime/TimeRangeProvider/index.d.ts +3 -0
  183. package/dist/runtime/TimeRangeProvider/index.d.ts.map +1 -0
  184. package/dist/runtime/TimeRangeProvider/index.js +16 -0
  185. package/dist/runtime/TimeRangeProvider/index.js.map +1 -0
  186. package/dist/runtime/TimeRangeProvider/query-params.d.ts +25 -0
  187. package/dist/runtime/TimeRangeProvider/query-params.d.ts.map +1 -0
  188. package/dist/runtime/TimeRangeProvider/query-params.js +153 -0
  189. package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -0
  190. package/dist/runtime/datasources.d.ts +25 -0
  191. package/dist/runtime/datasources.d.ts.map +1 -0
  192. package/dist/runtime/datasources.js +34 -0
  193. package/dist/runtime/datasources.js.map +1 -0
  194. package/dist/runtime/index.d.ts +6 -0
  195. package/dist/runtime/index.d.ts.map +1 -0
  196. package/dist/runtime/index.js +19 -0
  197. package/dist/runtime/index.js.map +1 -0
  198. package/dist/runtime/plugin-registry.d.ts +32 -0
  199. package/dist/runtime/plugin-registry.d.ts.map +1 -0
  200. package/dist/runtime/plugin-registry.js +69 -0
  201. package/dist/runtime/plugin-registry.js.map +1 -0
  202. package/dist/runtime/template-variables.d.ts +17 -0
  203. package/dist/runtime/template-variables.d.ts.map +1 -0
  204. package/dist/runtime/template-variables.js +44 -0
  205. package/dist/runtime/template-variables.js.map +1 -0
  206. package/dist/runtime/time-series-queries.d.ts +13 -0
  207. package/dist/runtime/time-series-queries.d.ts.map +1 -0
  208. package/dist/runtime/time-series-queries.js +132 -0
  209. package/dist/runtime/time-series-queries.js.map +1 -0
  210. package/dist/test/index.d.ts +2 -0
  211. package/dist/test/index.d.ts.map +1 -0
  212. package/dist/test/index.js +15 -0
  213. package/dist/test/index.js.map +1 -0
  214. package/dist/test/render.d.ts +13 -0
  215. package/dist/test/render.d.ts.map +1 -0
  216. package/dist/test/render.js +49 -0
  217. package/dist/test/render.js.map +1 -0
  218. package/dist/test/setup-tests.d.ts +2 -0
  219. package/dist/test/setup-tests.d.ts.map +1 -0
  220. package/dist/test/setup-tests.js +18 -0
  221. package/dist/test/setup-tests.js.map +1 -0
  222. package/dist/test/test-plugins/bert/index.d.ts +8 -0
  223. package/dist/test/test-plugins/bert/index.d.ts.map +1 -0
  224. package/dist/test/test-plugins/bert/index.js +66 -0
  225. package/dist/test/test-plugins/bert/index.js.map +1 -0
  226. package/dist/test/test-plugins/ernie/index.d.ts +5 -0
  227. package/dist/test/test-plugins/ernie/index.d.ts.map +1 -0
  228. package/dist/test/test-plugins/ernie/index.js +53 -0
  229. package/dist/test/test-plugins/ernie/index.js.map +1 -0
  230. package/dist/test/test-plugins/index.d.ts +6 -0
  231. package/dist/test/test-plugins/index.d.ts.map +1 -0
  232. package/dist/test/test-plugins/index.js +29 -0
  233. package/dist/test/test-plugins/index.js.map +1 -0
  234. package/dist/test-utils/index.d.ts +2 -0
  235. package/dist/test-utils/index.d.ts.map +1 -0
  236. package/dist/test-utils/index.js +15 -0
  237. package/dist/test-utils/index.js.map +1 -0
  238. package/dist/test-utils/mock-plugin-registry.d.ts +20 -0
  239. package/dist/test-utils/mock-plugin-registry.d.ts.map +1 -0
  240. package/dist/test-utils/mock-plugin-registry.js +62 -0
  241. package/dist/test-utils/mock-plugin-registry.js.map +1 -0
  242. package/package.json +45 -0
@@ -0,0 +1,86 @@
1
+ // Copyright 2022 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
+ const _jsxRuntime = require("react/jsx-runtime");
18
+ const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
19
+ const _react = require("@testing-library/react");
20
+ const _test = require("../test");
21
+ const _pluginKindSelect = require("./PluginKindSelect");
22
+ function _interopRequireDefault(obj) {
23
+ return obj && obj.__esModule ? obj : {
24
+ default: obj
25
+ };
26
+ }
27
+ describe('PluginKindSelect', ()=>{
28
+ const renderComponent = (props)=>{
29
+ return (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginKindSelect.PluginKindSelect, {
30
+ ...props
31
+ }));
32
+ };
33
+ // Opens the select and waits for loading to finish (i.e. options to appear)
34
+ const openSelect = async ()=>{
35
+ const select = _react.screen.getByRole('button');
36
+ _userEvent.default.click(select);
37
+ const options = await _react.screen.findAllByRole('option');
38
+ return options;
39
+ };
40
+ it('displays the list of plugins for a plugin type', async ()=>{
41
+ renderComponent({
42
+ pluginType: 'Panel',
43
+ value: ''
44
+ });
45
+ // Open the select and verify the list of options from the test plugin data
46
+ const options = await openSelect();
47
+ expect(options).toHaveLength(2);
48
+ let option = _react.screen.queryByRole('option', {
49
+ name: 'Bert Panel 1'
50
+ });
51
+ expect(option).toBeInTheDocument();
52
+ option = _react.screen.queryByRole('option', {
53
+ name: 'Bert Panel 2'
54
+ });
55
+ expect(option).toBeInTheDocument();
56
+ });
57
+ it('shows the correct selected value', async ()=>{
58
+ renderComponent({
59
+ pluginType: 'Variable',
60
+ value: 'ErnieVariable'
61
+ });
62
+ // Use findByRole to wait for loading to finish and selected value to appear
63
+ const select = await _react.screen.findByRole('button', {
64
+ name: 'Ernie Variable'
65
+ });
66
+ expect(select).toBeInTheDocument();
67
+ });
68
+ it('can select new value', async ()=>{
69
+ let onChangeValue = undefined;
70
+ const onChange = jest.fn((e)=>{
71
+ onChangeValue = e.target.value;
72
+ });
73
+ renderComponent({
74
+ pluginType: 'Variable',
75
+ value: 'ErnieVariable',
76
+ onChange
77
+ });
78
+ await openSelect();
79
+ const newOption = _react.screen.getByRole('option', {
80
+ name: 'Bert Variable'
81
+ });
82
+ _userEvent.default.click(newOption);
83
+ expect(onChange).toHaveBeenCalledTimes(1);
84
+ expect(onChangeValue).toBe('BertVariable');
85
+ });
86
+ });
@@ -0,0 +1,85 @@
1
+ // Copyright 2022 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, "PluginRegistry", {
18
+ enumerable: true,
19
+ get: ()=>PluginRegistry
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _core = require("@perses-dev/core");
23
+ const _react = require("react");
24
+ const _runtime = require("../../runtime");
25
+ const _pluginIndexes = require("./plugin-indexes");
26
+ function PluginRegistry(props) {
27
+ const { pluginLoader: { getInstalledPlugins , importPluginModule } , children , defaultPluginKinds , } = props;
28
+ const getPluginIndexes = (0, _pluginIndexes.usePluginIndexes)(getInstalledPlugins);
29
+ // De-dupe calls to import plugin modules
30
+ const importCache = (0, _react.useRef)(new Map());
31
+ // Do useEvent here since this accesses the importPluginModule prop and we want a stable reference to it for the
32
+ // callback below
33
+ const loadPluginModule = (0, _core.useEvent)((resource)=>{
34
+ let request = importCache.current.get(resource);
35
+ if (request === undefined) {
36
+ request = importPluginModule(resource);
37
+ importCache.current.set(resource, request);
38
+ // Remove failed requests from the cache so they can potentially be retried
39
+ request.catch(()=>importCache.current.delete(resource));
40
+ }
41
+ return request;
42
+ });
43
+ const getPlugin = (0, _react.useCallback)(async (pluginType, kind)=>{
44
+ // Get the indexes of the installed plugins
45
+ const pluginIndexes = await getPluginIndexes();
46
+ // Figure out what module the plugin is in by looking in the index
47
+ const typeAndKindKey = (0, _pluginIndexes.getTypeAndKindKey)(pluginType, kind);
48
+ const resource = pluginIndexes.pluginResourcesByTypeAndKind.get(typeAndKindKey);
49
+ if (resource === undefined) {
50
+ throw new Error(`A ${pluginType} plugin for kind '${kind}' is not installed`);
51
+ }
52
+ // Treat the plugin module as a bunch of named exports that have plugins
53
+ const pluginModule = await loadPluginModule(resource);
54
+ // We currently assume that plugin modules will have named exports that match the kinds they handle
55
+ const plugin = pluginModule[kind];
56
+ if (plugin === undefined) {
57
+ throw new Error(`The ${pluginType} plugin for kind '${kind}' is missing from the ${resource.metadata.name} plugin module`);
58
+ }
59
+ return plugin;
60
+ }, [
61
+ getPluginIndexes,
62
+ loadPluginModule
63
+ ]);
64
+ const listPluginMetadata = (0, _react.useCallback)(async (pluginType)=>{
65
+ const pluginIndexes = await getPluginIndexes();
66
+ var ref;
67
+ return (ref = pluginIndexes.pluginMetadataByType.get(pluginType)) !== null && ref !== void 0 ? ref : [];
68
+ }, [
69
+ getPluginIndexes
70
+ ]);
71
+ // Create the registry's context value and render
72
+ const context = (0, _react.useMemo)(()=>({
73
+ getPlugin,
74
+ listPluginMetadata,
75
+ defaultPluginKinds
76
+ }), [
77
+ getPlugin,
78
+ listPluginMetadata,
79
+ defaultPluginKinds
80
+ ]);
81
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_runtime.PluginRegistryContext.Provider, {
82
+ value: context,
83
+ children: children
84
+ });
85
+ }
@@ -0,0 +1,144 @@
1
+ // Copyright 2022 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
+ const _jsxRuntime = require("react/jsx-runtime");
18
+ const _react = /*#__PURE__*/ _interopRequireDefault(require("react"));
19
+ const _react1 = require("@testing-library/react");
20
+ const _runtime = require("../../runtime");
21
+ const _test = require("../../test");
22
+ function _interopRequireDefault(obj) {
23
+ return obj && obj.__esModule ? obj : {
24
+ default: obj
25
+ };
26
+ }
27
+ describe('PluginRegistry', ()=>{
28
+ const renderPluginRegistry = (children)=>{
29
+ (0, _test.renderWithContext)(children);
30
+ };
31
+ it('can load a plugin that exists', async ()=>{
32
+ renderPluginRegistry(/*#__PURE__*/ (0, _jsxRuntime.jsx)(PluginConsumer, {
33
+ pluginType: "Variable",
34
+ kind: "ErnieVariable"
35
+ }));
36
+ const hasPlugin = await _react1.screen.findByText('Has plugin: true', undefined, {
37
+ timeout: 3000
38
+ });
39
+ expect(hasPlugin).toBeInTheDocument();
40
+ });
41
+ it('errors when plugin is not installed', async ()=>{
42
+ // This plugin is not in the test metadata at all
43
+ renderPluginRegistry(/*#__PURE__*/ (0, _jsxRuntime.jsx)(PluginConsumer, {
44
+ pluginType: "TimeSeriesQuery",
45
+ kind: "NotInstalled"
46
+ }));
47
+ const error = await _react1.screen.findByText(/error:/i);
48
+ expect(error).toBeInTheDocument();
49
+ expect(error).toHaveTextContent(/not installed/i);
50
+ });
51
+ it('errors when plugin is missing from the module', async ()=>{
52
+ // This plugin is in the test metadata, but the code is missing from the module
53
+ renderPluginRegistry(/*#__PURE__*/ (0, _jsxRuntime.jsx)(PluginConsumer, {
54
+ pluginType: "Variable",
55
+ kind: "MissingErnieVariable"
56
+ }));
57
+ const error = await _react1.screen.findByText(/error:/i);
58
+ expect(error).toBeInTheDocument();
59
+ expect(error).toHaveTextContent(/missing/i);
60
+ });
61
+ it('lists metadata for plugin metadata that exists', async ()=>{
62
+ // There should be 3 variable plugins across both test modules
63
+ renderPluginRegistry(/*#__PURE__*/ (0, _jsxRuntime.jsx)(MetadataConsumer, {
64
+ pluginType: "Variable"
65
+ }));
66
+ const table = await _react1.screen.findByRole('table');
67
+ expect(table).toBeInTheDocument();
68
+ const rows = _react1.screen.getAllByRole('row');
69
+ expect(rows).toHaveLength(3);
70
+ });
71
+ it('lists metadata for plugin types with no plugins available', async ()=>{
72
+ // There are no TimeSeriesQuery plugins in any of the test modules
73
+ renderPluginRegistry(/*#__PURE__*/ (0, _jsxRuntime.jsx)(MetadataConsumer, {
74
+ pluginType: "TimeSeriesQuery"
75
+ }));
76
+ const table = await _react1.screen.findByRole('table');
77
+ expect(table).toBeInTheDocument();
78
+ const rows = _react1.screen.queryAllByRole('row');
79
+ expect(rows).toHaveLength(0);
80
+ });
81
+ });
82
+ // A helper component for testing the PluginRegistry by calling usePlugin to load a plugin
83
+ const PluginConsumer = (props)=>{
84
+ const { data: plugin , isLoading , error } = (0, _runtime.usePlugin)(props.pluginType, props.kind);
85
+ if (error) {
86
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
87
+ children: [
88
+ "Error: ",
89
+ error.message
90
+ ]
91
+ });
92
+ }
93
+ if (isLoading) {
94
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
95
+ children: "Loading"
96
+ });
97
+ }
98
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
99
+ children: [
100
+ "Has plugin: ",
101
+ (plugin !== undefined).toString()
102
+ ]
103
+ });
104
+ };
105
+ // A helper component for testing the PluginRegistry metadata APIs by calling useListPluginMetadata
106
+ const MetadataConsumer = (props)=>{
107
+ const { data: pluginMetadata , isLoading , error } = (0, _runtime.useListPluginMetadata)(props.pluginType);
108
+ if (error) {
109
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
110
+ children: [
111
+ "Error: ",
112
+ error.message
113
+ ]
114
+ });
115
+ }
116
+ if (isLoading) {
117
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)("div", {
118
+ children: "Loading"
119
+ });
120
+ }
121
+ if (pluginMetadata === undefined) {
122
+ return null;
123
+ }
124
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)("table", {
125
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)("tbody", {
126
+ children: pluginMetadata.map((item)=>/*#__PURE__*/ (0, _jsxRuntime.jsxs)("tr", {
127
+ children: [
128
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)("td", {
129
+ children: item.pluginType
130
+ }),
131
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)("td", {
132
+ children: item.kind
133
+ }),
134
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)("td", {
135
+ children: item.display.name
136
+ }),
137
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)("td", {
138
+ children: item.display.description
139
+ })
140
+ ]
141
+ }, item.kind))
142
+ })
143
+ });
144
+ };
@@ -0,0 +1,28 @@
1
+ // Copyright 2022 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("./PluginRegistry"), 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,78 @@
1
+ // Copyright 2022 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
+ usePluginIndexes: ()=>usePluginIndexes,
25
+ getTypeAndKindKey: ()=>getTypeAndKindKey
26
+ });
27
+ const _core = require("@perses-dev/core");
28
+ const _react = require("react");
29
+ function usePluginIndexes(getInstalledPlugins) {
30
+ // Creates indexes from the installed plugins data (does useEvent because this accesses the getInstalledPlugins prop
31
+ // and we want a stable reference for the callback below)
32
+ const createPluginIndexes = (0, _core.useEvent)(async ()=>{
33
+ const installedPlugins = await getInstalledPlugins();
34
+ // Create the two indexes from the installed plugins
35
+ const pluginResourcesByTypeAndKind = new Map();
36
+ const pluginMetadataByType = new Map();
37
+ for (const resource of installedPlugins){
38
+ for (const pluginMetadata of resource.spec.plugins){
39
+ const { pluginType , kind } = pluginMetadata;
40
+ // Index the plugin by type and kind to point at the module that contains it
41
+ const key = getTypeAndKindKey(pluginType, kind);
42
+ if (pluginResourcesByTypeAndKind.has(key)) {
43
+ console.warn(`Got more than one ${pluginType} plugin for kind ${kind}`);
44
+ }
45
+ pluginResourcesByTypeAndKind.set(key, resource);
46
+ // Index the metadata by plugin type
47
+ let list = pluginMetadataByType.get(pluginType);
48
+ if (list === undefined) {
49
+ list = [];
50
+ pluginMetadataByType.set(pluginType, list);
51
+ }
52
+ list.push(pluginMetadata);
53
+ }
54
+ }
55
+ return {
56
+ pluginResourcesByTypeAndKind,
57
+ pluginMetadataByType
58
+ };
59
+ });
60
+ // De-dupe creating plugin indexes (i.e. requests to get installed plugins)
61
+ const pluginIndexesCache = (0, _react.useRef)(undefined);
62
+ const getPluginIndexes = (0, _react.useCallback)(()=>{
63
+ let request = pluginIndexesCache.current;
64
+ if (request === undefined) {
65
+ request = createPluginIndexes();
66
+ pluginIndexesCache.current = request;
67
+ // Remove failed requests from the cache so they can potentially be retried
68
+ request.catch(()=>pluginIndexesCache.current === undefined);
69
+ }
70
+ return request;
71
+ }, [
72
+ createPluginIndexes
73
+ ]);
74
+ return getPluginIndexes;
75
+ }
76
+ function getTypeAndKindKey(pluginType, kind) {
77
+ return `${pluginType}:${kind}`;
78
+ }
@@ -0,0 +1,43 @@
1
+ // Copyright 2022 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, "PluginSpecEditor", {
18
+ enumerable: true,
19
+ get: ()=>PluginSpecEditor
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _components = require("@perses-dev/components");
23
+ const _runtime = require("../runtime");
24
+ function PluginSpecEditor(props) {
25
+ const { pluginType , pluginKind , ...others } = props;
26
+ const { data: plugin , isLoading , error } = (0, _runtime.usePlugin)(pluginType, pluginKind);
27
+ if (error) {
28
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorAlert, {
29
+ error: error
30
+ });
31
+ }
32
+ // TODO: Proper loading indicator
33
+ if (isLoading) {
34
+ return null;
35
+ }
36
+ if (plugin === undefined) {
37
+ throw new Error(`Missing OptionsEditorComponent for ${pluginType} plugin with kind '${pluginKind}'`);
38
+ }
39
+ const { OptionsEditorComponent } = plugin;
40
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(OptionsEditorComponent, {
41
+ ...others
42
+ });
43
+ }
@@ -0,0 +1,70 @@
1
+ // Copyright 2022 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
+ const _jsxRuntime = require("react/jsx-runtime");
18
+ const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
19
+ const _react = require("@testing-library/react");
20
+ const _test = require("../test");
21
+ const _pluginSpecEditor = require("./PluginSpecEditor");
22
+ function _interopRequireDefault(obj) {
23
+ return obj && obj.__esModule ? obj : {
24
+ default: obj
25
+ };
26
+ }
27
+ describe('PluginSpecEditor', ()=>{
28
+ const renderComponent = (props)=>{
29
+ (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSpecEditor.PluginSpecEditor, {
30
+ ...props
31
+ }));
32
+ };
33
+ it('shows the options editor component for a plugin', async ()=>{
34
+ renderComponent({
35
+ pluginType: 'Panel',
36
+ pluginKind: 'BertPanel1',
37
+ value: {},
38
+ onChange: jest.fn()
39
+ });
40
+ const editor = await _react.screen.findByLabelText('BertPanel1 editor');
41
+ expect(editor).toBeInTheDocument();
42
+ });
43
+ it('propagates value changes', async ()=>{
44
+ const onChange = jest.fn();
45
+ renderComponent({
46
+ pluginType: 'Panel',
47
+ pluginKind: 'BertPanel1',
48
+ value: {
49
+ option1: 'Option1Value'
50
+ },
51
+ onChange
52
+ });
53
+ const editor = await _react.screen.findByLabelText('BertPanel1 editor');
54
+ expect(editor).toHaveValue('Option1Value');
55
+ _userEvent.default.clear(editor);
56
+ expect(onChange).toHaveBeenCalledWith({
57
+ option1: ''
58
+ });
59
+ });
60
+ it('shows an error if plugin fails to load', async ()=>{
61
+ renderComponent({
62
+ pluginType: 'Variable',
63
+ pluginKind: 'DoesNotExist',
64
+ value: {},
65
+ onChange: jest.fn()
66
+ });
67
+ const errorAlert = await _react.screen.findByRole('alert');
68
+ expect(errorAlert).toHaveTextContent(/doesnotexist/i);
69
+ });
70
+ });
@@ -0,0 +1,42 @@
1
+ // Copyright 2022 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 _material = require("@mui/material");
23
+ const _immer = require("immer");
24
+ const _pluginEditor = require("./PluginEditor");
25
+ function TimeSeriesQueryEditor(props) {
26
+ const { value , onChange , ...others } = props;
27
+ const { spec: { plugin } , } = value;
28
+ const handlePluginChange = (next)=>{
29
+ onChange((0, _immer.produce)(value, (draft)=>{
30
+ draft.spec.plugin = next;
31
+ }));
32
+ };
33
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
34
+ ...others,
35
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginEditor.PluginEditor, {
36
+ pluginType: "TimeSeriesQuery",
37
+ pluginKindLabel: "Query Type",
38
+ value: plugin,
39
+ onChange: handlePluginChange
40
+ })
41
+ });
42
+ }
@@ -0,0 +1,35 @@
1
+ // Copyright 2022 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("./CalculationSelector"), exports);
18
+ _exportStar(require("./DatasourceSelect"), exports);
19
+ _exportStar(require("./OptionsEditorTabs"), exports);
20
+ _exportStar(require("./PluginEditor"), exports);
21
+ _exportStar(require("./PluginKindSelect"), exports);
22
+ _exportStar(require("./PluginRegistry"), exports);
23
+ _exportStar(require("./PluginSpecEditor"), exports);
24
+ _exportStar(require("./TimeSeriesQueryEditor"), exports);
25
+ function _exportStar(from, to) {
26
+ Object.keys(from).forEach(function(k) {
27
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
28
+ enumerable: true,
29
+ get: function() {
30
+ return from[k];
31
+ }
32
+ });
33
+ });
34
+ return from;
35
+ }
@@ -0,0 +1,31 @@
1
+ // Copyright 2022 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("./components"), exports);
18
+ _exportStar(require("./model"), exports);
19
+ _exportStar(require("./runtime"), exports);
20
+ _exportStar(require("./test-utils"), exports);
21
+ function _exportStar(from, to) {
22
+ Object.keys(from).forEach(function(k) {
23
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
24
+ enumerable: true,
25
+ get: function() {
26
+ return from[k];
27
+ }
28
+ });
29
+ });
30
+ return from;
31
+ }