@perses-dev/plugin-system 0.39.0 → 0.40.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 (253) hide show
  1. package/dist/cjs/components/CalculationSelector/CalculationSelector.js +6 -4
  2. package/dist/cjs/components/CalculationSelector/index.js +10 -8
  3. package/dist/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +380 -0
  4. package/dist/cjs/components/DatasourceEditorForm/index.js +30 -0
  5. package/dist/cjs/components/DatasourceSelect.js +119 -21
  6. package/dist/cjs/components/LegendOptionsEditor/LegendOptionsEditor.js +18 -16
  7. package/dist/cjs/components/LegendOptionsEditor/index.js +10 -8
  8. package/dist/cjs/components/OptionsEditorRadios/OptionsEditorRadios.js +23 -28
  9. package/dist/cjs/components/OptionsEditorRadios/index.js +10 -8
  10. package/dist/cjs/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js +6 -4
  11. package/dist/cjs/components/OptionsEditorTabPanel/index.js +10 -8
  12. package/dist/cjs/components/OptionsEditorTabs/OptionsEditorTabs.js +10 -8
  13. package/dist/cjs/components/OptionsEditorTabs/index.js +10 -8
  14. package/dist/cjs/components/PanelSpecEditor/PanelSpecEditor.js +13 -11
  15. package/dist/cjs/components/PanelSpecEditor/index.js +10 -8
  16. package/dist/cjs/components/PluginEditor/PluginEditor.js +24 -31
  17. package/dist/cjs/components/PluginEditor/index.js +11 -9
  18. package/dist/cjs/components/PluginEditor/plugin-editor-api.js +5 -3
  19. package/dist/cjs/components/PluginKindSelect/PluginKindSelect.js +23 -12
  20. package/dist/cjs/components/PluginKindSelect/index.js +10 -8
  21. package/dist/cjs/components/PluginRegistry/PluginRegistry.js +11 -9
  22. package/dist/cjs/components/PluginRegistry/index.js +10 -8
  23. package/dist/cjs/components/PluginRegistry/plugin-indexes.js +6 -2
  24. package/dist/cjs/components/PluginSpecEditor/PluginSpecEditor.js +6 -4
  25. package/dist/cjs/components/PluginSpecEditor/index.js +10 -8
  26. package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +15 -13
  27. package/dist/cjs/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js +21 -19
  28. package/dist/cjs/components/TimeSeriesQueryEditor/index.js +10 -8
  29. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +256 -166
  30. package/dist/cjs/components/Variables/VariableEditorForm/VariablePreview.js +32 -28
  31. package/dist/cjs/components/Variables/VariableEditorForm/index.js +11 -9
  32. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +28 -32
  33. package/dist/cjs/components/Variables/index.js +11 -9
  34. package/dist/cjs/components/Variables/variable-model.js +17 -9
  35. package/dist/cjs/components/index.js +22 -19
  36. package/dist/cjs/constants/index.js +10 -8
  37. package/dist/cjs/constants/user-interface-text.js +3 -1
  38. package/dist/cjs/index.js +16 -13
  39. package/dist/cjs/model/index.js +17 -15
  40. package/dist/cjs/model/legend.js +32 -20
  41. package/dist/cjs/model/panels.js +2 -2
  42. package/dist/cjs/model/plugin-base.js +2 -2
  43. package/dist/cjs/model/plugin-loading.js +3 -1
  44. package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +19 -11
  45. package/dist/cjs/runtime/DataQueriesProvider/index.js +11 -9
  46. package/dist/cjs/runtime/DataQueriesProvider/model.js +12 -8
  47. package/dist/cjs/runtime/TimeRangeProvider/TimeRangeProvider.js +19 -11
  48. package/dist/cjs/runtime/TimeRangeProvider/index.js +11 -9
  49. package/dist/cjs/runtime/TimeRangeProvider/query-params.js +36 -18
  50. package/dist/cjs/runtime/builtin-variables.js +81 -0
  51. package/dist/cjs/runtime/datasources.js +29 -11
  52. package/dist/cjs/runtime/index.js +16 -13
  53. package/dist/cjs/runtime/plugin-registry.js +41 -11
  54. package/dist/cjs/runtime/template-variables.js +42 -12
  55. package/dist/cjs/runtime/time-series-queries.js +39 -27
  56. package/dist/cjs/stories/shared-utils/decorators/WithDataQueries.js +7 -5
  57. package/dist/cjs/stories/shared-utils/decorators/WithPluginRegistry.js +16 -14
  58. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +42 -0
  59. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +19 -13
  60. package/dist/cjs/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js +6 -4
  61. package/dist/cjs/stories/shared-utils/decorators/WithTimeRange.js +7 -5
  62. package/dist/cjs/stories/shared-utils/decorators/index.js +15 -12
  63. package/dist/cjs/stories/shared-utils/index.js +10 -8
  64. package/dist/cjs/test/index.js +11 -9
  65. package/dist/cjs/test/mock-data.js +3 -1
  66. package/dist/cjs/test/render.js +13 -11
  67. package/dist/cjs/test/test-plugins/bert/index.js +14 -10
  68. package/dist/cjs/test/test-plugins/ernie/index.js +13 -9
  69. package/dist/cjs/test/test-plugins/index.js +11 -9
  70. package/dist/cjs/test-utils/index.js +10 -8
  71. package/dist/cjs/test-utils/mock-plugin-registry.js +8 -4
  72. package/dist/cjs/utils/action.js +43 -0
  73. package/dist/cjs/utils/index.js +11 -8
  74. package/dist/cjs/utils/variables.js +26 -8
  75. package/dist/cjs/validation/datasource.js +30 -0
  76. package/dist/cjs/validation/index.js +32 -0
  77. package/dist/cjs/validation/resource.js +24 -0
  78. package/dist/cjs/validation/variable.js +29 -0
  79. package/dist/components/CalculationSelector/CalculationSelector.js.map +1 -1
  80. package/dist/components/CalculationSelector/index.js.map +1 -1
  81. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts +15 -0
  82. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -0
  83. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +333 -0
  84. package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -0
  85. package/dist/components/DatasourceEditorForm/index.d.ts +2 -0
  86. package/dist/components/DatasourceEditorForm/index.d.ts.map +1 -0
  87. package/dist/components/DatasourceEditorForm/index.js +15 -0
  88. package/dist/components/DatasourceEditorForm/index.js.map +1 -0
  89. package/dist/components/DatasourceSelect.d.ts +5 -0
  90. package/dist/components/DatasourceSelect.d.ts.map +1 -1
  91. package/dist/components/DatasourceSelect.js +102 -19
  92. package/dist/components/DatasourceSelect.js.map +1 -1
  93. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js +2 -2
  94. package/dist/components/LegendOptionsEditor/LegendOptionsEditor.js.map +1 -1
  95. package/dist/components/LegendOptionsEditor/index.js.map +1 -1
  96. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts +2 -2
  97. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.d.ts.map +1 -1
  98. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js +16 -23
  99. package/dist/components/OptionsEditorRadios/OptionsEditorRadios.js.map +1 -1
  100. package/dist/components/OptionsEditorRadios/index.js.map +1 -1
  101. package/dist/components/OptionsEditorTabPanel/OptionsEditorTabPanel.js.map +1 -1
  102. package/dist/components/OptionsEditorTabPanel/index.js.map +1 -1
  103. package/dist/components/OptionsEditorTabs/OptionsEditorTabs.js.map +1 -1
  104. package/dist/components/OptionsEditorTabs/index.js.map +1 -1
  105. package/dist/components/PanelSpecEditor/PanelSpecEditor.js +2 -2
  106. package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
  107. package/dist/components/PanelSpecEditor/index.js.map +1 -1
  108. package/dist/components/PluginEditor/PluginEditor.js +15 -24
  109. package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
  110. package/dist/components/PluginEditor/index.js.map +1 -1
  111. package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -1
  112. package/dist/components/PluginEditor/plugin-editor-api.js +2 -2
  113. package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
  114. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +3 -3
  115. package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
  116. package/dist/components/PluginKindSelect/PluginKindSelect.js +21 -12
  117. package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
  118. package/dist/components/PluginKindSelect/index.js.map +1 -1
  119. package/dist/components/PluginRegistry/PluginRegistry.js +3 -3
  120. package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
  121. package/dist/components/PluginRegistry/index.js.map +1 -1
  122. package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
  123. package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
  124. package/dist/components/PluginSpecEditor/index.js.map +1 -1
  125. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js +4 -4
  126. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryEditor.js.map +1 -1
  127. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js +1 -1
  128. package/dist/components/TimeSeriesQueryEditor/TimeSeriesQueryInput.js.map +1 -1
  129. package/dist/components/TimeSeriesQueryEditor/index.js.map +1 -1
  130. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +10 -7
  131. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  132. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +200 -112
  133. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  134. package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
  135. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -1
  136. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +5 -4
  137. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  138. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +22 -30
  139. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  140. package/dist/components/Variables/index.js.map +1 -1
  141. package/dist/components/Variables/variable-model.js +3 -3
  142. package/dist/components/Variables/variable-model.js.map +1 -1
  143. package/dist/components/index.d.ts +1 -0
  144. package/dist/components/index.d.ts.map +1 -1
  145. package/dist/components/index.js +1 -0
  146. package/dist/components/index.js.map +1 -1
  147. package/dist/constants/index.js.map +1 -1
  148. package/dist/constants/user-interface-text.js.map +1 -1
  149. package/dist/index.d.ts +1 -0
  150. package/dist/index.d.ts.map +1 -1
  151. package/dist/index.js +1 -0
  152. package/dist/index.js.map +1 -1
  153. package/dist/model/datasource.d.ts +2 -1
  154. package/dist/model/datasource.d.ts.map +1 -1
  155. package/dist/model/datasource.js.map +1 -1
  156. package/dist/model/index.js.map +1 -1
  157. package/dist/model/legend.d.ts +1 -1
  158. package/dist/model/legend.d.ts.map +1 -1
  159. package/dist/model/legend.js +14 -14
  160. package/dist/model/legend.js.map +1 -1
  161. package/dist/model/panels.js.map +1 -1
  162. package/dist/model/plugin-base.js.map +1 -1
  163. package/dist/model/plugin-loading.js.map +1 -1
  164. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +4 -4
  165. package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
  166. package/dist/runtime/DataQueriesProvider/index.js.map +1 -1
  167. package/dist/runtime/DataQueriesProvider/model.d.ts +3 -2
  168. package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
  169. package/dist/runtime/DataQueriesProvider/model.js +4 -4
  170. package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
  171. package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
  172. package/dist/runtime/TimeRangeProvider/index.js.map +1 -1
  173. package/dist/runtime/TimeRangeProvider/query-params.js +1 -1
  174. package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
  175. package/dist/runtime/builtin-variables.d.ts +11 -0
  176. package/dist/runtime/builtin-variables.d.ts.map +1 -0
  177. package/dist/runtime/builtin-variables.js +59 -0
  178. package/dist/runtime/builtin-variables.js.map +1 -0
  179. package/dist/runtime/datasources.d.ts +14 -6
  180. package/dist/runtime/datasources.d.ts.map +1 -1
  181. package/dist/runtime/datasources.js +13 -6
  182. package/dist/runtime/datasources.js.map +1 -1
  183. package/dist/runtime/index.d.ts +1 -0
  184. package/dist/runtime/index.d.ts.map +1 -1
  185. package/dist/runtime/index.js +1 -0
  186. package/dist/runtime/index.js.map +1 -1
  187. package/dist/runtime/plugin-registry.d.ts +2 -0
  188. package/dist/runtime/plugin-registry.d.ts.map +1 -1
  189. package/dist/runtime/plugin-registry.js +19 -2
  190. package/dist/runtime/plugin-registry.js.map +1 -1
  191. package/dist/runtime/template-variables.d.ts +2 -1
  192. package/dist/runtime/template-variables.d.ts.map +1 -1
  193. package/dist/runtime/template-variables.js +27 -8
  194. package/dist/runtime/template-variables.js.map +1 -1
  195. package/dist/runtime/time-series-queries.d.ts +3 -3
  196. package/dist/runtime/time-series-queries.d.ts.map +1 -1
  197. package/dist/runtime/time-series-queries.js +14 -12
  198. package/dist/runtime/time-series-queries.js.map +1 -1
  199. package/dist/stories/shared-utils/decorators/WithDataQueries.js.map +1 -1
  200. package/dist/stories/shared-utils/decorators/WithPluginRegistry.js.map +1 -1
  201. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts +13 -0
  202. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.d.ts.map +1 -0
  203. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js +39 -0
  204. package/dist/stories/shared-utils/decorators/WithPluginSystemBuiltinVariables.js.map +1 -0
  205. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.d.ts.map +1 -1
  206. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js +11 -7
  207. package/dist/stories/shared-utils/decorators/WithPluginSystemDatasourceStore.js.map +1 -1
  208. package/dist/stories/shared-utils/decorators/WithPluginSystemTemplateVariables.js.map +1 -1
  209. package/dist/stories/shared-utils/decorators/WithTimeRange.js.map +1 -1
  210. package/dist/stories/shared-utils/decorators/index.d.ts +1 -0
  211. package/dist/stories/shared-utils/decorators/index.d.ts.map +1 -1
  212. package/dist/stories/shared-utils/decorators/index.js +1 -0
  213. package/dist/stories/shared-utils/decorators/index.js.map +1 -1
  214. package/dist/stories/shared-utils/index.js.map +1 -1
  215. package/dist/test/index.js.map +1 -1
  216. package/dist/test/mock-data.js.map +1 -1
  217. package/dist/test/render.js +2 -2
  218. package/dist/test/render.js.map +1 -1
  219. package/dist/test/setup-tests.js.map +1 -1
  220. package/dist/test/test-plugins/bert/index.js.map +1 -1
  221. package/dist/test/test-plugins/ernie/index.js.map +1 -1
  222. package/dist/test/test-plugins/index.js.map +1 -1
  223. package/dist/test-utils/index.js.map +1 -1
  224. package/dist/test-utils/mock-plugin-registry.js +2 -2
  225. package/dist/test-utils/mock-plugin-registry.js.map +1 -1
  226. package/dist/utils/action.d.ts +4 -0
  227. package/dist/utils/action.d.ts.map +1 -0
  228. package/dist/utils/action.js +27 -0
  229. package/dist/utils/action.js.map +1 -0
  230. package/dist/utils/index.d.ts +1 -0
  231. package/dist/utils/index.d.ts.map +1 -1
  232. package/dist/utils/index.js +1 -0
  233. package/dist/utils/index.js.map +1 -1
  234. package/dist/utils/variables.d.ts.map +1 -1
  235. package/dist/utils/variables.js +17 -5
  236. package/dist/utils/variables.js.map +1 -1
  237. package/dist/validation/datasource.d.ts +19 -0
  238. package/dist/validation/datasource.d.ts.map +1 -0
  239. package/dist/validation/datasource.js +22 -0
  240. package/dist/validation/datasource.js.map +1 -0
  241. package/dist/validation/index.d.ts +4 -0
  242. package/dist/validation/index.d.ts.map +1 -0
  243. package/dist/validation/index.js +17 -0
  244. package/dist/validation/index.js.map +1 -0
  245. package/dist/validation/resource.d.ts +3 -0
  246. package/dist/validation/resource.d.ts.map +1 -0
  247. package/dist/validation/resource.js +16 -0
  248. package/dist/validation/resource.js.map +1 -0
  249. package/dist/validation/variable.d.ts +19 -0
  250. package/dist/validation/variable.d.ts.map +1 -0
  251. package/dist/validation/variable.js +21 -0
  252. package/dist/validation/variable.js.map +1 -0
  253. package/package.json +8 -6
