@perses-dev/dashboards 0.8.1 → 0.10.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 (258) hide show
  1. package/dist/cjs/components/Dashboard.js +25 -14
  2. package/dist/cjs/components/DashboardToolbar.js +148 -20
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +25 -19
  4. package/dist/cjs/components/GridLayout/GridLayout.js +92 -27
  5. package/dist/cjs/components/GridLayout/GridTitle.js +91 -31
  6. package/dist/cjs/components/GridLayout/index.js +18 -19
  7. package/dist/cjs/components/Panel/DeletePanelDialog.js +91 -0
  8. package/dist/cjs/components/Panel/Panel.js +156 -55
  9. package/dist/cjs/components/Panel/Panel.test.js +58 -41
  10. package/dist/cjs/components/Panel/PanelContent.js +41 -12
  11. package/dist/cjs/components/Panel/index.js +16 -17
  12. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +84 -108
  13. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +87 -92
  14. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +194 -0
  15. package/dist/cjs/components/PanelDrawer/PanelPreview.js +48 -0
  16. package/dist/cjs/components/PanelDrawer/index.js +28 -0
  17. package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +86 -0
  18. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +121 -39
  19. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +74 -88
  20. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +120 -38
  21. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +42 -27
  22. package/dist/cjs/components/TimeRangeControls/index.js +16 -17
  23. package/dist/cjs/components/Variables/Variable.js +195 -36
  24. package/dist/cjs/components/Variables/VariableEditor.js +207 -0
  25. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +236 -0
  26. package/dist/cjs/components/Variables/VariableEditorForm/index.js +28 -0
  27. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +88 -0
  28. package/dist/cjs/components/Variables/VariableList.js +81 -13
  29. package/dist/cjs/components/Variables/index.js +18 -18
  30. package/dist/cjs/components/index.js +21 -21
  31. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +70 -0
  32. package/dist/cjs/context/DashboardProvider/common.js +18 -0
  33. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +71 -0
  34. package/dist/cjs/context/DashboardProvider/index.js +29 -0
  35. package/dist/cjs/context/DashboardProvider/layout-slice.js +200 -0
  36. package/dist/cjs/context/DashboardProvider/panel-editing-slice.js +156 -0
  37. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +38 -0
  38. package/dist/cjs/context/DatasourceStoreProvider.js +170 -0
  39. package/dist/cjs/context/QueryStringProvider.js +69 -15
  40. package/dist/cjs/context/TemplateVariableProvider.js +135 -136
  41. package/dist/cjs/context/TimeRangeProvider.js +79 -30
  42. package/dist/cjs/context/index.js +20 -22
  43. package/dist/cjs/css/styles.js +43 -39
  44. package/dist/cjs/index.js +19 -20
  45. package/dist/cjs/test/dashboard-provider.js +51 -0
  46. package/dist/cjs/test/index.js +18 -18
  47. package/dist/cjs/test/plugin-registry.js +52 -25
  48. package/dist/cjs/test/render.js +25 -22
  49. package/dist/cjs/test/setup-tests.js +4 -2
  50. package/dist/cjs/test/testDashboard.js +203 -107
  51. package/dist/cjs/utils/functions.js +9 -5
  52. package/dist/cjs/views/ViewDashboard/DashboardApp.js +49 -23
  53. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +62 -31
  54. package/dist/cjs/views/ViewDashboard/index.js +16 -17
  55. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +165 -0
  56. package/dist/cjs/views/index.js +16 -17
  57. package/dist/components/Dashboard.d.ts +1 -4
  58. package/dist/components/Dashboard.d.ts.map +1 -1
  59. package/dist/components/Dashboard.js +34 -1
  60. package/dist/components/Dashboard.js.map +1 -0
  61. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  62. package/dist/components/DashboardToolbar.js +154 -1
  63. package/dist/components/DashboardToolbar.js.map +1 -0
  64. package/dist/components/GridLayout/GridItemContent.d.ts +3 -3
  65. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  66. package/dist/components/GridLayout/GridItemContent.js +35 -1
  67. package/dist/components/GridLayout/GridItemContent.js.map +1 -0
  68. package/dist/components/GridLayout/GridLayout.d.ts +2 -3
  69. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  70. package/dist/components/GridLayout/GridLayout.js +102 -1
  71. package/dist/components/GridLayout/GridLayout.js.map +1 -0
  72. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  73. package/dist/components/GridLayout/GridTitle.js +99 -1
  74. package/dist/components/GridLayout/GridTitle.js.map +1 -0
  75. package/dist/components/GridLayout/index.js +16 -1
  76. package/dist/components/GridLayout/index.js.map +1 -0
  77. package/dist/components/Panel/DeletePanelDialog.d.ts +5 -0
  78. package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -0
  79. package/dist/components/Panel/DeletePanelDialog.js +80 -0
  80. package/dist/components/Panel/DeletePanelDialog.js.map +1 -0
  81. package/dist/components/Panel/Panel.d.ts +1 -1
  82. package/dist/components/Panel/Panel.d.ts.map +1 -1
  83. package/dist/components/Panel/Panel.js +181 -1
  84. package/dist/components/Panel/Panel.js.map +1 -0
  85. package/dist/components/Panel/Panel.test.js +74 -1
  86. package/dist/components/Panel/Panel.test.js.map +1 -0
  87. package/dist/components/Panel/PanelContent.d.ts +5 -4
  88. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  89. package/dist/components/Panel/PanelContent.js +41 -1
  90. package/dist/components/Panel/PanelContent.js.map +1 -0
  91. package/dist/components/Panel/index.js +15 -1
  92. package/dist/components/Panel/index.js.map +1 -0
  93. package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
  94. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  95. package/dist/components/PanelDrawer/PanelDrawer.js +96 -1
  96. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
  97. package/dist/components/PanelDrawer/PanelDrawer.test.js +99 -1
  98. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
  99. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
  100. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
  101. package/dist/components/PanelDrawer/PanelEditorForm.js +184 -0
  102. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
  103. package/dist/components/PanelDrawer/PanelPreview.d.ts +4 -0
  104. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -0
  105. package/dist/components/PanelDrawer/PanelPreview.js +42 -0
  106. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -0
  107. package/dist/components/PanelDrawer/index.d.ts +2 -0
  108. package/dist/components/PanelDrawer/index.d.ts.map +1 -0
  109. package/dist/components/PanelDrawer/index.js +15 -0
  110. package/dist/components/PanelDrawer/index.js.map +1 -0
  111. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +4 -0
  112. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
  113. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +75 -0
  114. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
  115. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  116. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +131 -1
  117. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
  118. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +74 -1
  119. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
  120. package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
  121. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
  122. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
  123. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
  124. package/dist/components/TimeRangeControls/index.js +15 -1
  125. package/dist/components/TimeRangeControls/index.js.map +1 -0
  126. package/dist/components/Variables/Variable.d.ts.map +1 -1
  127. package/dist/components/Variables/Variable.js +210 -1
  128. package/dist/components/Variables/Variable.js.map +1 -0
  129. package/dist/components/Variables/VariableEditor.d.ts +8 -0
  130. package/dist/components/Variables/VariableEditor.d.ts.map +1 -0
  131. package/dist/components/Variables/VariableEditor.js +196 -0
  132. package/dist/components/Variables/VariableEditor.js.map +1 -0
  133. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +8 -0
  134. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
  135. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +225 -0
  136. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
  137. package/dist/components/Variables/VariableEditorForm/index.d.ts +2 -0
  138. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
  139. package/dist/components/Variables/VariableEditorForm/index.js +15 -0
  140. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
  141. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +21 -0
  142. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
  143. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +76 -0
  144. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
  145. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  146. package/dist/components/Variables/VariableList.js +84 -1
  147. package/dist/components/Variables/VariableList.js.map +1 -0
  148. package/dist/components/Variables/index.d.ts +1 -0
  149. package/dist/components/Variables/index.d.ts.map +1 -1
  150. package/dist/components/Variables/index.js +17 -1
  151. package/dist/components/Variables/index.js.map +1 -0
  152. package/dist/components/index.d.ts +1 -0
  153. package/dist/components/index.d.ts.map +1 -1
  154. package/dist/components/index.js +20 -1
  155. package/dist/components/index.js.map +1 -0
  156. package/dist/context/DashboardProvider/DashboardProvider.d.ts +23 -0
  157. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -0
  158. package/dist/context/DashboardProvider/DashboardProvider.js +52 -0
  159. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -0
  160. package/dist/context/DashboardProvider/common.d.ts +5 -0
  161. package/dist/context/DashboardProvider/common.d.ts.map +1 -0
  162. package/dist/context/DashboardProvider/common.js +17 -0
  163. package/dist/context/DashboardProvider/common.js.map +1 -0
  164. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +32 -0
  165. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -0
  166. package/dist/context/DashboardProvider/dashboard-provider-api.js +56 -0
  167. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -0
  168. package/dist/context/DashboardProvider/index.d.ts +3 -0
  169. package/dist/context/DashboardProvider/index.d.ts.map +1 -0
  170. package/dist/context/DashboardProvider/index.js +16 -0
  171. package/dist/context/DashboardProvider/index.js.map +1 -0
  172. package/dist/context/DashboardProvider/layout-slice.d.ts +57 -0
  173. package/dist/context/DashboardProvider/layout-slice.d.ts.map +1 -0
  174. package/dist/context/DashboardProvider/layout-slice.js +196 -0
  175. package/dist/context/DashboardProvider/layout-slice.js.map +1 -0
  176. package/dist/context/DashboardProvider/panel-editing-slice.d.ts +70 -0
  177. package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +1 -0
  178. package/dist/context/DashboardProvider/panel-editing-slice.js +152 -0
  179. package/dist/context/DashboardProvider/panel-editing-slice.js.map +1 -0
  180. package/dist/context/DashboardProvider/panel-group-slice.d.ts +15 -0
  181. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -0
  182. package/dist/context/DashboardProvider/panel-group-slice.js +32 -0
  183. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -0
  184. package/dist/context/DatasourceStoreProvider.d.ts +24 -0
  185. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
  186. package/dist/context/DatasourceStoreProvider.js +166 -0
  187. package/dist/context/DatasourceStoreProvider.js.map +1 -0
  188. package/dist/context/QueryStringProvider.js +40 -1
  189. package/dist/context/QueryStringProvider.js.map +1 -0
  190. package/dist/context/TemplateVariableProvider.d.ts +8 -3
  191. package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
  192. package/dist/context/TemplateVariableProvider.js +199 -1
  193. package/dist/context/TemplateVariableProvider.js.map +1 -0
  194. package/dist/context/TimeRangeProvider.js +72 -1
  195. package/dist/context/TimeRangeProvider.js.map +1 -0
  196. package/dist/context/index.d.ts +3 -4
  197. package/dist/context/index.d.ts.map +1 -1
  198. package/dist/context/index.js +19 -1
  199. package/dist/context/index.js.map +1 -0
  200. package/dist/css/styles.js +186 -1
  201. package/dist/css/styles.js.map +1 -0
  202. package/dist/index.js +17 -1
  203. package/dist/index.js.map +1 -0
  204. package/dist/test/dashboard-provider.d.ts +19 -0
  205. package/dist/test/dashboard-provider.d.ts.map +1 -0
  206. package/dist/test/dashboard-provider.js +40 -0
  207. package/dist/test/dashboard-provider.js.map +1 -0
  208. package/dist/test/index.d.ts +1 -0
  209. package/dist/test/index.d.ts.map +1 -1
  210. package/dist/test/index.js +17 -1
  211. package/dist/test/index.js.map +1 -0
  212. package/dist/test/plugin-registry.d.ts +3 -4
  213. package/dist/test/plugin-registry.d.ts.map +1 -1
  214. package/dist/test/plugin-registry.js +74 -1
  215. package/dist/test/plugin-registry.js.map +1 -0
  216. package/dist/test/render.d.ts +1 -2
  217. package/dist/test/render.d.ts.map +1 -1
  218. package/dist/test/render.js +34 -1
  219. package/dist/test/render.js.map +1 -0
  220. package/dist/test/setup-tests.js +18 -1
  221. package/dist/test/setup-tests.js.map +1 -0
  222. package/dist/test/testDashboard.d.ts.map +1 -1
  223. package/dist/test/testDashboard.js +286 -1
  224. package/dist/test/testDashboard.js.map +1 -0
  225. package/dist/utils/functions.js +17 -1
  226. package/dist/utils/functions.js.map +1 -0
  227. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  228. package/dist/views/ViewDashboard/DashboardApp.js +55 -1
  229. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
  230. package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -0
  231. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  232. package/dist/views/ViewDashboard/ViewDashboard.js +79 -1
  233. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
  234. package/dist/views/ViewDashboard/index.js +15 -1
  235. package/dist/views/ViewDashboard/index.js.map +1 -0
  236. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +2 -0
  237. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +1 -0
  238. package/dist/views/ViewDashboard/tests/panelGroups.test.js +158 -0
  239. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -0
  240. package/dist/views/index.js +15 -1
  241. package/dist/views/index.js.map +1 -0
  242. package/package.json +13 -7
  243. package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
  244. package/dist/cjs/context/DashboardAppSlice.js +0 -45
  245. package/dist/cjs/context/DashboardProvider.js +0 -98
  246. package/dist/cjs/context/LayoutsSlice.js +0 -42
  247. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
  248. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
  249. package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
  250. package/dist/context/DashboardAppSlice.d.ts +0 -26
  251. package/dist/context/DashboardAppSlice.d.ts.map +0 -1
  252. package/dist/context/DashboardAppSlice.js +0 -1
  253. package/dist/context/DashboardProvider.d.ts +0 -34
  254. package/dist/context/DashboardProvider.d.ts.map +0 -1
  255. package/dist/context/DashboardProvider.js +0 -1
  256. package/dist/context/LayoutsSlice.d.ts +0 -12
  257. package/dist/context/LayoutsSlice.d.ts.map +0 -1
  258. package/dist/context/LayoutsSlice.js +0 -1
