@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 +1,74 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import{screen}from"@testing-library/react";import userEvent from"@testing-library/user-event";import produce from"immer";import*as dashboardAppSlice from"../../context/DashboardAppSlice";import*as layoutsSlice from"../../context/LayoutsSlice";import{renderWithContext}from"../../test";import testDashboard from"../../test/testDashboard";import PanelGroupDialog from"./PanelGroupDialog";const dashboardApp={panelDrawer:void 0,openPanelDrawer:jest.fn(),closePanelDrawer:jest.fn(),panelGroupDialog:{groupIndex:void 0},openPanelGroupDialog:jest.fn(),closePanelGroupDialog:jest.fn()},updateLayout=jest.fn();jest.spyOn(layoutsSlice,"useLayouts").mockReturnValue({updateLayout,addItemToLayout:jest.fn(),layouts:testDashboard.spec.layouts}),describe("Add Panel Group",(()=>{beforeEach((()=>{jest.clearAllMocks()})),it("should add new panel group",(()=>{jest.spyOn(dashboardAppSlice,"useDashboardApp").mockReturnValue(dashboardApp),renderWithContext(_jsx(PanelGroupDialog,{}));const e=screen.getByLabelText(/Name/);userEvent.type(e,"New Panel Group"),userEvent.click(screen.getByText("Add")),expect(updateLayout).toHaveBeenCalledWith({kind:"Grid",spec:{display:{title:"New Panel Group",collapse:{open:!0}},items:[]}},void 0)})),it("should edit existing panel group",(()=>{jest.spyOn(dashboardAppSlice,"useDashboardApp").mockReturnValue({...dashboardApp,panelGroupDialog:{groupIndex:0}}),renderWithContext(_jsx(PanelGroupDialog,{}));const e=screen.getByLabelText(/Name/);userEvent.type(e,"New Name"),userEvent.click(screen.getByText("Apply")),expect(updateLayout).toHaveBeenCalledWith(produce(testDashboard.spec.layouts[0],(e=>{e.spec.display.title+="New Name",e.spec.display.collapse={open:!1}})),0)}))}));
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
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { screen } from '@testing-library/react';
15
+ import userEvent from '@testing-library/user-event';
16
+ import { act } from 'react-dom/test-utils';
17
+ import { DashboardProvider } from '../../context';
18
+ import { createDashboardProviderSpy, getTestDashboard, renderWithContext } from '../../test';
19
+ import testDashboard from '../../test/testDashboard';
20
+ import PanelGroupDialog from './PanelGroupDialog';
21
+ describe('Add Panel Group', ()=>{
22
+ const renderDialog = ()=>{
23
+ const { store , DashboardProviderSpy } = createDashboardProviderSpy();
24
+ renderWithContext(/*#__PURE__*/ _jsxs(DashboardProvider, {
25
+ initialState: {
26
+ dashboardSpec: getTestDashboard().spec,
27
+ isEditMode: true
28
+ },
29
+ children: [
30
+ /*#__PURE__*/ _jsx(DashboardProviderSpy, {}),
31
+ /*#__PURE__*/ _jsx(PanelGroupDialog, {})
32
+ ]
33
+ }));
34
+ const { value: storeApi } = store;
35
+ if (storeApi === undefined) {
36
+ throw new Error('Expected dashboard store to be set after initial render');
37
+ }
38
+ return storeApi;
39
+ };
40
+ it('should add new panel group', async ()=>{
41
+ const storeApi = renderDialog();
42
+ // Open the dialog for a new panel group
43
+ act(()=>storeApi.getState().openPanelGroupDialog());
44
+ const nameInput = await screen.findByLabelText(/Name/);
45
+ userEvent.type(nameInput, 'New Panel Group');
46
+ userEvent.click(screen.getByText('Add'));
47
+ const layouts = storeApi.getState().layouts;
48
+ expect(layouts).toContainEqual({
49
+ id: 3,
50
+ title: 'New Panel Group',
51
+ isCollapsed: false,
52
+ items: []
53
+ });
54
+ });
55
+ it('should edit existing panel group', async ()=>{
56
+ var ref;
57
+ const storeApi = renderDialog();
58
+ // Open the dialog for an existing panel group
59
+ act(()=>storeApi.getState().openPanelGroupDialog(0));
60
+ const nameInput = await screen.findByLabelText(/Name/);
61
+ userEvent.clear(nameInput);
62
+ userEvent.type(nameInput, 'New Name');
63
+ userEvent.click(screen.getByText('Apply'));
64
+ const layouts = storeApi.getState().layouts;
65
+ expect(layouts).toContainEqual({
66
+ id: 0,
67
+ title: 'New Name',
68
+ isCollapsed: false,
69
+ items: (ref = testDashboard.spec.layouts[0]) === null || ref === void 0 ? void 0 : ref.spec.items
70
+ });
71
+ });
72
+ });
73
+
74
+ //# sourceMappingURL=PanelGroupDialog.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/PanelGroupDialog/PanelGroupDialog.test.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { screen } from '@testing-library/react';\nimport userEvent from '@testing-library/user-event';\nimport { act } from 'react-dom/test-utils';\nimport { DashboardProvider } from '../../context';\nimport { createDashboardProviderSpy, getTestDashboard, renderWithContext } from '../../test';\nimport testDashboard from '../../test/testDashboard';\nimport PanelGroupDialog from './PanelGroupDialog';\n\ndescribe('Add Panel Group', () => {\n const renderDialog = () => {\n const { store, DashboardProviderSpy } = createDashboardProviderSpy();\n\n renderWithContext(\n <DashboardProvider initialState={{ dashboardSpec: getTestDashboard().spec, isEditMode: true }}>\n <DashboardProviderSpy />\n <PanelGroupDialog />\n </DashboardProvider>\n );\n\n const { value: storeApi } = store;\n if (storeApi === undefined) {\n throw new Error('Expected dashboard store to be set after initial render');\n }\n\n return storeApi;\n };\n\n it('should add new panel group', async () => {\n const storeApi = renderDialog();\n\n // Open the dialog for a new panel group\n act(() => storeApi.getState().openPanelGroupDialog());\n\n const nameInput = await screen.findByLabelText(/Name/);\n userEvent.type(nameInput, 'New Panel Group');\n userEvent.click(screen.getByText('Add'));\n\n const layouts = storeApi.getState().layouts;\n expect(layouts).toContainEqual({\n id: 3,\n title: 'New Panel Group',\n isCollapsed: false,\n items: [],\n });\n });\n\n it('should edit existing panel group', async () => {\n const storeApi = renderDialog();\n\n // Open the dialog for an existing panel group\n act(() => storeApi.getState().openPanelGroupDialog(0));\n\n const nameInput = await screen.findByLabelText(/Name/);\n userEvent.clear(nameInput);\n userEvent.type(nameInput, 'New Name');\n userEvent.click(screen.getByText('Apply'));\n\n const layouts = storeApi.getState().layouts;\n expect(layouts).toContainEqual({\n id: 0,\n title: 'New Name',\n isCollapsed: false,\n items: testDashboard.spec.layouts[0]?.spec.items,\n });\n });\n});\n"],"names":["screen","userEvent","act","DashboardProvider","createDashboardProviderSpy","getTestDashboard","renderWithContext","testDashboard","PanelGroupDialog","describe","renderDialog","store","DashboardProviderSpy","initialState","dashboardSpec","spec","isEditMode","value","storeApi","undefined","Error","it","getState","openPanelGroupDialog","nameInput","findByLabelText","type","click","getByText","layouts","expect","toContainEqual","id","title","isCollapsed","items","clear"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,MAAM,QAAQ,wBAAwB,CAAC;AAChD,OAAOC,SAAS,MAAM,6BAA6B,CAAC;AACpD,SAASC,GAAG,QAAQ,sBAAsB,CAAC;AAC3C,SAASC,iBAAiB,QAAQ,eAAe,CAAC;AAClD,SAASC,0BAA0B,EAAEC,gBAAgB,EAAEC,iBAAiB,QAAQ,YAAY,CAAC;AAC7F,OAAOC,aAAa,MAAM,0BAA0B,CAAC;AACrD,OAAOC,gBAAgB,MAAM,oBAAoB,CAAC;AAElDC,QAAQ,CAAC,iBAAiB,EAAE,IAAM;IAChC,MAAMC,YAAY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C,EAAE,UAAY;YAgBxCd,GAA6B;QAftC,MAAMW,QAAQ,GAAGR,YAAY,EAAE,AAAC;QAEhC,8CAA8C;QAC9CR,GAAG,CAAC,IAAMgB,QAAQ,CAACI,QAAQ,EAAE,CAACC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC;QAEvD,MAAMC,SAAS,GAAG,MAAMxB,MAAM,CAACyB,eAAe,QAAQ,AAAC;QACvDxB,SAAS,CAACmC,KAAK,CAACZ,SAAS,CAAC,CAAC;QAC3BvB,SAAS,CAACyB,IAAI,CAACF,SAAS,EAAE,UAAU,CAAC,CAAC;QACtCvB,SAAS,CAAC0B,KAAK,CAAC3B,MAAM,CAAC4B,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAE3C,MAAMC,OAAO,GAAGX,QAAQ,CAACI,QAAQ,EAAE,CAACO,OAAO,AAAC;QAC5CC,MAAM,CAACD,OAAO,CAAC,CAACE,cAAc,CAAC;YAC7BC,EAAE,EAAE,CAAC;YACLC,KAAK,EAAE,UAAU;YACjBC,WAAW,EAAE,KAAK;YAClBC,KAAK,EAAE5B,CAAAA,GAA6B,GAA7BA,aAAa,CAACQ,IAAI,CAACc,OAAO,CAAC,CAAC,CAAC,cAA7BtB,GAA6B,WAAM,GAAnCA,KAAAA,CAAmC,GAAnCA,GAA6B,CAAEQ,IAAI,CAACoB,KAAK;SACjD,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1 +1,137 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useRef,useState}from"react";import{Box,FormControl,Popover,Stack}from"@mui/material";import{AbsoluteTimePicker,TimeRangeSelector}from"@perses-dev/components";import{getDefaultTimeRange}from"@perses-dev/core";import{useTimeRange,useQueryString}from"@perses-dev/plugin-system";import{useDashboard}from"../../context";export const TIME_OPTIONS=[{value:{pastDuration:"5m"},display:"Last 5 minutes"},{value:{pastDuration:"15m"},display:"Last 15 minutes"},{value:{pastDuration:"30m"},display:"Last 30 minutes"},{value:{pastDuration:"1h"},display:"Last 1 hour"},{value:{pastDuration:"6h"},display:"Last 6 hours"},{value:{pastDuration:"12h"},display:"Last 12 hours"},{value:{pastDuration:"24h"},display:"Last 1 day"},{value:{pastDuration:"7d"},display:"Last 7 days"},{value:{pastDuration:"14d"},display:"Last 14 days"}];export function TimeRangeControls(){const{timeRange:e,setTimeRange:t}=useTimeRange(),{dashboard:a}=useDashboard(),{queryString:s}=useQueryString(),r=getDefaultTimeRange(a.duration,s),[o,i]=useState(r),[n,u]=useState(!1),l=useRef();return _jsxs(Stack,{direction:"row",spacing:1,children:[_jsx(Popover,{anchorEl:l.current,anchorOrigin:{vertical:"bottom",horizontal:"center"},open:n,onClose:()=>u(!1),sx:e=>({padding:e.spacing(2)}),children:_jsx(AbsoluteTimePicker,{initialTimeRange:e,onChange:e=>{t(e),i(e),u(!1)}})}),_jsx(FormControl,{fullWidth:!0,children:_jsx(Box,{ref:l,children:_jsx(TimeRangeSelector,{timeOptions:TIME_OPTIONS,value:o,onSelectChange:e=>{const a={pastDuration:e.target.value,end:new Date};t(a),i(a),u(!1)},onCustomClick:()=>{u(!0)}})})})]})}
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
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { useRef, useState } from 'react';
15
+ import { Box, FormControl, Popover, Stack } from '@mui/material';
16
+ import { AbsoluteTimePicker, TimeRangeSelector } from '@perses-dev/components';
17
+ import { getDefaultTimeRange } from '@perses-dev/core';
18
+ import { useTimeRange, useQueryString } from '@perses-dev/plugin-system';
19
+ import { useDefaultTimeRange } from '../../context';
20
+ // TODO: add time shortcut if one does not match duration
21
+ export const TIME_OPTIONS = [
22
+ {
23
+ value: {
24
+ pastDuration: '5m'
25
+ },
26
+ display: 'Last 5 minutes'
27
+ },
28
+ {
29
+ value: {
30
+ pastDuration: '15m'
31
+ },
32
+ display: 'Last 15 minutes'
33
+ },
34
+ {
35
+ value: {
36
+ pastDuration: '30m'
37
+ },
38
+ display: 'Last 30 minutes'
39
+ },
40
+ {
41
+ value: {
42
+ pastDuration: '1h'
43
+ },
44
+ display: 'Last 1 hour'
45
+ },
46
+ {
47
+ value: {
48
+ pastDuration: '6h'
49
+ },
50
+ display: 'Last 6 hours'
51
+ },
52
+ {
53
+ value: {
54
+ pastDuration: '12h'
55
+ },
56
+ display: 'Last 12 hours'
57
+ },
58
+ {
59
+ value: {
60
+ pastDuration: '24h'
61
+ },
62
+ display: 'Last 1 day'
63
+ },
64
+ {
65
+ value: {
66
+ pastDuration: '7d'
67
+ },
68
+ display: 'Last 7 days'
69
+ },
70
+ {
71
+ value: {
72
+ pastDuration: '14d'
73
+ },
74
+ display: 'Last 14 days'
75
+ }
76
+ ];
77
+ export function TimeRangeControls() {
78
+ const { timeRange , setTimeRange } = useTimeRange();
79
+ const dashboardDefaultTimeRange = useDefaultTimeRange();
80
+ const { queryString } = useQueryString();
81
+ const defaultTimeRange = getDefaultTimeRange(dashboardDefaultTimeRange, queryString);
82
+ // selected form value can be relative or absolute, timeRange from plugin-system is only absolute
83
+ const [selectedTimeRange, setSelectedTimeRange] = useState(defaultTimeRange);
84
+ const [showCustomDateSelector, setShowCustomDateSelector] = useState(false);
85
+ const anchorEl = useRef();
86
+ return /*#__PURE__*/ _jsxs(Stack, {
87
+ direction: "row",
88
+ spacing: 1,
89
+ children: [
90
+ /*#__PURE__*/ _jsx(Popover, {
91
+ anchorEl: anchorEl.current,
92
+ anchorOrigin: {
93
+ vertical: 'bottom',
94
+ horizontal: 'center'
95
+ },
96
+ open: showCustomDateSelector,
97
+ onClose: ()=>setShowCustomDateSelector(false),
98
+ sx: (theme)=>({
99
+ padding: theme.spacing(2)
100
+ }),
101
+ children: /*#__PURE__*/ _jsx(AbsoluteTimePicker, {
102
+ initialTimeRange: timeRange,
103
+ onChange: (timeRange)=>{
104
+ setTimeRange(timeRange);
105
+ setSelectedTimeRange(timeRange);
106
+ setShowCustomDateSelector(false);
107
+ }
108
+ })
109
+ }),
110
+ /*#__PURE__*/ _jsx(FormControl, {
111
+ fullWidth: true,
112
+ children: /*#__PURE__*/ _jsx(Box, {
113
+ ref: anchorEl,
114
+ children: /*#__PURE__*/ _jsx(TimeRangeSelector, {
115
+ timeOptions: TIME_OPTIONS,
116
+ value: selectedTimeRange,
117
+ onSelectChange: (event)=>{
118
+ const duration = event.target.value;
119
+ const relativeTimeInput = {
120
+ pastDuration: duration,
121
+ end: new Date()
122
+ };
123
+ setTimeRange(relativeTimeInput);
124
+ setSelectedTimeRange(relativeTimeInput);
125
+ setShowCustomDateSelector(false);
126
+ },
127
+ onCustomClick: ()=>{
128
+ setShowCustomDateSelector(true);
129
+ }
130
+ })
131
+ })
132
+ })
133
+ ]
134
+ });
135
+ }
136
+
137
+ //# sourceMappingURL=TimeRangeControls.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useRef, useState } from 'react';\nimport { Box, FormControl, Popover, Stack } from '@mui/material';\nimport { AbsoluteTimePicker, TimeRangeSelector, TimeOption } from '@perses-dev/components';\nimport {\n DurationString,\n RelativeTimeRange,\n AbsoluteTimeRange,\n TimeRangeValue,\n getDefaultTimeRange,\n} from '@perses-dev/core';\nimport { useTimeRange, useQueryString } from '@perses-dev/plugin-system';\nimport { useDefaultTimeRange } from '../../context';\n\n// TODO: add time shortcut if one does not match duration\nexport const TIME_OPTIONS: TimeOption[] = [\n { value: { pastDuration: '5m' }, display: 'Last 5 minutes' },\n { value: { pastDuration: '15m' }, display: 'Last 15 minutes' },\n { value: { pastDuration: '30m' }, display: 'Last 30 minutes' },\n { value: { pastDuration: '1h' }, display: 'Last 1 hour' },\n { value: { pastDuration: '6h' }, display: 'Last 6 hours' },\n { value: { pastDuration: '12h' }, display: 'Last 12 hours' },\n { value: { pastDuration: '24h' }, display: 'Last 1 day' },\n { value: { pastDuration: '7d' }, display: 'Last 7 days' },\n { value: { pastDuration: '14d' }, display: 'Last 14 days' },\n];\n\nexport function TimeRangeControls() {\n const { timeRange, setTimeRange } = useTimeRange();\n const dashboardDefaultTimeRange = useDefaultTimeRange();\n const { queryString } = useQueryString();\n\n const defaultTimeRange = getDefaultTimeRange(dashboardDefaultTimeRange, queryString);\n\n // selected form value can be relative or absolute, timeRange from plugin-system is only absolute\n const [selectedTimeRange, setSelectedTimeRange] = useState<TimeRangeValue>(defaultTimeRange);\n\n const [showCustomDateSelector, setShowCustomDateSelector] = useState(false);\n const anchorEl = useRef();\n\n return (\n <Stack direction=\"row\" spacing={1}>\n <Popover\n anchorEl={anchorEl.current}\n anchorOrigin={{\n vertical: 'bottom',\n horizontal: 'center',\n }}\n open={showCustomDateSelector}\n onClose={() => setShowCustomDateSelector(false)}\n sx={(theme) => ({\n padding: theme.spacing(2),\n })}\n >\n <AbsoluteTimePicker\n initialTimeRange={timeRange}\n onChange={(timeRange: AbsoluteTimeRange) => {\n setTimeRange(timeRange);\n setSelectedTimeRange(timeRange);\n setShowCustomDateSelector(false);\n }}\n />\n </Popover>\n <FormControl fullWidth>\n <Box ref={anchorEl}>\n <TimeRangeSelector\n timeOptions={TIME_OPTIONS}\n value={selectedTimeRange}\n onSelectChange={(event) => {\n const duration = event.target.value;\n const relativeTimeInput: RelativeTimeRange = {\n pastDuration: duration as DurationString,\n end: new Date(),\n };\n setTimeRange(relativeTimeInput);\n setSelectedTimeRange(relativeTimeInput);\n setShowCustomDateSelector(false);\n }}\n onCustomClick={() => {\n setShowCustomDateSelector(true);\n }}\n />\n </Box>\n </FormControl>\n </Stack>\n );\n}\n"],"names":["useRef","useState","Box","FormControl","Popover","Stack","AbsoluteTimePicker","TimeRangeSelector","getDefaultTimeRange","useTimeRange","useQueryString","useDefaultTimeRange","TIME_OPTIONS","value","pastDuration","display","TimeRangeControls","timeRange","setTimeRange","dashboardDefaultTimeRange","queryString","defaultTimeRange","selectedTimeRange","setSelectedTimeRange","showCustomDateSelector","setShowCustomDateSelector","anchorEl","direction","spacing","current","anchorOrigin","vertical","horizontal","open","onClose","sx","theme","padding","initialTimeRange","onChange","fullWidth","ref","timeOptions","onSelectChange","event","duration","target","relativeTimeInput","end","Date","onCustomClick"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,MAAM,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACzC,SAASC,GAAG,EAAEC,WAAW,EAAEC,OAAO,EAAEC,KAAK,QAAQ,eAAe,CAAC;AACjE,SAASC,kBAAkB,EAAEC,iBAAiB,QAAoB,wBAAwB,CAAC;AAC3F,SAKEC,mBAAmB,QACd,kBAAkB,CAAC;AAC1B,SAASC,YAAY,EAAEC,cAAc,QAAQ,2BAA2B,CAAC;AACzE,SAASC,mBAAmB,QAAQ,eAAe,CAAC;AAEpD,yDAAyD;AACzD,OAAO,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C;4BACF/B,YAAY,CAAC6B,iBAAiB,CAAC,CAAC;4BAChCxB,oBAAoB,CAACwB,iBAAiB,CAAC,CAAC;4BACxCtB,yBAAyB,CAAC,KAAK,CAAC,CAAC;wBACnC,CAAC;wBACDyB,aAAa,EAAE,IAAM;4BACnBzB,yBAAyB,CAAC,IAAI,CAAC,CAAC;wBAClC,CAAC;sBACD;kBACE;cACM;;MACR,CACR;AACJ,CAAC"}
@@ -1 +1,59 @@
1
- import{jsx as _jsx}from"react/jsx-runtime";import userEvent from"@testing-library/user-event";import{getDefaultTimeRange}from"@perses-dev/core";import{screen}from"@testing-library/react";import{renderWithContext}from"../../test";import testDashboard from"../../test/testDashboard";import{DashboardProvider,TimeRangeProvider,QueryStringProvider}from"../../context";import{TimeRangeControls}from"./TimeRangeControls";describe("TimeRangeControls",(()=>{let e;beforeEach((()=>{e={dashboardSpec:testDashboard.spec}}));const t=()=>{const t=new URLSearchParams,r=getDefaultTimeRange(e.dashboardSpec.duration,t);renderWithContext(_jsx(QueryStringProvider,{queryString:t,children:_jsx(DashboardProvider,{initialState:e,children:_jsx(TimeRangeProvider,{initialTimeRange:r,children:_jsx(TimeRangeControls,{})})})}))};it("should render correct initial relative time shortcut",(async()=>{t(),expect(screen.getByText("Last 1 day")).toBeInTheDocument()})),it("should be able to select the first option",(()=>{t();const e=screen.getByRole("button");userEvent.click(e);const r=screen.getByRole("option",{name:"Last 5 minutes"});userEvent.click(r),expect(e).toHaveTextContent(/5 minutes/i)}))}));
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
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import userEvent from '@testing-library/user-event';
15
+ import { getDefaultTimeRange } from '@perses-dev/core';
16
+ import { screen } from '@testing-library/react';
17
+ import { renderWithContext } from '../../test';
18
+ import testDashboard from '../../test/testDashboard';
19
+ import { DashboardProvider, TimeRangeProvider, QueryStringProvider } from '../../context';
20
+ import { TimeRangeControls } from './TimeRangeControls';
21
+ describe('TimeRangeControls', ()=>{
22
+ let initialState;
23
+ beforeEach(()=>{
24
+ initialState = {
25
+ dashboardSpec: testDashboard.spec
26
+ };
27
+ });
28
+ const renderTimeRangeControls = ()=>{
29
+ const queryString = new URLSearchParams();
30
+ const defaultTimeRange = getDefaultTimeRange(initialState.dashboardSpec.duration, queryString);
31
+ renderWithContext(/*#__PURE__*/ _jsx(QueryStringProvider, {
32
+ queryString: queryString,
33
+ children: /*#__PURE__*/ _jsx(DashboardProvider, {
34
+ initialState: initialState,
35
+ children: /*#__PURE__*/ _jsx(TimeRangeProvider, {
36
+ initialTimeRange: defaultTimeRange,
37
+ children: /*#__PURE__*/ _jsx(TimeRangeControls, {})
38
+ })
39
+ })
40
+ }));
41
+ };
42
+ it('should render correct initial relative time shortcut', async ()=>{
43
+ renderTimeRangeControls();
44
+ expect(screen.getByText('Last 1 day')).toBeInTheDocument();
45
+ });
46
+ it('should be able to select the first option', ()=>{
47
+ renderTimeRangeControls();
48
+ const dateButton = screen.getByRole('button');
49
+ userEvent.click(dateButton);
50
+ const firstOption = screen.getByRole('option', {
51
+ name: 'Last 5 minutes'
52
+ });
53
+ userEvent.click(firstOption);
54
+ expect(dateButton).toHaveTextContent(/5 minutes/i);
55
+ });
56
+ // TODO: add additional tests for absolute time selection, other inputs, form validation, etc.
57
+ });
58
+
59
+ //# sourceMappingURL=TimeRangeControls.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/TimeRangeControls/TimeRangeControls.test.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport userEvent from '@testing-library/user-event';\nimport { getDefaultTimeRange } from '@perses-dev/core';\nimport { screen } from '@testing-library/react';\nimport { renderWithContext } from '../../test';\nimport testDashboard from '../../test/testDashboard';\nimport { DashboardProvider, DashboardStoreProps, TimeRangeProvider, QueryStringProvider } from '../../context';\nimport { TimeRangeControls } from './TimeRangeControls';\n\ndescribe('TimeRangeControls', () => {\n let initialState: DashboardStoreProps;\n\n beforeEach(() => {\n initialState = {\n dashboardSpec: testDashboard.spec,\n };\n });\n\n const renderTimeRangeControls = () => {\n const queryString = new URLSearchParams();\n const defaultTimeRange = getDefaultTimeRange(initialState.dashboardSpec.duration, queryString);\n renderWithContext(\n <QueryStringProvider queryString={queryString}>\n <DashboardProvider initialState={initialState}>\n <TimeRangeProvider initialTimeRange={defaultTimeRange}>\n <TimeRangeControls />\n </TimeRangeProvider>\n </DashboardProvider>\n </QueryStringProvider>\n );\n };\n\n it('should render correct initial relative time shortcut', async () => {\n renderTimeRangeControls();\n expect(screen.getByText('Last 1 day')).toBeInTheDocument();\n });\n\n it('should be able to select the first option', () => {\n renderTimeRangeControls();\n const dateButton = screen.getByRole('button');\n userEvent.click(dateButton);\n const firstOption = screen.getByRole('option', { name: 'Last 5 minutes' });\n userEvent.click(firstOption);\n expect(dateButton).toHaveTextContent(/5 minutes/i);\n });\n\n // TODO: add additional tests for absolute time selection, other inputs, form validation, etc.\n});\n"],"names":["userEvent","getDefaultTimeRange","screen","renderWithContext","testDashboard","DashboardProvider","TimeRangeProvider","QueryStringProvider","TimeRangeControls","describe","initialState","beforeEach","dashboardSpec","spec","renderTimeRangeControls","queryString","URLSearchParams","defaultTimeRange","duration","initialTimeRange","it","expect","getByText","toBeInTheDocument","dateButton","getByRole","click","firstOption","name","toHaveTextContent"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,SAAS,MAAM,6BAA6B,CAAC;AACpD,SAASC,mBAAmB,QAAQ,kBAAkB,CAAC;AACvD,SAASC,MAAM,QAAQ,wBAAwB,CAAC;AAChD,SAASC,iBAAiB,QAAQ,YAAY,CAAC;AAC/C,OAAOC,aAAa,MAAM,0BAA0B,CAAC;AACrD,SAASC,iBAAiB,EAAuBC,iBAAiB,EAAEC,mBAAmB,QAAQ,eAAe,CAAC;AAC/G,SAASC,iBAAiB,QAAQ,qBAAqB,CAAC;AAExDC,QAAQ,CAAC,mBAAmB,EAAE,IAAM;IAClC,IAAIC,YAAY,AAAqB,AAAC;IAEtCC,UAAU,CAAC,IAAM;QACfD,YAAY,GAAG;YACbE,aAAa,EAAER,aAAa,CAACS,IAAI;SAClC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,MAAMC,uBAAuB,GAAG,IAAM;QACpC,MAAMC,WAAW,GAAG,IAAIC,eAAe,EAAE,AAAC;QAC1C,MAAMC,gBAAgB,GAAGhB,mBAAmB,CAACS,YAAY,CAACE,aAAa,CAACM,QAAQ,EAAEH,WAAW,CAAC,AAAC;QAC/FZ,iBAAiB,eACf,KAACI,mBAAmB;YAACQ,WAAW,EAAEA,WAAW;sBAC3C,cAAA,KAACV,iBAAiB;gBAACK,YAAY,EAAEA,YAAY;0BAC3C,cAAA,KAACJ,iBAAiB;oBAACa,gBAAgB,EAAEF,gBAAgB;8BACnD,cAAA,KAACT,iBAAiB,KAAG;kBACH;cACF;UACA,CACvB,CAAC;IACJ,CAAC,AAAC;IAEFY,EAAE,CAAC,sDAAsD,EAAE,UAAY;QACrEN,uBAAuB,EAAE,CAAC;QAC1BO,MAAM,CAACnB,MAAM,CAACoB,SAAS,CAAC,YAAY,CAAC,CAAC,CAACC,iBAAiB,EAAE,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEHH,EAAE,CAAC,2CAA2C,EAAE,IAAM;QACpDN,uBAAuB,EAAE,CAAC;QAC1B,MAAMU,UAAU,GAAGtB,MAAM,CAACuB,SAAS,CAAC,QAAQ,CAAC,AAAC;QAC9CzB,SAAS,CAAC0B,KAAK,CAACF,UAAU,CAAC,CAAC;QAC5B,MAAMG,WAAW,GAAGzB,MAAM,CAACuB,SAAS,CAAC,QAAQ,EAAE;YAAEG,IAAI,EAAE,gBAAgB;SAAE,CAAC,AAAC;QAC3E5B,SAAS,CAAC0B,KAAK,CAACC,WAAW,CAAC,CAAC;QAC7BN,MAAM,CAACG,UAAU,CAAC,CAACK,iBAAiB,cAAc,CAAC;IACrD,CAAC,CAAC,CAAC;AAEH,8FAA8F;AAChG,CAAC,CAAC,CAAC"}
@@ -1 +1,15 @@
1
- export*from"./TimeRangeControls";
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
+ export * from './TimeRangeControls';
14
+
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/TimeRangeControls/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './TimeRangeControls';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"Variable.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/Variable.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAE,YAAY,EAA0B,MAAM,kBAAkB,CAAC;AAGxE,aAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,EAAE,qBAAqB,eAW/D"}
1
+ {"version":3,"file":"Variable.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/Variable.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,YAAY,EAAyC,MAAM,kBAAkB,CAAC;AAWvF,aAAK,qBAAqB,GAAG;IAC3B,IAAI,EAAE,YAAY,CAAC;CACpB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,EAAE,IAAI,EAAE,EAAE,qBAAqB,eAW/D"}
@@ -1 +1,210 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useEffect,useRef}from"react";import{Select,FormControl,InputLabel,MenuItem,Box,LinearProgress,IconButton,TextField}from"@mui/material";import{Reload}from"mdi-material-ui";import{useTemplateVariable,useTemplateVariableActions,useTemplateVariableStore}from"../../context";export function TemplateVariable({name:e}){var a;const l=null===(a=useTemplateVariable(e).definition)||void 0===a?void 0:a.kind;switch(l){case"TextVariable":return _jsx(TextVariable,{name:e});case"ListVariable":return _jsx(ListVariable,{name:e})}return _jsxs("div",{children:["Unsupported Variable Kind: $",l]})}function ListVariable({name:e}){var a,l,t,i;const r=useTemplateVariable(e),n=r.definition,{setVariableValue:o,loadTemplateVariable:s}=useTemplateVariableActions(),u=!0===(null==n?void 0:n.options.allowMultiple);useEffect((()=>{s(e)}),[e,s]);let d=null===(a=r.state)||void 0===a?void 0:a.value;return u&&!Array.isArray(d)&&(d=[]),_jsxs(Box,{display:"flex",children:[_jsxs(FormControl,{children:[_jsx(InputLabel,{id:e,children:e}),_jsx(Select,{id:e,label:e,value:d,onChange:a=>{o(e,a.target.value)},multiple:u,children:null===(t=null===(l=r.state)||void 0===l?void 0:l.options)||void 0===t?void 0:t.map((e=>_jsx(MenuItem,{value:e.value,children:e.label},e.value)))}),(null===(i=r.state)||void 0===i?void 0:i.loading)&&_jsx(LinearProgress,{})]}),_jsx(IconButton,{onClick:()=>s(e),children:_jsx(Reload,{})})]})}function TextVariable({name:e}){const{state:a}=useTemplateVariable(e),l=useTemplateVariableStore().setVariableValue,t=useRef(null);return _jsx(TextField,{ref:t,defaultValue:null==a?void 0:a.value,onBlur:a=>l(e,a.target.value),placeholder:e,label:e})}
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
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
+ import { useEffect, useMemo, useState } from 'react';
15
+ import { Select, FormControl, InputLabel, MenuItem, Box, LinearProgress, TextField } from '@mui/material';
16
+ import { usePlugin, DEFAULT_ALL_VALUE, useTemplateVariableValues, useDatasourceStore } from '@perses-dev/plugin-system';
17
+ import { useQuery } from '@tanstack/react-query';
18
+ import { useTemplateVariable, useTemplateVariableActions } from '../../context';
19
+ export function TemplateVariable({ name }) {
20
+ var ref;
21
+ const ctx = useTemplateVariable(name);
22
+ const kind = (ref = ctx.definition) === null || ref === void 0 ? void 0 : ref.kind;
23
+ switch(kind){
24
+ case 'TextVariable':
25
+ return /*#__PURE__*/ _jsx(TextVariable, {
26
+ name: name
27
+ });
28
+ case 'ListVariable':
29
+ return /*#__PURE__*/ _jsx(ListVariable, {
30
+ name: name
31
+ });
32
+ }
33
+ return /*#__PURE__*/ _jsxs("div", {
34
+ children: [
35
+ "Unsupported Variable Kind: $",
36
+ kind
37
+ ]
38
+ });
39
+ }
40
+ /**
41
+ * Returns a serialized string of the current state of variable values.
42
+ */ function getVariableValuesKey(v) {
43
+ return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
44
+ }
45
+ function ListVariable({ name }) {
46
+ var ref, ref1, ref2, ref3;
47
+ const ctx = useTemplateVariable(name);
48
+ const definition = ctx.definition;
49
+ const { data: variablePlugin } = usePlugin('Variable', definition.spec.plugin.kind);
50
+ const { setVariableValue , setVariableLoading , setVariableOptions } = useTemplateVariableActions();
51
+ const datasourceStore = useDatasourceStore();
52
+ const spec = definition.spec.plugin.spec;
53
+ let dependsOnVariables;
54
+ if (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.dependsOn) {
55
+ dependsOnVariables = variablePlugin.dependsOn(spec);
56
+ }
57
+ const variables = useTemplateVariableValues(dependsOnVariables);
58
+ const allowMultiple = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_multiple) === true;
59
+ const allowAllValue = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_all_value) === true;
60
+ var ref4;
61
+ 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;
62
+ let waitToLoad = false;
63
+ if (dependsOnVariables) {
64
+ waitToLoad = dependsOnVariables.some((v)=>{
65
+ var ref;
66
+ return (ref = variables[v]) === null || ref === void 0 ? void 0 : ref.loading;
67
+ });
68
+ }
69
+ const variablesValueKey = getVariableValuesKey(variables);
70
+ const variablesOptionsQuery = useQuery([
71
+ name,
72
+ definition,
73
+ variablesValueKey
74
+ ], async ()=>{
75
+ const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
76
+ datasourceStore,
77
+ variables
78
+ }));
79
+ var ref;
80
+ return (ref = resp === null || resp === void 0 ? void 0 : resp.data) !== null && ref !== void 0 ? ref : [];
81
+ }, {
82
+ enabled: !!variablePlugin || waitToLoad
83
+ });
84
+ useEffect(()=>{
85
+ setVariableLoading(name, variablesOptionsQuery.isFetching);
86
+ if (variablesOptionsQuery.data) {
87
+ setVariableOptions(name, variablesOptionsQuery.data);
88
+ }
89
+ }, [
90
+ variablesOptionsQuery,
91
+ name,
92
+ setVariableLoading,
93
+ setVariableOptions
94
+ ]);
95
+ let value = (ref1 = ctx.state) === null || ref1 === void 0 ? void 0 : ref1.value;
96
+ const options = (ref2 = ctx.state) === null || ref2 === void 0 ? void 0 : ref2.options;
97
+ const loading = (ref3 = ctx.state) === null || ref3 === void 0 ? void 0 : ref3.loading;
98
+ // Make sure value is an array if allowMultiple is true
99
+ if (allowMultiple && !Array.isArray(value)) {
100
+ value = typeof value === 'string' ? [
101
+ value
102
+ ] : [];
103
+ }
104
+ const finalOptions = useMemo(()=>{
105
+ let computedOptions = options ? [
106
+ ...options
107
+ ] : [];
108
+ // Add the all value if it's allowed
109
+ if (allowAllValue) {
110
+ computedOptions = [
111
+ {
112
+ value: DEFAULT_ALL_VALUE,
113
+ label: 'All'
114
+ },
115
+ ...computedOptions
116
+ ];
117
+ }
118
+ return computedOptions;
119
+ }, [
120
+ options,
121
+ allowAllValue
122
+ ]);
123
+ useEffect(()=>{
124
+ const firstOption = finalOptions === null || finalOptions === void 0 ? void 0 : finalOptions[0];
125
+ const valueIsInOptions = Boolean(finalOptions.find((v)=>{
126
+ if (allowMultiple) {
127
+ return value.includes(v.value);
128
+ }
129
+ return value === v.value;
130
+ }));
131
+ // If there is no value but there are options, set the value to the first option.
132
+ if (!value && firstOption) {
133
+ setVariableValue(name, firstOption.value);
134
+ }
135
+ // If there is a value but it's not in the options, select the first value or set to null
136
+ if (value && !valueIsInOptions && !definition.spec.default_value) {
137
+ setVariableValue(name, (firstOption === null || firstOption === void 0 ? void 0 : firstOption.value) || null);
138
+ }
139
+ }, [
140
+ finalOptions,
141
+ setVariableValue,
142
+ value,
143
+ name,
144
+ allowMultiple
145
+ ]);
146
+ return /*#__PURE__*/ _jsx(Box, {
147
+ display: 'flex',
148
+ children: /*#__PURE__*/ _jsxs(FormControl, {
149
+ children: [
150
+ /*#__PURE__*/ _jsx(InputLabel, {
151
+ id: name,
152
+ children: label
153
+ }),
154
+ /*#__PURE__*/ _jsxs(Select, {
155
+ sx: {
156
+ minWidth: 100,
157
+ maxWidth: 250
158
+ },
159
+ id: name,
160
+ label: name,
161
+ value: value !== null && value !== void 0 ? value : '',
162
+ onChange: (e)=>{
163
+ // Must be selected
164
+ if (e.target.value === null || e.target.value.length === 0) {
165
+ if (allowAllValue) {
166
+ setVariableValue(name, DEFAULT_ALL_VALUE);
167
+ }
168
+ return;
169
+ }
170
+ setVariableValue(name, e.target.value);
171
+ },
172
+ multiple: allowMultiple,
173
+ children: [
174
+ loading && /*#__PURE__*/ _jsx(MenuItem, {
175
+ value: "loading",
176
+ disabled: true,
177
+ children: "Loading"
178
+ }),
179
+ finalOptions.map((option)=>/*#__PURE__*/ _jsx(MenuItem, {
180
+ value: option.value,
181
+ children: option.label
182
+ }, option.value))
183
+ ]
184
+ }),
185
+ loading && /*#__PURE__*/ _jsx(LinearProgress, {})
186
+ ]
187
+ })
188
+ });
189
+ }
190
+ function TextVariable({ name }) {
191
+ const { state } = useTemplateVariable(name);
192
+ var ref;
193
+ const [tempValue, setTempValue] = useState((ref = state === null || state === void 0 ? void 0 : state.value) !== null && ref !== void 0 ? ref : '');
194
+ const { setVariableValue } = useTemplateVariableActions();
195
+ useEffect(()=>{
196
+ var ref;
197
+ setTempValue((ref = state === null || state === void 0 ? void 0 : state.value) !== null && ref !== void 0 ? ref : '');
198
+ }, [
199
+ state === null || state === void 0 ? void 0 : state.value
200
+ ]);
201
+ return /*#__PURE__*/ _jsx(TextField, {
202
+ value: tempValue,
203
+ onChange: (e)=>setTempValue(e.target.value),
204
+ onBlur: ()=>setVariableValue(name, tempValue),
205
+ placeholder: name,
206
+ label: name
207
+ });
208
+ }
209
+
210
+ //# sourceMappingURL=Variable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/Variables/Variable.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useEffect, useMemo, useState } from 'react';\nimport { Select, FormControl, InputLabel, MenuItem, Box, LinearProgress, TextField } from '@mui/material';\nimport { VariableName, ListVariableDefinition, VariableValue } from '@perses-dev/core';\nimport {\n usePlugin,\n DEFAULT_ALL_VALUE,\n useTemplateVariableValues,\n VariableStateMap,\n useDatasourceStore,\n} from '@perses-dev/plugin-system';\nimport { useQuery } from '@tanstack/react-query';\nimport { useTemplateVariable, useTemplateVariableActions } from '../../context';\n\ntype TemplateVariableProps = {\n name: VariableName;\n};\n\nexport function TemplateVariable({ name }: TemplateVariableProps) {\n const ctx = useTemplateVariable(name);\n const kind = ctx.definition?.kind;\n switch (kind) {\n case 'TextVariable':\n return <TextVariable name={name} />;\n case 'ListVariable':\n return <ListVariable name={name} />;\n }\n\n return <div>Unsupported Variable Kind: ${kind}</div>;\n}\n\n/**\n * Returns a serialized string of the current state of variable values.\n */\nfunction getVariableValuesKey(v: VariableStateMap) {\n return Object.values(v)\n .map((v) => JSON.stringify(v.value))\n .join(',');\n}\n\nfunction ListVariable({ name }: TemplateVariableProps) {\n const ctx = useTemplateVariable(name);\n const definition = ctx.definition as ListVariableDefinition;\n const { data: variablePlugin } = usePlugin('Variable', definition.spec.plugin.kind);\n const { setVariableValue, setVariableLoading, setVariableOptions } = useTemplateVariableActions();\n const datasourceStore = useDatasourceStore();\n\n const spec = definition.spec.plugin.spec;\n\n let dependsOnVariables: string[] | undefined;\n if (variablePlugin?.dependsOn) {\n dependsOnVariables = variablePlugin.dependsOn(spec);\n }\n\n const variables = useTemplateVariableValues(dependsOnVariables);\n const allowMultiple = definition?.spec.allow_multiple === true;\n const allowAllValue = definition?.spec.allow_all_value === true;\n const label = definition?.spec.display?.label ?? name;\n\n let waitToLoad = false;\n if (dependsOnVariables) {\n waitToLoad = dependsOnVariables.some((v) => variables[v]?.loading);\n }\n\n const variablesValueKey = getVariableValuesKey(variables);\n\n const variablesOptionsQuery = useQuery(\n [name, definition, variablesValueKey],\n async () => {\n const resp = await variablePlugin?.getVariableOptions(spec, { datasourceStore, variables });\n return resp?.data ?? [];\n },\n { enabled: !!variablePlugin || waitToLoad }\n );\n\n useEffect(() => {\n setVariableLoading(name, variablesOptionsQuery.isFetching);\n if (variablesOptionsQuery.data) {\n setVariableOptions(name, variablesOptionsQuery.data);\n }\n }, [variablesOptionsQuery, name, setVariableLoading, setVariableOptions]);\n\n let value = ctx.state?.value;\n const options = ctx.state?.options;\n const loading = ctx.state?.loading;\n\n // Make sure value is an array if allowMultiple is true\n if (allowMultiple && !Array.isArray(value)) {\n value = typeof value === 'string' ? [value] : [];\n }\n\n const finalOptions = useMemo(() => {\n let computedOptions = options ? [...options] : [];\n\n // Add the all value if it's allowed\n if (allowAllValue) {\n computedOptions = [{ value: DEFAULT_ALL_VALUE, label: 'All' }, ...computedOptions];\n }\n return computedOptions;\n }, [options, allowAllValue]);\n\n useEffect(() => {\n const firstOption = finalOptions?.[0];\n const valueIsInOptions = Boolean(\n finalOptions.find((v) => {\n if (allowMultiple) {\n return (value as string[]).includes(v.value);\n }\n return value === v.value;\n })\n );\n\n // If there is no value but there are options, set the value to the first option.\n if (!value && firstOption) {\n setVariableValue(name, firstOption.value);\n }\n\n // If there is a value but it's not in the options, select the first value or set to null\n if (value && !valueIsInOptions && !definition.spec.default_value) {\n setVariableValue(name, firstOption?.value || null);\n }\n }, [finalOptions, setVariableValue, value, name, allowMultiple]);\n\n return (\n <Box display={'flex'}>\n <FormControl>\n <InputLabel id={name}>{label}</InputLabel>\n <Select\n sx={{ minWidth: 100, maxWidth: 250 }}\n id={name}\n label={name}\n value={value ?? ''}\n onChange={(e) => {\n // Must be selected\n if (e.target.value === null || e.target.value.length === 0) {\n if (allowAllValue) {\n setVariableValue(name, DEFAULT_ALL_VALUE);\n }\n return;\n }\n setVariableValue(name, e.target.value as VariableValue);\n }}\n multiple={allowMultiple}\n >\n {loading && (\n <MenuItem value=\"loading\" disabled>\n Loading\n </MenuItem>\n )}\n {finalOptions.map((option) => (\n <MenuItem key={option.value} value={option.value}>\n {option.label}\n </MenuItem>\n ))}\n </Select>\n {loading && <LinearProgress />}\n </FormControl>\n </Box>\n );\n}\n\nfunction TextVariable({ name }: TemplateVariableProps) {\n const { state } = useTemplateVariable(name);\n const [tempValue, setTempValue] = useState(state?.value ?? '');\n const { setVariableValue } = useTemplateVariableActions();\n\n useEffect(() => {\n setTempValue(state?.value ?? '');\n }, [state?.value]);\n\n return (\n <TextField\n value={tempValue}\n onChange={(e) => setTempValue(e.target.value)}\n onBlur={() => setVariableValue(name, tempValue)}\n placeholder={name}\n label={name}\n />\n );\n}\n"],"names":["useEffect","useMemo","useState","Select","FormControl","InputLabel","MenuItem","Box","LinearProgress","TextField","usePlugin","DEFAULT_ALL_VALUE","useTemplateVariableValues","useDatasourceStore","useQuery","useTemplateVariable","useTemplateVariableActions","TemplateVariable","name","ctx","kind","definition","TextVariable","ListVariable","div","getVariableValuesKey","v","Object","values","map","JSON","stringify","value","join","data","variablePlugin","spec","plugin","setVariableValue","setVariableLoading","setVariableOptions","datasourceStore","dependsOnVariables","dependsOn","variables","allowMultiple","allow_multiple","allowAllValue","allow_all_value","label","display","waitToLoad","some","loading","variablesValueKey","variablesOptionsQuery","resp","getVariableOptions","enabled","isFetching","state","options","Array","isArray","finalOptions","computedOptions","firstOption","valueIsInOptions","Boolean","find","includes","default_value","id","sx","minWidth","maxWidth","onChange","e","target","length","multiple","disabled","option","tempValue","setTempValue","onBlur","placeholder"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AACrD,SAASC,MAAM,EAAEC,WAAW,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,GAAG,EAAEC,cAAc,EAAEC,SAAS,QAAQ,eAAe,CAAC;AAE1G,SACEC,SAAS,EACTC,iBAAiB,EACjBC,yBAAyB,EAEzBC,kBAAkB,QACb,2BAA2B,CAAC;AACnC,SAASC,QAAQ,QAAQ,uBAAuB,CAAC;AACjD,SAASC,mBAAmB,EAAEC,0BAA0B,QAAQ,eAAe,CAAC;AAMhF,OAAO,SAASC,gBAAgB,CAAC,EAAEC,IAAI,CAAA,EAAyB,EAAE;QAEnDC,GAAc;IAD3B,MAAMA,GAAG,GAAGJ,mBAAmB,CAACG,IAAI,CAAC,AAAC;IACtC,MAAME,IAAI,GAAGD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SAAS,CAAC;QAC/CG,WAAW,EAAEpE,IAAI;QACjB+B,KAAK,EAAE/B,IAAI;MACX,CACF;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ import { VariableDefinition } from '@perses-dev/core';
3
+ export declare function VariableEditor(props: {
4
+ variableDefinitions: VariableDefinition[];
5
+ onChange: (variableDefinitions: VariableDefinition[]) => void;
6
+ onCancel: () => void;
7
+ }): JSX.Element;
8
+ //# sourceMappingURL=VariableEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VariableEditor.d.ts","sourceRoot":"","sources":["../../../src/components/Variables/VariableEditor.tsx"],"names":[],"mappings":";AA6BA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtD,wBAAgB,cAAc,CAAC,KAAK,EAAE;IACpC,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,QAAQ,EAAE,CAAC,mBAAmB,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;IAC9D,QAAQ,EAAE,MAAM,IAAI,CAAC;CACtB,eAkIA"}