@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,75 @@
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
+ PluginRegistryContext: ()=>PluginRegistryContext,
25
+ usePluginRegistry: ()=>usePluginRegistry,
26
+ usePlugin: ()=>usePlugin,
27
+ usePlugins: ()=>usePlugins,
28
+ useListPluginMetadata: ()=>useListPluginMetadata
29
+ });
30
+ const _react = require("react");
31
+ const _reactQuery = require("@tanstack/react-query");
32
+ const PluginRegistryContext = (0, _react.createContext)(undefined);
33
+ function usePluginRegistry() {
34
+ const ctx = (0, _react.useContext)(PluginRegistryContext);
35
+ if (ctx === undefined) {
36
+ throw new Error('PluginRegistryContext not found. Did you forget a provider?');
37
+ }
38
+ return ctx;
39
+ }
40
+ function usePlugin(pluginType, kind, options) {
41
+ var ref;
42
+ // We never want to ask for a plugin when the kind isn't set yet, so disable those queries automatically
43
+ options = {
44
+ ...options,
45
+ enabled: ((ref = options === null || options === void 0 ? void 0 : options.enabled) !== null && ref !== void 0 ? ref : true) && kind !== ''
46
+ };
47
+ const { getPlugin } = usePluginRegistry();
48
+ return (0, _reactQuery.useQuery)([
49
+ 'getPlugin',
50
+ pluginType,
51
+ kind
52
+ ], ()=>getPlugin(pluginType, kind), options);
53
+ }
54
+ function usePlugins(pluginType, plugins) {
55
+ const { getPlugin } = usePluginRegistry();
56
+ return (0, _reactQuery.useQueries)({
57
+ queries: plugins.map((p)=>{
58
+ return {
59
+ queryKey: [
60
+ 'getPlugin',
61
+ pluginType,
62
+ p.kind
63
+ ],
64
+ queryFn: ()=>getPlugin(pluginType, p.kind)
65
+ };
66
+ })
67
+ });
68
+ }
69
+ function useListPluginMetadata(pluginType, options) {
70
+ const { listPluginMetadata } = usePluginRegistry();
71
+ return (0, _reactQuery.useQuery)([
72
+ 'listPluginMetadata',
73
+ pluginType
74
+ ], ()=>listPluginMetadata(pluginType), options);
75
+ }
@@ -0,0 +1,57 @@
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
+ DEFAULT_ALL_VALUE: ()=>DEFAULT_ALL_VALUE,
25
+ TemplateVariableContext: ()=>TemplateVariableContext,
26
+ useTemplateVariableValues: ()=>useTemplateVariableValues
27
+ });
28
+ const _react = require("react");
29
+ const DEFAULT_ALL_VALUE = '$__all';
30
+ const TemplateVariableContext = (0, _react.createContext)(undefined);
31
+ function useTemplateVariableContext() {
32
+ const ctx = (0, _react.useContext)(TemplateVariableContext);
33
+ if (ctx === undefined) {
34
+ throw new Error('No TemplateVariableContext found. Did you forget a Provider?');
35
+ }
36
+ return ctx;
37
+ }
38
+ function useTemplateVariableValues(names) {
39
+ const { state } = useTemplateVariableContext();
40
+ const values = (0, _react.useMemo)(()=>{
41
+ const values = {};
42
+ names === null || names === void 0 ? void 0 : names.forEach((name)=>{
43
+ const s = state[name];
44
+ if (s) {
45
+ values[name] = s;
46
+ }
47
+ });
48
+ return values;
49
+ }, [
50
+ state,
51
+ names
52
+ ]);
53
+ if (names === undefined) {
54
+ return state;
55
+ }
56
+ return values;
57
+ }
@@ -0,0 +1,140 @@
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
+ useTimeSeriesQuery: ()=>useTimeSeriesQuery,
25
+ useTimeSeriesQueries: ()=>useTimeSeriesQueries
26
+ });
27
+ const _reactQuery = require("@tanstack/react-query");
28
+ const _templateVariables = require("./template-variables");
29
+ const _timeRangeProvider = require("./TimeRangeProvider");
30
+ const _datasources = require("./datasources");
31
+ const _pluginRegistry = require("./plugin-registry");
32
+ /**
33
+ * Returns a serialized string of the current state of variable values.
34
+ */ function getVariableValuesKey(v) {
35
+ return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
36
+ }
37
+ function filterVariableStateMap(v, names) {
38
+ if (!names) {
39
+ return v;
40
+ }
41
+ return Object.fromEntries(Object.entries(v).filter(([name])=>names.includes(name)));
42
+ }
43
+ function getQueryOptions({ plugin , definition , context }) {
44
+ const { timeRange , datasourceStore , suggestedStepMs , variableState , refreshKey } = context;
45
+ const dependencies = (plugin === null || plugin === void 0 ? void 0 : plugin.dependsOn) ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};
46
+ const variableDependencies = dependencies === null || dependencies === void 0 ? void 0 : dependencies.variables;
47
+ // Determine queryKey
48
+ const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);
49
+ const variablesValueKey = getVariableValuesKey(filteredVariabledState);
50
+ const queryKey = [
51
+ definition,
52
+ timeRange,
53
+ datasourceStore,
54
+ suggestedStepMs,
55
+ variablesValueKey,
56
+ refreshKey
57
+ ];
58
+ // Determine queryEnabled
59
+ let waitToLoad = false;
60
+ if (variableDependencies) {
61
+ waitToLoad = variableDependencies.some((v)=>{
62
+ var ref;
63
+ return (ref = variableState[v]) === null || ref === void 0 ? void 0 : ref.loading;
64
+ });
65
+ }
66
+ const queryEnabled = plugin !== undefined && !waitToLoad;
67
+ return {
68
+ queryKey,
69
+ queryEnabled
70
+ };
71
+ }
72
+ const useTimeSeriesQuery = (definition, options)=>{
73
+ const { data: plugin } = (0, _pluginRegistry.usePlugin)('TimeSeriesQuery', definition.spec.plugin.kind);
74
+ const context = useTimeSeriesQueryContext();
75
+ const { queryEnabled , queryKey } = getQueryOptions({
76
+ plugin,
77
+ definition,
78
+ context
79
+ });
80
+ return (0, _reactQuery.useQuery)({
81
+ enabled: queryEnabled,
82
+ queryKey: queryKey,
83
+ queryFn: ()=>{
84
+ // The 'enabled' option should prevent this from happening, but make TypeScript happy by checking
85
+ if (plugin === undefined) {
86
+ throw new Error('Expected plugin to be loaded');
87
+ }
88
+ // Keep options out of query key so we don't re-run queries because suggested step changes
89
+ const ctx = {
90
+ ...context,
91
+ suggestedStepMs: options === null || options === void 0 ? void 0 : options.suggestedStepMs
92
+ };
93
+ return plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
94
+ }
95
+ });
96
+ };
97
+ function useTimeSeriesQueries(definitions, options) {
98
+ const { getPlugin } = (0, _pluginRegistry.usePluginRegistry)();
99
+ const context = useTimeSeriesQueryContext();
100
+ const pluginLoaderResponse = (0, _pluginRegistry.usePlugins)('TimeSeriesQuery', definitions.map((d)=>({
101
+ kind: d.spec.plugin.kind
102
+ })));
103
+ return (0, _reactQuery.useQueries)({
104
+ queries: definitions.map((definition, idx)=>{
105
+ var ref;
106
+ const plugin = (ref = pluginLoaderResponse[idx]) === null || ref === void 0 ? void 0 : ref.data;
107
+ const { queryEnabled , queryKey } = getQueryOptions({
108
+ plugin,
109
+ definition,
110
+ context
111
+ });
112
+ return {
113
+ enabled: queryEnabled,
114
+ queryKey: queryKey,
115
+ queryFn: async ()=>{
116
+ // Keep options out of query key so we don't re-run queries because suggested step changes
117
+ const ctx = {
118
+ ...context,
119
+ suggestedStepMs: options === null || options === void 0 ? void 0 : options.suggestedStepMs
120
+ };
121
+ const plugin = await getPlugin('TimeSeriesQuery', definition.spec.plugin.kind);
122
+ const data = await plugin.getTimeSeriesData(definition.spec.plugin.spec, ctx);
123
+ return data;
124
+ }
125
+ };
126
+ })
127
+ });
128
+ }
129
+ function useTimeSeriesQueryContext() {
130
+ // Build the context object from data available at runtime
131
+ const { absoluteTimeRange , refreshKey } = (0, _timeRangeProvider.useTimeRange)();
132
+ const variableState = (0, _templateVariables.useTemplateVariableValues)();
133
+ const datasourceStore = (0, _datasources.useDatasourceStore)();
134
+ return {
135
+ timeRange: absoluteTimeRange,
136
+ variableState,
137
+ datasourceStore,
138
+ refreshKey
139
+ };
140
+ }
@@ -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("./render"), 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,52 @@
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, "renderWithContext", {
18
+ enumerable: true,
19
+ get: ()=>renderWithContext
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("@testing-library/react");
23
+ const _reactQuery = require("@tanstack/react-query");
24
+ const _pluginRegistry = require("../components/PluginRegistry");
25
+ const _testPlugins = require("./test-plugins");
26
+ const testLogger = {
27
+ log: console.log,
28
+ warn: console.warn,
29
+ error: ()=>{
30
+ // Don't log network errors in tests to the console
31
+ }
32
+ };
33
+ function renderWithContext(ui, renderOptions, contextOptions) {
34
+ // Create a new QueryClient for each test to avoid caching issues
35
+ const queryClient = new _reactQuery.QueryClient({
36
+ defaultOptions: {
37
+ queries: {
38
+ refetchOnWindowFocus: false,
39
+ retry: false
40
+ }
41
+ },
42
+ logger: testLogger
43
+ });
44
+ return (0, _react.render)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactQuery.QueryClientProvider, {
45
+ client: queryClient,
46
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginRegistry.PluginRegistry, {
47
+ pluginLoader: _testPlugins.testPluginLoader,
48
+ defaultPluginKinds: contextOptions === null || contextOptions === void 0 ? void 0 : contextOptions.defaultPluginKinds,
49
+ children: ui
50
+ })
51
+ }), renderOptions);
52
+ }
@@ -0,0 +1,20 @@
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
+ // Add testing library assertions
14
+ "use strict";
15
+ Object.defineProperty(exports, "__esModule", {
16
+ value: true
17
+ });
18
+ require("@testing-library/jest-dom/extend-expect");
19
+ // Always mock e-charts during tests since we don't have a proper canvas in jsdom
20
+ jest.mock('echarts/core');
@@ -0,0 +1,77 @@
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
+ BertPanel1: ()=>BertPanel1,
25
+ BertPanel2: ()=>BertPanel2
26
+ });
27
+ const _jsxRuntime = require("react/jsx-runtime");
28
+ const BertPanel1 = {
29
+ PanelComponent: ()=>null,
30
+ OptionsEditorComponent: function BertPanel1Editor({ value , onChange }) {
31
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
32
+ children: [
33
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)("label", {
34
+ htmlFor: "editor-input",
35
+ children: "BertPanel1 editor"
36
+ }),
37
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)("input", {
38
+ type: "text",
39
+ id: "editor-input",
40
+ value: value.option1,
41
+ onChange: (e)=>onChange({
42
+ ...value,
43
+ option1: e.target.value
44
+ })
45
+ })
46
+ ]
47
+ });
48
+ },
49
+ createInitialOptions: ()=>({
50
+ option1: ''
51
+ })
52
+ };
53
+ const BertPanel2 = {
54
+ PanelComponent: ()=>null,
55
+ OptionsEditorComponent: function BertPanel2Editor({ value , onChange }) {
56
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
57
+ children: [
58
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)("label", {
59
+ htmlFor: "editor-input",
60
+ children: "BertPanel2 editor"
61
+ }),
62
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)("input", {
63
+ type: "text",
64
+ id: "editor-input",
65
+ value: value.option2,
66
+ onChange: (e)=>onChange({
67
+ ...value,
68
+ option2: e.target.value
69
+ })
70
+ })
71
+ ]
72
+ });
73
+ },
74
+ createInitialOptions: ()=>({
75
+ option2: ''
76
+ })
77
+ };
@@ -0,0 +1,58 @@
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, "ErnieVariable", {
18
+ enumerable: true,
19
+ get: ()=>ErnieVariable
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const data = [
23
+ {
24
+ label: 'Grover',
25
+ value: 'Grover'
26
+ },
27
+ {
28
+ label: 'Snuffleupagus',
29
+ value: 'Snuffleupagus'
30
+ }
31
+ ];
32
+ const ErnieVariable = {
33
+ getVariableOptions: async ()=>({
34
+ data
35
+ }),
36
+ OptionsEditorComponent: function ErnieVariableEditor({ value , onChange }) {
37
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
38
+ children: [
39
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)("label", {
40
+ htmlFor: "editor-input",
41
+ children: "ErnieVariable editor"
42
+ }),
43
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)("input", {
44
+ type: "text",
45
+ id: "editor-input",
46
+ value: value.variableOption,
47
+ onChange: (e)=>onChange({
48
+ ...value,
49
+ variableOption: e.target.value
50
+ })
51
+ })
52
+ ]
53
+ });
54
+ },
55
+ createInitialOptions: ()=>({
56
+ variableOption: ''
57
+ })
58
+ };
@@ -0,0 +1,77 @@
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, "testPluginLoader", {
18
+ enumerable: true,
19
+ get: ()=>testPluginLoader
20
+ });
21
+ const _model = require("../../model");
22
+ const _pluginJson = /*#__PURE__*/ _interopRequireDefault(require("./bert/plugin.json"));
23
+ const _pluginJson1 = /*#__PURE__*/ _interopRequireDefault(require("./ernie/plugin.json"));
24
+ function _interopRequireDefault(obj) {
25
+ return obj && obj.__esModule ? obj : {
26
+ default: obj
27
+ };
28
+ }
29
+ function _getRequireWildcardCache(nodeInterop) {
30
+ if (typeof WeakMap !== "function") return null;
31
+ var cacheBabelInterop = new WeakMap();
32
+ var cacheNodeInterop = new WeakMap();
33
+ return (_getRequireWildcardCache = function(nodeInterop) {
34
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
35
+ })(nodeInterop);
36
+ }
37
+ function _interopRequireWildcard(obj, nodeInterop) {
38
+ if (!nodeInterop && obj && obj.__esModule) {
39
+ return obj;
40
+ }
41
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
42
+ return {
43
+ default: obj
44
+ };
45
+ }
46
+ var cache = _getRequireWildcardCache(nodeInterop);
47
+ if (cache && cache.has(obj)) {
48
+ return cache.get(obj);
49
+ }
50
+ var newObj = {};
51
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
52
+ for(var key in obj){
53
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
54
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
55
+ if (desc && (desc.get || desc.set)) {
56
+ Object.defineProperty(newObj, key, desc);
57
+ } else {
58
+ newObj[key] = obj[key];
59
+ }
60
+ }
61
+ }
62
+ newObj.default = obj;
63
+ if (cache) {
64
+ cache.set(obj, newObj);
65
+ }
66
+ return newObj;
67
+ }
68
+ const testPluginLoader = (0, _model.dynamicImportPluginLoader)([
69
+ {
70
+ resource: _pluginJson.default,
71
+ importPlugin: ()=>Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("./bert")))
72
+ },
73
+ {
74
+ resource: _pluginJson1.default,
75
+ importPlugin: ()=>Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("./ernie")))
76
+ }
77
+ ]);
@@ -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("./mock-plugin-registry"), 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
+ }