@@ -16,9 +16,11 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  Object.defineProperty(exports, "CalculationSelector", {
18
18
  enumerable: true,
19
- get: ()=>CalculationSelector
19
+ get: function() {
20
+ return CalculationSelector;
21
+ }
20
22
  });
21
- const _jsxRuntime = require("react/jsx-runtime");
23
+ const _jsxruntime = require("react/jsx-runtime");
22
24
  const _components = require("@perses-dev/components");
23
25
  const _core = require("@perses-dev/core");
24
26
  const CALC_OPTIONS = Object.entries(_core.CALCULATIONS_CONFIG).map(([id, config])=>{
@@ -32,9 +34,9 @@ function CalculationSelector({ value , onChange }) {
32
34
  onChange(newValue.id);
33
35
  };
34
36
  const calcConfig = _core.CALCULATIONS_CONFIG[value];
35
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.OptionsEditorControl, {
37
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.OptionsEditorControl, {
36
38
  label: "Calculation",
37
- control: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.SettingsAutocomplete, {
39
+ control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.SettingsAutocomplete, {
38
40
  value: {
39
41
  ...calcConfig,
40
42
  id: value
@@ -14,15 +14,17 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- _exportStar(require("./CalculationSelector"), exports);
18
- function _exportStar(from, to) {
17
+ _export_star(require("./CalculationSelector"), exports);
18
+ function _export_star(from, to) {
19
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
- });
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
21
+ Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ }
26
28
  });
27
29
  return from;
28
30
  }
@@ -0,0 +1,380 @@
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, "DatasourceEditorForm", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return DatasourceEditorForm;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _useimmer = require("use-immer");
25
+ const _material = require("@mui/material");
26
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
27
+ const _components = require("@perses-dev/components");
28
+ const _reacthookform = require("react-hook-form");
29
+ const _zod = require("@hookform/resolvers/zod");
30
+ const _PluginEditor = require("../PluginEditor");
31
+ const _utils = require("../../utils");
32
+ const _validation = require("../../validation");
33
+ function _getRequireWildcardCache(nodeInterop) {
34
+ if (typeof WeakMap !== "function") return null;
35
+ var cacheBabelInterop = new WeakMap();
36
+ var cacheNodeInterop = new WeakMap();
37
+ return (_getRequireWildcardCache = function(nodeInterop) {
38
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
39
+ })(nodeInterop);
40
+ }
41
+ function _interop_require_wildcard(obj, nodeInterop) {
42
+ if (!nodeInterop && obj && obj.__esModule) {
43
+ return obj;
44
+ }
45
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
46
+ return {
47
+ default: obj
48
+ };
49
+ }
50
+ var cache = _getRequireWildcardCache(nodeInterop);
51
+ if (cache && cache.has(obj)) {
52
+ return cache.get(obj);
53
+ }
54
+ var newObj = {};
55
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
56
+ for(var key in obj){
57
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
58
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
59
+ if (desc && (desc.get || desc.set)) {
60
+ Object.defineProperty(newObj, key, desc);
61
+ } else {
62
+ newObj[key] = obj[key];
63
+ }
64
+ }
65
+ }
66
+ newObj.default = obj;
67
+ if (cache) {
68
+ cache.set(obj, newObj);
69
+ }
70
+ return newObj;
71
+ }
72
+ /**
73
+ * This preprocessing ensures that we always have a defined object for the `display` property
74
+ * @param datasource
75
+ */ function getInitialState(datasource) {
76
+ var _datasource_spec_display, _datasource_spec_display1;
77
+ var _datasource_spec_display_name, _datasource_spec_display_description;
78
+ const patchedDisplay = {
79
+ name: (_datasource_spec_display_name = (_datasource_spec_display = datasource.spec.display) === null || _datasource_spec_display === void 0 ? void 0 : _datasource_spec_display.name) !== null && _datasource_spec_display_name !== void 0 ? _datasource_spec_display_name : '',
80
+ description: (_datasource_spec_display_description = (_datasource_spec_display1 = datasource.spec.display) === null || _datasource_spec_display1 === void 0 ? void 0 : _datasource_spec_display1.description) !== null && _datasource_spec_display_description !== void 0 ? _datasource_spec_display_description : ''
81
+ };
82
+ return {
83
+ ...datasource,
84
+ spec: {
85
+ ...datasource.spec,
86
+ display: patchedDisplay
87
+ }
88
+ };
89
+ }
90
+ function DatasourceEditorForm(props) {
91
+ var _state_spec_display, _state_spec_display1;
92
+ const { initialDatasource , initialAction , isDraft , isReadonly , onSave , onClose , onDelete } = props;
93
+ const patchedInitialDatasource = getInitialState(initialDatasource);
94
+ const [state, setState] = (0, _useimmer.useImmer)(patchedInitialDatasource);
95
+ const [isDiscardDialogOpened, setDiscardDialogOpened] = (0, _react.useState)(false);
96
+ const [action, setAction] = (0, _react.useState)(initialAction);
97
+ const titleAction = (0, _utils.getTitleAction)(action, isDraft);
98
+ const submitText = (0, _utils.getSubmitText)(action, isDraft);
99
+ const form = (0, _reacthookform.useForm)({
100
+ resolver: (0, _zod.zodResolver)(_validation.datasourceEditValidationSchema),
101
+ mode: 'onBlur',
102
+ defaultValues: {
103
+ name: state.metadata.name,
104
+ title: (_state_spec_display = state.spec.display) === null || _state_spec_display === void 0 ? void 0 : _state_spec_display.name,
105
+ description: (_state_spec_display1 = state.spec.display) === null || _state_spec_display1 === void 0 ? void 0 : _state_spec_display1.description,
106
+ default: state.spec.default
107
+ }
108
+ });
109
+ const processForm = ()=>{
110
+ onSave(state);
111
+ };
112
+ // When user click on cancel, several possibilities:
113
+ // - create action: ask for discard approval
114
+ // - update action: ask for discard approval if changed
115
+ // - read action: don´t ask for discard approval
116
+ const handleCancel = (0, _react.useCallback)(()=>{
117
+ if (JSON.stringify(patchedInitialDatasource) !== JSON.stringify(state)) {
118
+ setDiscardDialogOpened(true);
119
+ } else {
120
+ onClose();
121
+ }
122
+ }, [
123
+ state,
124
+ patchedInitialDatasource,
125
+ setDiscardDialogOpened,
126
+ onClose
127
+ ]);
128
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_reacthookform.FormProvider, {
129
+ ...form,
130
+ children: [
131
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
132
+ sx: {
133
+ display: 'flex',
134
+ alignItems: 'center',
135
+ padding: (theme)=>theme.spacing(1, 2),
136
+ borderBottom: (theme)=>`1px solid ${theme.palette.divider}`
137
+ },
138
+ children: [
139
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Typography, {
140
+ variant: "h2",
141
+ children: [
142
+ titleAction,
143
+ " Datasource"
144
+ ]
145
+ }),
146
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Stack, {
147
+ direction: "row",
148
+ spacing: 1,
149
+ sx: {
150
+ marginLeft: 'auto'
151
+ },
152
+ children: action === 'read' ? /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
153
+ children: [
154
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
155
+ disabled: isReadonly,
156
+ variant: "contained",
157
+ onClick: ()=>setAction('update'),
158
+ children: "Edit"
159
+ }),
160
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
161
+ color: "error",
162
+ variant: "outlined",
163
+ onClick: onDelete,
164
+ children: "Delete"
165
+ }),
166
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Divider, {
167
+ orientation: "vertical",
168
+ flexItem: true,
169
+ sx: (theme)=>({
170
+ borderColor: theme.palette.grey['500'],
171
+ '&.MuiDivider-root': {
172
+ marginLeft: 2,
173
+ marginRight: 1
174
+ }
175
+ })
176
+ }),
177
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
178
+ color: "secondary",
179
+ variant: "outlined",
180
+ onClick: onClose,
181
+ children: "Close"
182
+ })
183
+ ]
184
+ }) : /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
185
+ children: [
186
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
187
+ variant: "contained",
188
+ disabled: !form.formState.isValid,
189
+ onClick: form.handleSubmit(processForm),
190
+ children: submitText
191
+ }),
192
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
193
+ color: "secondary",
194
+ variant: "outlined",
195
+ onClick: handleCancel,
196
+ children: "Cancel"
197
+ })
198
+ ]
199
+ })
200
+ })
201
+ ]
202
+ }),
203
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
204
+ padding: 2,
205
+ sx: {
206
+ overflowY: 'scroll'
207
+ },
208
+ children: [
209
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Grid, {
210
+ container: true,
211
+ spacing: 2,
212
+ mb: 2,
213
+ children: [
214
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Grid, {
215
+ item: true,
216
+ xs: 4,
217
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reacthookform.Controller, {
218
+ name: "name",
219
+ render: ({ field , fieldState })=>{
220
+ var _fieldState_error;
221
+ /*#__PURE__*/ return (0, _jsxruntime.jsx)(_material.TextField, {
222
+ ...field,
223
+ required: true,
224
+ fullWidth: true,
225
+ name: "name",
226
+ label: "Name",
227
+ InputLabelProps: {
228
+ shrink: action === 'read' ? true : undefined
229
+ },
230
+ InputProps: {
231
+ disabled: action === 'update',
232
+ readOnly: action === 'read'
233
+ },
234
+ error: !!fieldState.error,
235
+ helperText: (_fieldState_error = fieldState.error) === null || _fieldState_error === void 0 ? void 0 : _fieldState_error.message,
236
+ onChange: (event)=>{
237
+ field.onChange(event);
238
+ setState((draft)=>{
239
+ draft.metadata.name = event.target.value;
240
+ });
241
+ }
242
+ });
243
+ }
244
+ })
245
+ }),
246
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Grid, {
247
+ item: true,
248
+ xs: 8,
249
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reacthookform.Controller, {
250
+ name: "title",
251
+ render: ({ field , fieldState })=>{
252
+ var _fieldState_error;
253
+ /*#__PURE__*/ return (0, _jsxruntime.jsx)(_material.TextField, {
254
+ ...field,
255
+ fullWidth: true,
256
+ name: "title",
257
+ label: "Display Label",
258
+ InputLabelProps: {
259
+ shrink: action === 'read' ? true : undefined
260
+ },
261
+ InputProps: {
262
+ readOnly: action === 'read'
263
+ },
264
+ error: !!fieldState.error,
265
+ helperText: (_fieldState_error = fieldState.error) === null || _fieldState_error === void 0 ? void 0 : _fieldState_error.message,
266
+ onChange: (event)=>{
267
+ setState((draft)=>{
268
+ field.onChange(event);
269
+ if (draft.spec.display) {
270
+ draft.spec.display.name = event.target.value;
271
+ }
272
+ });
273
+ }
274
+ });
275
+ }
276
+ })
277
+ }),
278
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Grid, {
279
+ item: true,
280
+ xs: 12,
281
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_reacthookform.Controller, {
282
+ name: "description",
283
+ render: ({ field , fieldState })=>{
284
+ var _fieldState_error;
285
+ /*#__PURE__*/ return (0, _jsxruntime.jsx)(_material.TextField, {
286
+ ...field,
287
+ fullWidth: true,
288
+ name: "description",
289
+ label: "Description",
290
+ InputLabelProps: {
291
+ shrink: action === 'read' ? true : undefined
292
+ },
293
+ InputProps: {
294
+ readOnly: action === 'read'
295
+ },
296
+ error: !!fieldState.error,
297
+ helperText: (_fieldState_error = fieldState.error) === null || _fieldState_error === void 0 ? void 0 : _fieldState_error.message,
298
+ onChange: (event)=>{
299
+ field.onChange(event);
300
+ setState((draft)=>{
301
+ if (draft.spec.display) {
302
+ draft.spec.display.description = event.target.value;
303
+ }
304
+ });
305
+ }
306
+ });
307
+ }
308
+ })
309
+ }),
310
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Grid, {
311
+ item: true,
312
+ xs: 6,
313
+ sx: {
314
+ paddingTop: '5px !important'
315
+ },
316
+ children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
317
+ children: [
318
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_reacthookform.Controller, {
319
+ name: "default",
320
+ render: ({ field })=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.FormControlLabel, {
321
+ ...field,
322
+ control: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Switch, {
323
+ checked: state.spec.default,
324
+ readOnly: action === 'read',
325
+ onChange: (event)=>{
326
+ if (action === 'read') return; // ReadOnly prop is not blocking user interaction...
327
+ field.onChange(event);
328
+ setState((draft)=>{
329
+ draft.spec.default = event.target.checked;
330
+ });
331
+ }
332
+ }),
333
+ label: "Set as default"
334
+ })
335
+ }),
336
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Typography, {
337
+ variant: "caption",
338
+ children: [
339
+ "Whether this datasource should be the default ",
340
+ state.spec.plugin.kind,
341
+ " to be used"
342
+ ]
343
+ })
344
+ ]
345
+ })
346
+ })
347
+ ]
348
+ }),
349
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Divider, {}),
350
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Typography, {
351
+ py: 1,
352
+ variant: "h3",
353
+ children: "Plugin Options"
354
+ }),
355
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_PluginEditor.PluginEditor, {
356
+ width: "100%",
357
+ pluginType: "Datasource",
358
+ pluginKindLabel: "Source",
359
+ value: state.spec.plugin,
360
+ isReadonly: action === 'read',
361
+ onChange: (v)=>{
362
+ setState((draft)=>{
363
+ draft.spec.plugin = v;
364
+ });
365
+ }
366
+ })
367
+ ]
368
+ }),
369
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.DiscardChangesConfirmationDialog, {
370
+ description: "Are you sure you want to discard your changes? Changes cannot be recovered.",
371
+ isOpen: isDiscardDialogOpened,
372
+ onCancel: ()=>setDiscardDialogOpened(false),
373
+ onDiscardChanges: ()=>{
374
+ setDiscardDialogOpened(false);
375
+ onClose();
376
+ }
377
+ })
378
+ ]
379
+ });
380
+ }
@@ -0,0 +1,30 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _export_star(require("./DatasourceEditorForm"), exports);
18
+ function _export_star(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
21
+ Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ }
28
+ });
29
+ return from;
30
+ }
@@ -14,63 +14,161 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "DatasourceSelect", {
18
- enumerable: true,
19
- get: ()=>DatasourceSelect
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
+ DatasourceSelect: function() {
25
+ return DatasourceSelect;
26
+ },
27
+ DatasourceName: function() {
28
+ return DatasourceName;
29
+ }
20
30
  });