@@ -1,9 +1,3 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const jsx_runtime_1 = require("react/jsx-runtime");
7
1
  // Copyright 2022 The Perses Authors
8
2
  // Licensed under the Apache License, Version 2.0 (the "License");
9
3
  // you may not use this file except in compliance with the License.
@@ -16,36 +10,57 @@ const jsx_runtime_1 = require("react/jsx-runtime");
16
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
11
  // See the License for the specific language governing permissions and
18
12
  // limitations under the License.
19
- const user_event_1 = __importDefault(require("@testing-library/user-event"));
20
- const core_1 = require("@perses-dev/core");
21
- const react_1 = require("@testing-library/react");
22
- const test_1 = require("../../test");
23
- const testDashboard_1 = __importDefault(require("../../test/testDashboard"));
24
- const context_1 = require("../../context");
25
- const TimeRangeControls_1 = require("./TimeRangeControls");
26
- describe('TimeRangeControls', () => {
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 _core = require("@perses-dev/core");
20
+ const _react = require("@testing-library/react");
21
+ const _test = require("../../test");
22
+ const _testDashboard = /*#__PURE__*/ _interopRequireDefault(require("../../test/testDashboard"));
23
+ const _context = require("../../context");
24
+ const _timeRangeControls = require("./TimeRangeControls");
25
+ function _interopRequireDefault(obj) {
26
+ return obj && obj.__esModule ? obj : {
27
+ default: obj
28
+ };
29
+ }
30
+ describe('TimeRangeControls', ()=>{
27
31
  let initialState;
28
- beforeEach(() => {
32
+ beforeEach(()=>{
29
33
  initialState = {
30
- dashboardSpec: testDashboard_1.default.spec,
34
+ dashboardSpec: _testDashboard.default.spec
31
35
  };
32
36
  });
33
- const renderTimeRangeControls = () => {
37
+ const renderTimeRangeControls = ()=>{
34
38
  const queryString = new URLSearchParams();
35
- const defaultTimeRange = (0, core_1.getDefaultTimeRange)(initialState.dashboardSpec.duration, queryString);
36
- (0, test_1.renderWithContext)((0, jsx_runtime_1.jsx)(context_1.QueryStringProvider, { queryString: queryString, children: (0, jsx_runtime_1.jsx)(context_1.DashboardProvider, { initialState: initialState, children: (0, jsx_runtime_1.jsx)(context_1.TimeRangeProvider, { initialTimeRange: defaultTimeRange, children: (0, jsx_runtime_1.jsx)(TimeRangeControls_1.TimeRangeControls, {}) }) }) }));
39
+ const defaultTimeRange = (0, _core.getDefaultTimeRange)(initialState.dashboardSpec.duration, queryString);
40
+ (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.QueryStringProvider, {
41
+ queryString: queryString,
42
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.DashboardProvider, {
43
+ initialState: initialState,
44
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.TimeRangeProvider, {
45
+ initialTimeRange: defaultTimeRange,
46
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_timeRangeControls.TimeRangeControls, {})
47
+ })
48
+ })
49
+ }));
37
50
  };
38
- it('should render correct initial relative time shortcut', async () => {
51
+ it('should render correct initial relative time shortcut', async ()=>{
39
52
  renderTimeRangeControls();
40
- expect(react_1.screen.getByText('Last 1 day')).toBeInTheDocument();
53
+ expect(_react.screen.getByText('Last 1 day')).toBeInTheDocument();
41
54
  });
42
- it('should be able to select the first option', () => {
55
+ it('should be able to select the first option', ()=>{
43
56
  renderTimeRangeControls();
44
- const dateButton = react_1.screen.getByRole('button');
45
- user_event_1.default.click(dateButton);
46
- const firstOption = react_1.screen.getByRole('option', { name: 'Last 5 minutes' });
47
- user_event_1.default.click(firstOption);
57
+ const dateButton = _react.screen.getByRole('button');
58
+ _userEvent.default.click(dateButton);
59
+ const firstOption = _react.screen.getByRole('option', {
60
+ name: 'Last 5 minutes'
61
+ });
62
+ _userEvent.default.click(firstOption);
48
63
  expect(dateButton).toHaveTextContent(/5 minutes/i);
49
64
  });
50
- // TODO: add additional tests for absolute time selection, other inputs, form validation, etc.
65
+ // TODO: add additional tests for absolute time selection, other inputs, form validation, etc.
51
66
  });
@@ -1,4 +1,3 @@
1
- "use strict";
2
1
  // Copyright 2022 The Perses Authors
3
2
  // Licensed under the Apache License, Version 2.0 (the "License");
4
3
  // you may not use this file except in compliance with the License.
@@ -11,19 +10,19 @@
11
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
11
  // See the License for the specific language governing permissions and
13
12
  // limitations under the License.
14
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
- if (k2 === undefined) k2 = k;
16
- var desc = Object.getOwnPropertyDescriptor(m, k);
17
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
- desc = { enumerable: true, get: function() { return m[k]; } };
19
- }
20
- Object.defineProperty(o, k2, desc);
21
- }) : (function(o, m, k, k2) {
22
- if (k2 === undefined) k2 = k;
23
- o[k2] = m[k];
24
- }));
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- __exportStar(require("./TimeRangeControls"), exports);
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./TimeRangeControls"), 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
+ }
@@ -1,7 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TemplateVariable = void 0;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
1
  // Copyright 2022 The Perses Authors