21
- const _jsxRuntime = require("react/jsx-runtime");
31
+ const _jsxruntime = require("react/jsx-runtime");
32
+ const _OpenInNew = /*#__PURE__*/ _interop_require_default(require("mdi-material-ui/OpenInNew"));
22
33
  const _material = require("@mui/material");
23
34
  const _react = require("react");
24
35
  const _runtime = require("../runtime");
36
+ function _interop_require_default(obj) {
37
+ return obj && obj.__esModule ? obj : {
38
+ default: obj
39
+ };
40
+ }
25
41
  function DatasourceSelect(props) {
26
42
  const { datasourcePluginKind , value , onChange , ...others } = props;
27
- const { data , isLoading } = (0, _runtime.useListDatasources)(datasourcePluginKind);
28
- // Convert the datasource list into menu items with name/value strings that the Select input can work with
43
+ const { data , isLoading } = (0, _runtime.useListDatasourceSelectItems)(datasourcePluginKind);
44
+ // Rebuild the group of the value if not provided
45
+ const defaultValue = (0, _react.useMemo)(()=>{
46
+ var _flatMap_find;
47
+ const group = (_flatMap_find = (data !== null && data !== void 0 ? data : []).flatMap((itemGroup)=>itemGroup.items).find((item)=>{
48
+ return value.kind === item.selector.kind && value.name === item.selector.name && !item.overridden;
49
+ })) === null || _flatMap_find === void 0 ? void 0 : _flatMap_find.selector.group;
50
+ return {
51
+ ...value,
52
+ group
53
+ };
54
+ }, [
55
+ value,
56
+ data
57
+ ]);
58
+ // Convert the datasource list into menu items with name/group?/value strings that the Select input can work with
29
59
  const menuItems = (0, _react.useMemo)(()=>{
30
- if (data === undefined) return [];
31
- return data.map((ds)=>({
32
- name: ds.name,
33
- value: selectorToOptionValue(ds.selector)
60
+ return (data !== null && data !== void 0 ? data : []).map((itemGroup)=>({
61
+ group: itemGroup.group,
62
+ editLink: itemGroup.editLink,
63
+ items: itemGroup.items.map((item)=>({
64
+ name: item.name,
65
+ overriding: item.overriding,
66
+ overridden: item.overridden,
67
+ group: item.selector.group,
68
+ value: selectorToOptionValue(item.selector)
69
+ }))
34
70
  }));
35
71
  }, [
36
72
  data
37
73
  ]);
38
74
  // While loading available values, just use an empty string so MUI select doesn't warn about values out of range
39
- const optionValue = isLoading ? '' : selectorToOptionValue(value);
75
+ const optionValue = isLoading ? '' : selectorToOptionValue(defaultValue);
40
76
  // When the user makes a selection, convert the string option value back to a DatasourceSelector
41
77
  const handleChange = (e)=>{
42
78
  const next = optionValueToSelector(e.target.value);
43
79
  onChange(next);
44
80
  };
45
- // TODO: Does this need a loading indicator of some kind?
46
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Select, {
81
+ // We use a fake action event when we click on the action of the chip (hijack the "delete" feature).
82
+ // This is because the href link action is on the `deleteIcon` property already, but the `onDelete` property
83
+ // controls its visibility.
84
+ // eslint-disable-next-line @typescript-eslint/no-empty-function
85
+ const fakeActionEvent = ()=>{};
86
+ // TODO:
87
+ // - Does this need a loading indicator of some kind?
88
+ // - The group's edit link is not clickable once selected.
89
+ // - The group's edit link is disabled if datasource is overridden.
90
+ // Ref: https://github.com/mui/material-ui/issues/36572
91
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Select, {
47
92
  ...others,
48
93
  value: optionValue,
49
94
  onChange: handleChange,
50
- children: menuItems.map((menuItem)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
51
- value: menuItem.value,
52
- children: menuItem.name
53
- }, menuItem.value))
95
+ children: menuItems.map((menuItemGroup)=>[
96
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Divider, {}, `${menuItemGroup.group}-divider`),
97
+ ...menuItemGroup.items.map((menuItem)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_material.MenuItem, {
98
+ value: menuItem.value,
99
+ disabled: menuItem.overridden,
100
+ children: /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Stack, {
101
+ direction: "row",
102
+ alignItems: "center",
103
+ justifyContent: "space-between",
104
+ width: "100%",
105
+ children: [
106
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.ListItemText, {
107
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(DatasourceName, {
108
+ name: menuItem.name,
109
+ overridden: menuItem.overridden,
110
+ overriding: menuItem.overriding
111
+ })
112
+ }),
113
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.ListItemText, {
114
+ style: {
115
+ textAlign: 'right'
116
+ },
117
+ children: menuItemGroup.group && menuItemGroup.group.length > 0 && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Chip, {
118
+ disabled: false,
119
+ label: menuItemGroup.group,
120
+ size: "small",
121
+ onDelete: menuItemGroup.editLink ? fakeActionEvent : undefined,
122
+ deleteIcon: menuItemGroup.editLink ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.IconButton, {
123
+ href: menuItemGroup.editLink,
124
+ target: "_blank",
125
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_OpenInNew.default, {
126
+ fontSize: "small"
127
+ })
128
+ }) : undefined
129
+ })
130
+ })
131
+ ]
132
+ })
133
+ }, menuItem.value))
134
+ ])
135
+ });
136
+ }
137
+ function DatasourceName(props) {
138
+ const { name , overridden , overriding } = props;
139
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_jsxruntime.Fragment, {
140
+ children: [
141
+ `${name} `,
142
+ !overridden && overriding && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
143
+ display: "inline",
144
+ fontWeight: "normal",
145
+ color: (theme)=>theme.palette.primary.main,
146
+ children: "(overriding)"
147
+ }),
148
+ overridden && '(overridden)'
149
+ ]
54
150
  });