6
2
  // Licensed under the Apache License, Version 2.0 (the "License");
7
3
  // you may not use this file except in compliance with the License.
@@ -14,44 +10,207 @@ const jsx_runtime_1 = require("react/jsx-runtime");
14
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
11
  // See the License for the specific language governing permissions and
16
12
  // limitations under the License.
17
- const react_1 = require("react");
18
- const material_1 = require("@mui/material");
19
- const mdi_material_ui_1 = require("mdi-material-ui");
20
- const context_1 = require("../../context");
21
- function TemplateVariable({ name }) {
22
- var _a;
23
- const ctx = (0, context_1.useTemplateVariable)(name);
24
- const kind = (_a = ctx.definition) === null || _a === void 0 ? void 0 : _a.kind;
25
- switch (kind) {
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TemplateVariable", {
18
+ enumerable: true,
19
+ get: ()=>TemplateVariable
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _material = require("@mui/material");
24
+ const _pluginSystem = require("@perses-dev/plugin-system");
25
+ const _reactQuery = require("@tanstack/react-query");
26
+ const _context = require("../../context");
27
+ function TemplateVariable({ name }) {
28
+ var ref;
29
+ const ctx = (0, _context.useTemplateVariable)(name);
30
+ const kind = (ref = ctx.definition) === null || ref === void 0 ? void 0 : ref.kind;
31
+ switch(kind){
26
32
  case 'TextVariable':
27
- return (0, jsx_runtime_1.jsx)(TextVariable, { name: name });
33
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(TextVariable, {
34
+ name: name
35
+ });
28
36
  case 'ListVariable':
29
- return (0, jsx_runtime_1.jsx)(ListVariable, { name: name });
37
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(ListVariable, {
38
+ name: name
39
+ });
30
40
  }
31
- return (0, jsx_runtime_1.jsxs)("div", { children: ["Unsupported Variable Kind: $", kind] });
41
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)("div", {
42
+ children: [
43
+ "Unsupported Variable Kind: $",
44
+ kind
45
+ ]
46
+ });
47
+ }
48
+ /**
49
+ * Returns a serialized string of the current state of variable values.
50
+ */ function getVariableValuesKey(v) {
51
+ return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
32
52
  }
33
- exports.TemplateVariable = TemplateVariable;
34
- function ListVariable({ name }) {
35
- var _a, _b, _c, _d;
36
- const ctx = (0, context_1.useTemplateVariable)(name);
53
+ function ListVariable({ name }) {
54
+ var ref, ref1, ref2, ref3;
55
+ const ctx = (0, _context.useTemplateVariable)(name);
37
56
  const definition = ctx.definition;
38
- const { setVariableValue, loadTemplateVariable } = (0, context_1.useTemplateVariableActions)();
39
- const allowMultiple = (definition === null || definition === void 0 ? void 0 : definition.options.allowMultiple) === true;
40
- (0, react_1.useEffect)(() => {
41
- loadTemplateVariable(name);
42
- }, [name, loadTemplateVariable]);
43
- let value = (_a = ctx.state) === null || _a === void 0 ? void 0 : _a.value;
57
+ const { data: variablePlugin } = (0, _pluginSystem.usePlugin)('Variable', definition.spec.plugin.kind);
58
+ const { setVariableValue , setVariableLoading , setVariableOptions } = (0, _context.useTemplateVariableActions)();
59
+ const datasourceStore = (0, _pluginSystem.useDatasourceStore)();
60
+ const spec = definition.spec.plugin.spec;
61
+ let dependsOnVariables;
62
+ if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
63
+ dependsOnVariables = variablePlugin.dependsOn(spec);
64
+ }
65
+ const variables = (0, _pluginSystem.useTemplateVariableValues)(dependsOnVariables);
66
+ const allowMultiple = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_multiple) === true;
67
+ const allowAllValue = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_all_value) === true;
68
+ var ref4;
69
+ const label = (ref4 = (ref = definition === null || definition === void 0 ? void 0 : definition.spec.display) === null || ref === void 0 ? void 0 : ref.label) !== null && ref4 !== void 0 ? ref4 : name;
70
+ let waitToLoad = false;
71
+ if (dependsOnVariables) {
72
+ waitToLoad = dependsOnVariables.some((v)=>{
73
+ var ref;
74
+ return (ref = variables[v]) === null || ref === void 0 ? void 0 : ref.loading;
75
+ });
76
+ }
77
+ const variablesValueKey = getVariableValuesKey(variables);
78
+ const variablesOptionsQuery = (0, _reactQuery.useQuery)([
79
+ name,
80
+ definition,
81
+ variablesValueKey
82
+ ], async ()=>{
83
+ const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
84
+ datasourceStore,
85
+ variables
86
+ }));
87
+ var ref;
88
+ return (ref = resp === null || resp === void 0 ? void 0 : resp.data) !== null && ref !== void 0 ? ref : [];
89
+ }, {
90
+ enabled: !!variablePlugin || waitToLoad
91
+ });
92
+ (0, _react.useEffect)(()=>{
93
+ setVariableLoading(name, variablesOptionsQuery.isFetching);
94
+ if (variablesOptionsQuery.data) {
95
+ setVariableOptions(name, variablesOptionsQuery.data);
96
+ }
97
+ }, [
98
+ variablesOptionsQuery,
99
+ name,
100
+ setVariableLoading,
101
+ setVariableOptions
102
+ ]);
103
+ let value = (ref1 = ctx.state) === null || ref1 === void 0 ? void 0 : ref1.value;
104
+ const options = (ref2 = ctx.state) === null || ref2 === void 0 ? void 0 : ref2.options;
105
+ const loading = (ref3 = ctx.state) === null || ref3 === void 0 ? void 0 : ref3.loading;
106
+ // Make sure value is an array if allowMultiple is true
44
107
  if (allowMultiple && !Array.isArray(value)) {
45
- value = [];
108
+ value = typeof value === 'string' ? [
109
+ value
110
+ ] : [];
46
111
  }
47
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, { display: 'flex', children: [(0, jsx_runtime_1.jsxs)(material_1.FormControl, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { id: name, children: name }), (0, jsx_runtime_1.jsx)(material_1.Select, { id: name, label: name, value: value, onChange: (e) => {
48
- setVariableValue(name, e.target.value);
49
- }, multiple: allowMultiple, children: (_c = (_b = ctx.state) === null || _b === void 0 ? void 0 : _b.options) === null || _c === void 0 ? void 0 : _c.map((option) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: option.value, children: option.label }, option.value))) }), ((_d = ctx.state) === null || _d === void 0 ? void 0 : _d.loading) && (0, jsx_runtime_1.jsx)(material_1.LinearProgress, {})] }), (0, jsx_runtime_1.jsx)(material_1.IconButton, { onClick: () => loadTemplateVariable(name), children: (0, jsx_runtime_1.jsx)(mdi_material_ui_1.Reload, {}) })] }));
112
+ const finalOptions = (0, _react.useMemo)(()=>{
113
+ let computedOptions = options ? [
114
+ ...options
115
+ ] : [];
116
+ // Add the all value if it's allowed
117
+ if (allowAllValue) {
118
+ computedOptions = [
119
+ {
120
+ value: _pluginSystem.DEFAULT_ALL_VALUE,
121
+ label: 'All'
122
+ },
123
+ ...computedOptions
124
+ ];
125
+ }
126
+ return computedOptions;
127
+ }, [
128
+ options,
129
+ allowAllValue
130
+ ]);
131
+ (0, _react.useEffect)(()=>{
132
+ const firstOption = finalOptions === null || finalOptions === void 0 ? void 0 : finalOptions[0];
133
+ const valueIsInOptions = Boolean(finalOptions.find((v)=>{
134
+ if (allowMultiple) {
135
+ return value.includes(v.value);
136
+ }
137
+ return value === v.value;
138
+ }));
139
+ // If there is no value but there are options, set the value to the first option.
140
+ if (!value && firstOption) {
141
+ setVariableValue(name, firstOption.value);
142
+ }
143
+ // If there is a value but it's not in the options, select the first value or set to null
144
+ if (value && !valueIsInOptions && !definition.spec.default_value) {
145
+ setVariableValue(name, (firstOption === null || firstOption === void 0 ? void 0 : firstOption.value) || null);
146
+ }
147
+ }, [
148
+ finalOptions,
149
+ setVariableValue,
150
+ value,
151
+ name,
152
+ allowMultiple
153
+ ]);
154
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
155
+ display: 'flex',
156
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
157
+ children: [
158
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
159
+ id: name,
160
+ children: label
161
+ }),
162
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Select, {
163
+ sx: {
164
+ minWidth: 100,
165
+ maxWidth: 250
166
+ },
167
+ id: name,
168
+ label: name,
169
+ value: value !== null && value !== void 0 ? value : '',
170
+ onChange: (e)=>{
171
+ // Must be selected
172
+ if (e.target.value === null || e.target.value.length === 0) {
173
+ if (allowAllValue) {
174
+ setVariableValue(name, _pluginSystem.DEFAULT_ALL_VALUE);
175
+ }
176
+ return;
177
+ }
178
+ setVariableValue(name, e.target.value);
179
+ },
180
+ multiple: allowMultiple,
181
+ children: [
182
+ loading && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
183
+ value: "loading",
184
+ disabled: true,
185
+ children: "Loading"
186
+ }),
187
+ finalOptions.map((option)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
188
+ value: option.value,
189
+ children: option.label
190
+ }, option.value))
191
+ ]
192
+ }),
193
+ loading && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.LinearProgress, {})
194
+ ]
195
+ })
196
+ });
50
197
  }