55
151
  }
56
152
  // Delimiter used to stringify/parse option values
57
153
  const OPTION_VALUE_DELIMITER = '_____';
58
154
  // Given a DatasourceSelector, returns a string value like `{kind}_____{name}` that can be used as a Select input value
59
155
  function selectorToOptionValue(selector) {
60
- var _name;
156
+ var _selector_group, _selector_name;
61
157
  return [
62
158
  selector.kind,
63
- (_name = selector.name) !== null && _name !== void 0 ? _name : ''
159
+ (_selector_group = selector.group) !== null && _selector_group !== void 0 ? _selector_group : '',
160
+ (_selector_name = selector.name) !== null && _selector_name !== void 0 ? _selector_name : ''
64
161
  ].join(OPTION_VALUE_DELIMITER);
65
162
  }
66
163
  // Given an option value name like `{kind}_____{name}`, returns a DatasourceSelector
67
164
  function optionValueToSelector(optionValue) {
68
- const [kind, name] = optionValue.split(OPTION_VALUE_DELIMITER);
69
- if (kind === undefined || name === undefined) {
165
+ const [kind, group, name] = optionValue.split(OPTION_VALUE_DELIMITER);
166
+ if (kind === undefined || group === undefined || name === undefined) {
70
167
  throw new Error('Invalid optionValue string');
71
168
  }
72
169
  return {
73
170
  kind,
171
+ group: group === '' ? undefined : group,
74
172
  name: name === '' ? undefined : name
75
173
  };
76
174
  }