51
- function TextVariable({ name }) {
52
- const { state } = (0, context_1.useTemplateVariable)(name);
53
- const s = (0, context_1.useTemplateVariableStore)();
54
- const setVariableValue = s.setVariableValue;
55
- const ref = (0, react_1.useRef)(null);
56
- return ((0, jsx_runtime_1.jsx)(material_1.TextField, { ref: ref, defaultValue: state === null || state === void 0 ? void 0 : state.value, onBlur: (e) => setVariableValue(name, e.target.value), placeholder: name, label: name }));
198
+ function TextVariable({ name }) {
199
+ const { state } = (0, _context.useTemplateVariable)(name);
200
+ var ref;
201
+ const [tempValue, setTempValue] = (0, _react.useState)((ref = state === null || state === void 0 ? void 0 : state.value) !== null && ref !== void 0 ? ref : '');
202
+ const { setVariableValue } = (0, _context.useTemplateVariableActions)();
203
+ (0, _react.useEffect)(()=>{
204
+ var ref;
205
+ setTempValue((ref = state === null || state === void 0 ? void 0 : state.value) !== null && ref !== void 0 ? ref : '');
206
+ }, [
207
+ state === null || state === void 0 ? void 0 : state.value
208
+ ]);
209
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
210
+ value: tempValue,
211
+ onChange: (e)=>setTempValue(e.target.value),
212
+ onBlur: ()=>setVariableValue(name, tempValue),
213
+ placeholder: name,
214
+ label: name
215
+ });
57
216
  }
@@ -0,0 +1,207 @@
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, "VariableEditor", {
18
+ enumerable: true,
19
+ get: ()=>VariableEditor
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _material = require("@mui/material");
24
+ const _useImmer = require("use-immer");
25
+ const _pencil = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Pencil"));
26
+ const _trashCan = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/TrashCan"));
27
+ const _variableEditorForm = require("./VariableEditorForm");
28
+ function _interopRequireDefault(obj) {
29
+ return obj && obj.__esModule ? obj : {
30
+ default: obj
31
+ };
32
+ }
33
+ function VariableEditor(props) {
34
+ const [variableDefinitions, setVariableDefinitions] = (0, _useImmer.useImmer)(props.variableDefinitions);
35
+ const [variableEditIdx, setVariableEditIdx] = (0, _react.useState)(null);
36
+ const currentEditingVariableDefinition = typeof variableEditIdx === 'number' && variableDefinitions[variableEditIdx];
37
+ const removeVariable = (index)=>{
38
+ setVariableDefinitions((draft)=>{
39
+ draft.splice(index, 1);
40
+ });
41
+ };
42
+ const addVariable = ()=>{
43
+ setVariableDefinitions((draft)=>{
44
+ draft.push({
45
+ kind: 'TextVariable',
46
+ spec: {
47
+ name: 'NewVariable',
48
+ value: ''
49
+ }
50
+ });
51
+ });
52
+ };
53
+ const toggleVariableVisibility = (index, visible)=>{
54
+ setVariableDefinitions((draft)=>{
55
+ const v = draft[index];
56
+ if (!v) {
57
+ return;
58
+ }
59
+ if (!v.spec.display) {
60
+ v.spec.display = {
61
+ hidden: false
62
+ };
63
+ }
64
+ v.spec.display.hidden = visible === false;
65
+ });
66
+ };
67
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
68
+ p: 4,
69
+ children: [
70
+ currentEditingVariableDefinition && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
71
+ children: [
72
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
73
+ variant: "h3",
74
+ mb: 2,
75
+ children: "Edit Variable"
76
+ }),
77
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variableEditorForm.VariableEditForm, {
78
+ initialVariableDefinition: currentEditingVariableDefinition,
79
+ onChange: (definition)=>{
80
+ setVariableDefinitions((draft)=>{
81
+ draft[variableEditIdx] = definition;
82
+ setVariableEditIdx(null);
83
+ });
84
+ },
85
+ onCancel: ()=>setVariableEditIdx(null)
86
+ })
87
+ ]
88
+ }),
89
+ !currentEditingVariableDefinition && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
90
+ children: [
91
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
92
+ direction: "row",
93
+ spacing: 1,
94
+ justifyContent: "end",
95
+ children: [
96
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
97
+ onClick: ()=>{
98
+ props.onCancel();
99
+ },
100
+ children: "Cancel"
101
+ }),
102
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
103
+ disabled: props.variableDefinitions === variableDefinitions,
104
+ variant: "contained",
105
+ onClick: ()=>{
106
+ props.onChange(variableDefinitions);
107
+ },
108
+ children: "Apply Changes"
109
+ })
110
+ ]
111
+ }),
112
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
113
+ variant: "h3",
114
+ mb: 2,
115
+ children: "Variable List"
116
+ }),
117
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
118
+ spacing: 2,
119
+ children: [
120
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableContainer, {
121
+ component: _material.Paper,
122
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Table, {
123
+ sx: {
124
+ minWidth: 650
125
+ },
126
+ "aria-label": "simple table",
127
+ children: [
128
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableHead, {
129
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.TableRow, {
130
+ children: [
131
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
132
+ children: "Visibility"
133
+ }),
134
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
135
+ children: "Variable Name"
136
+ }),
137
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
138
+ children: "Variable Type"
139
+ }),
140
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
141
+ align: "right",
142
+ children: "Action"
143
+ })
144
+ ]
145
+ })
146
+ }),
147
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableBody, {
148
+ children: variableDefinitions.map((v, idx)=>{
149
+ var ref;
150
+ /*#__PURE__*/ return (0, _jsxRuntime.jsxs)(_material.TableRow, {
151
+ children: [
152
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
153
+ component: "th",
154
+ scope: "row",
155
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Switch, {
156
+ checked: ((ref = v.spec.display) === null || ref === void 0 ? void 0 : ref.hidden) !== true,
157
+ onChange: (e)=>{
158
+ toggleVariableVisibility(idx, e.target.checked);
159
+ }
160
+ })
161
+ }),
162
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
163
+ component: "th",
164
+ scope: "row",
165
+ sx: {
166
+ fontWeight: 'bold'
167
+ },
168
+ children: v.spec.name
169
+ }),
170
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
171
+ children: v.kind
172
+ }),
173
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.TableCell, {
174
+ align: "right",
175
+ children: [
176
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
177
+ onClick: ()=>setVariableEditIdx(idx),
178
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pencil.default, {})
179
+ }),
180
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
181
+ onClick: ()=>removeVariable(idx),
182
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_trashCan.default, {})
183
+ })
184
+ ]
185
+ })
186
+ ]
187
+ }, v.spec.name);
188
+ })
189
+ })
190
+ ]
191
+ })
192
+ }),
193
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
194
+ display: "flex",
195
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
196
+ onClick: addVariable,
197
+ variant: "contained",
198
+ children: "Add New Variable"
199
+ })
200
+ })
201
+ ]
202
+ })
203
+ ]
204
+ })
205
+ ]
206
+ });
207
+ }