@perses-dev/dashboards 0.9.0 → 0.11.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 (268) hide show
  1. package/dist/cjs/components/Dashboard.js +6 -11
  2. package/dist/cjs/components/DashboardToolbar.js +12 -6
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +7 -15
  4. package/dist/cjs/components/GridLayout/GridLayout.js +27 -22
  5. package/dist/cjs/components/GridLayout/GridTitle.js +27 -7
  6. package/dist/cjs/components/Panel/DeletePanelDialog.js +95 -0
  7. package/dist/cjs/components/Panel/Panel.js +12 -10
  8. package/dist/cjs/components/Panel/Panel.test.js +15 -6
  9. package/dist/cjs/components/Panel/PanelContent.js +3 -2
  10. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +13 -12
  11. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +9 -13
  12. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +87 -39
  13. package/dist/cjs/components/PanelDrawer/PanelPreview.js +54 -0
  14. package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +88 -0
  15. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +70 -118
  16. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +21 -36
  17. package/dist/cjs/components/PanelGroupDialog/PanelGroupEditorForm.js +92 -0
  18. package/dist/cjs/components/PanelGroupDialog/index.js +29 -0
  19. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +8 -11
  20. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +20 -13
  21. package/dist/cjs/components/Variables/Variable.js +20 -11
  22. package/dist/cjs/components/Variables/VariableEditor.js +240 -0
  23. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +236 -0
  24. package/dist/cjs/components/Variables/VariableEditorForm/index.js +28 -0
  25. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +88 -0
  26. package/dist/cjs/components/Variables/VariableList.js +49 -69
  27. package/dist/cjs/components/Variables/index.js +1 -0
  28. package/dist/cjs/components/index.js +1 -0
  29. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +82 -0
  30. package/dist/cjs/context/DashboardProvider/common.js +18 -0
  31. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +164 -0
  32. package/dist/cjs/context/DashboardProvider/index.js +29 -0
  33. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +175 -0
  34. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +102 -0
  35. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +208 -0
  36. package/dist/cjs/context/DatasourceStoreProvider.js +109 -7
  37. package/dist/cjs/context/TemplateVariableProvider.js +8 -1
  38. package/dist/cjs/context/TimeRangeProvider.js +20 -44
  39. package/dist/cjs/context/index.js +1 -3
  40. package/dist/cjs/context/useDashboardSpec.js +61 -0
  41. package/dist/cjs/index.js +1 -0
  42. package/dist/cjs/test/render.js +25 -5
  43. package/dist/cjs/test/setup-tests.js +4 -1
  44. package/dist/cjs/test/testDashboard.js +24 -11
  45. package/dist/cjs/utils/index.js +28 -0
  46. package/dist/cjs/utils/time-range-params.js +145 -0
  47. package/dist/cjs/views/ViewDashboard/DashboardApp.js +5 -8
  48. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +5 -22
  49. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +114 -0
  50. package/dist/components/Dashboard.d.ts +1 -4
  51. package/dist/components/Dashboard.d.ts.map +1 -1
  52. package/dist/components/Dashboard.js +7 -12
  53. package/dist/components/Dashboard.js.map +1 -1
  54. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  55. package/dist/components/DashboardToolbar.js +14 -8
  56. package/dist/components/DashboardToolbar.js.map +1 -1
  57. package/dist/components/GridLayout/GridItemContent.d.ts +2 -4
  58. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  59. package/dist/components/GridLayout/GridItemContent.js +7 -15
  60. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  61. package/dist/components/GridLayout/GridLayout.d.ts +2 -4
  62. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  63. package/dist/components/GridLayout/GridLayout.js +28 -23
  64. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  65. package/dist/components/GridLayout/GridTitle.d.ts +2 -1
  66. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  67. package/dist/components/GridLayout/GridTitle.js +28 -8
  68. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  69. package/dist/components/Panel/DeletePanelDialog.d.ts +5 -0
  70. package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -0
  71. package/dist/components/Panel/DeletePanelDialog.js +84 -0
  72. package/dist/components/Panel/DeletePanelDialog.js.map +1 -0
  73. package/dist/components/Panel/Panel.d.ts +2 -2
  74. package/dist/components/Panel/Panel.d.ts.map +1 -1
  75. package/dist/components/Panel/Panel.js +13 -11
  76. package/dist/components/Panel/Panel.js.map +1 -1
  77. package/dist/components/Panel/Panel.test.d.ts +1 -1
  78. package/dist/components/Panel/Panel.test.d.ts.map +1 -1
  79. package/dist/components/Panel/Panel.test.js +10 -6
  80. package/dist/components/Panel/Panel.test.js.map +1 -1
  81. package/dist/components/Panel/PanelContent.d.ts +4 -1
  82. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  83. package/dist/components/Panel/PanelContent.js +3 -2
  84. package/dist/components/Panel/PanelContent.js.map +1 -1
  85. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  86. package/dist/components/PanelDrawer/PanelDrawer.js +14 -13
  87. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  88. package/dist/components/PanelDrawer/PanelDrawer.test.js +9 -13
  89. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  90. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +3 -3
  91. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  92. package/dist/components/PanelDrawer/PanelEditorForm.js +89 -41
  93. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  94. package/dist/components/PanelDrawer/PanelPreview.d.ts +4 -0
  95. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -0
  96. package/dist/components/PanelDrawer/PanelPreview.js +48 -0
  97. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -0
  98. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +3 -0
  99. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
  100. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +77 -0
  101. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
  102. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +4 -2
  103. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  104. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +73 -119
  105. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  106. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +20 -35
  107. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
  108. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +12 -0
  109. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -0
  110. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +82 -0
  111. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -0
  112. package/dist/components/PanelGroupDialog/index.d.ts +3 -0
  113. package/dist/components/PanelGroupDialog/index.d.ts.map +1 -0
  114. package/dist/components/PanelGroupDialog/index.js +16 -0
  115. package/dist/components/PanelGroupDialog/index.js.map +1 -0
  116. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  117. package/dist/components/TimeRangeControls/TimeRangeControls.js +11 -14
  118. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  119. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +21 -14
  120. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  121. package/dist/components/Variables/Variable.js +22 -13
  122. package/dist/components/Variables/Variable.js.map +1 -1
  123. package/dist/components/Variables/VariableEditor.d.ts +8 -0
  124. package/dist/components/Variables/VariableEditor.d.ts.map +1 -0
  125. package/dist/components/Variables/VariableEditor.js +229 -0
  126. package/dist/components/Variables/VariableEditor.js.map +1 -0
  127. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +8 -0
  128. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
  129. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +225 -0
  130. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
  131. package/dist/components/Variables/VariableEditorForm/index.d.ts +2 -0
  132. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
  133. package/dist/components/Variables/VariableEditorForm/index.js +15 -0
  134. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
  135. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +21 -0
  136. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
  137. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +76 -0
  138. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
  139. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  140. package/dist/components/Variables/VariableList.js +47 -72
  141. package/dist/components/Variables/VariableList.js.map +1 -1
  142. package/dist/components/Variables/index.d.ts +1 -0
  143. package/dist/components/Variables/index.d.ts.map +1 -1
  144. package/dist/components/Variables/index.js +1 -0
  145. package/dist/components/Variables/index.js.map +1 -1
  146. package/dist/components/index.d.ts +1 -0
  147. package/dist/components/index.d.ts.map +1 -1
  148. package/dist/components/index.js +1 -0
  149. package/dist/components/index.js.map +1 -1
  150. package/dist/context/DashboardProvider/DashboardProvider.d.ts +25 -0
  151. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -0
  152. package/dist/context/DashboardProvider/DashboardProvider.js +64 -0
  153. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -0
  154. package/dist/context/DashboardProvider/common.d.ts +5 -0
  155. package/dist/context/DashboardProvider/common.d.ts.map +1 -0
  156. package/dist/context/DashboardProvider/common.js +17 -0
  157. package/dist/context/DashboardProvider/common.js.map +1 -0
  158. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +74 -0
  159. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -0
  160. package/dist/context/DashboardProvider/dashboard-provider-api.js +163 -0
  161. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -0
  162. package/dist/context/DashboardProvider/index.d.ts +5 -0
  163. package/dist/context/DashboardProvider/index.d.ts.map +1 -0
  164. package/dist/context/DashboardProvider/index.js +16 -0
  165. package/dist/context/DashboardProvider/index.js.map +1 -0
  166. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +85 -0
  167. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -0
  168. package/dist/context/DashboardProvider/panel-editor-slice.js +171 -0
  169. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -0
  170. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +40 -0
  171. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -0
  172. package/dist/context/DashboardProvider/panel-group-editor-slice.js +96 -0
  173. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -0
  174. package/dist/context/DashboardProvider/panel-group-slice.d.ts +80 -0
  175. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -0
  176. package/dist/context/DashboardProvider/panel-group-slice.js +204 -0
  177. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -0
  178. package/dist/context/DatasourceStoreProvider.d.ts +10 -2
  179. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  180. package/dist/context/DatasourceStoreProvider.js +111 -9
  181. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  182. package/dist/context/TemplateVariableProvider.d.ts +2 -0
  183. package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
  184. package/dist/context/TemplateVariableProvider.js +8 -1
  185. package/dist/context/TemplateVariableProvider.js.map +1 -1
  186. package/dist/context/TimeRangeProvider.d.ts +9 -2
  187. package/dist/context/TimeRangeProvider.d.ts.map +1 -1
  188. package/dist/context/TimeRangeProvider.js +15 -43
  189. package/dist/context/TimeRangeProvider.js.map +1 -1
  190. package/dist/context/index.d.ts +1 -3
  191. package/dist/context/index.d.ts.map +1 -1
  192. package/dist/context/index.js +1 -3
  193. package/dist/context/index.js.map +1 -1
  194. package/dist/context/useDashboardSpec.d.ts +3 -0
  195. package/dist/context/useDashboardSpec.d.ts.map +1 -0
  196. package/dist/context/useDashboardSpec.js +55 -0
  197. package/dist/context/useDashboardSpec.js.map +1 -0
  198. package/dist/index.d.ts +1 -0
  199. package/dist/index.d.ts.map +1 -1
  200. package/dist/index.js +1 -0
  201. package/dist/index.js.map +1 -1
  202. package/dist/test/plugin-registry.d.ts +2 -2
  203. package/dist/test/plugin-registry.d.ts.map +1 -1
  204. package/dist/test/plugin-registry.js.map +1 -1
  205. package/dist/test/render.d.ts +2 -1
  206. package/dist/test/render.d.ts.map +1 -1
  207. package/dist/test/render.js +25 -5
  208. package/dist/test/render.js.map +1 -1
  209. package/dist/test/setup-tests.d.ts.map +1 -1
  210. package/dist/test/setup-tests.js +4 -0
  211. package/dist/test/setup-tests.js.map +1 -1
  212. package/dist/test/testDashboard.d.ts.map +1 -1
  213. package/dist/test/testDashboard.js +24 -11
  214. package/dist/test/testDashboard.js.map +1 -1
  215. package/dist/utils/index.d.ts +2 -0
  216. package/dist/utils/index.d.ts.map +1 -0
  217. package/dist/utils/index.js +15 -0
  218. package/dist/utils/index.js.map +1 -0
  219. package/dist/utils/time-range-params.d.ts +25 -0
  220. package/dist/utils/time-range-params.d.ts.map +1 -0
  221. package/dist/utils/time-range-params.js +137 -0
  222. package/dist/utils/time-range-params.js.map +1 -0
  223. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  224. package/dist/views/ViewDashboard/DashboardApp.js +6 -9
  225. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  226. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  227. package/dist/views/ViewDashboard/ViewDashboard.js +5 -22
  228. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  229. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +2 -0
  230. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +1 -0
  231. package/dist/views/ViewDashboard/tests/panelGroups.test.js +107 -0
  232. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -0
  233. package/package.json +5 -4
  234. package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +0 -40
  235. package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +0 -38
  236. package/dist/cjs/components/PanelDrawer/panel-editor-model.js +0 -140
  237. package/dist/cjs/context/DashboardAppSlice.js +0 -57
  238. package/dist/cjs/context/DashboardProvider.js +0 -128
  239. package/dist/cjs/context/LayoutsSlice.js +0 -55
  240. package/dist/cjs/context/QueryStringProvider.js +0 -89
  241. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +0 -7
  242. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +0 -1
  243. package/dist/components/PanelDrawer/PanelSpecEditor.js +0 -34
  244. package/dist/components/PanelDrawer/PanelSpecEditor.js.map +0 -1
  245. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +0 -8
  246. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +0 -1
  247. package/dist/components/PanelDrawer/PanelTypeSelect.js +0 -34
  248. package/dist/components/PanelDrawer/PanelTypeSelect.js.map +0 -1
  249. package/dist/components/PanelDrawer/panel-editor-model.d.ts +0 -27
  250. package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +0 -1
  251. package/dist/components/PanelDrawer/panel-editor-model.js +0 -133
  252. package/dist/components/PanelDrawer/panel-editor-model.js.map +0 -1
  253. package/dist/context/DashboardAppSlice.d.ts +0 -26
  254. package/dist/context/DashboardAppSlice.d.ts.map +0 -1
  255. package/dist/context/DashboardAppSlice.js +0 -45
  256. package/dist/context/DashboardAppSlice.js.map +0 -1
  257. package/dist/context/DashboardProvider.d.ts +0 -36
  258. package/dist/context/DashboardProvider.d.ts.map +0 -1
  259. package/dist/context/DashboardProvider.js +0 -107
  260. package/dist/context/DashboardProvider.js.map +0 -1
  261. package/dist/context/LayoutsSlice.d.ts +0 -12
  262. package/dist/context/LayoutsSlice.d.ts.map +0 -1
  263. package/dist/context/LayoutsSlice.js +0 -43
  264. package/dist/context/LayoutsSlice.js.map +0 -1
  265. package/dist/context/QueryStringProvider.d.ts +0 -13
  266. package/dist/context/QueryStringProvider.d.ts.map +0 -1
  267. package/dist/context/QueryStringProvider.js +0 -40
  268. package/dist/context/QueryStringProvider.js.map +0 -1
@@ -10,129 +10,83 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- import { useState } from 'react';
15
- import { IconButton, Dialog, DialogTitle, DialogContent, FormControl, InputLabel, TextField, Stack, Box, DialogActions, Button, Select, MenuItem } from '@mui/material';
13
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
14
+ import { IconButton, Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@mui/material';
16
15
  import CloseIcon from 'mdi-material-ui/Close';
17
- import { useDashboardApp, useLayouts } from '../../context';
18
- const PanelGroupDialog = ()=>{
19
- var ref, ref1, ref2, ref3, ref4;
20
- const { layouts , updateLayout } = useLayouts();
21
- const { panelGroupDialog , closePanelGroupDialog } = useDashboardApp();
22
- const groupIndex = panelGroupDialog === null || panelGroupDialog === void 0 ? void 0 : panelGroupDialog.groupIndex;
23
- const isEditingPanelGroup = groupIndex !== undefined;
24
- const [isCollapsed, setIsCollapsed] = useState(isEditingPanelGroup && !((ref1 = (ref = layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.spec.display) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.collapse) === null || ref2 === void 0 ? void 0 : ref2.open));
25
- const [name, setName] = useState(isEditingPanelGroup ? (ref4 = (ref3 = layouts[groupIndex]) === null || ref3 === void 0 ? void 0 : ref3.spec.display) === null || ref4 === void 0 ? void 0 : ref4.title : '');
26
- const handleSubmit = (e)=>{
27
- var ref;
28
- e.preventDefault();
29
- var _items;
30
- const newLayout = {
31
- kind: 'Grid',
32
- spec: {
33
- display: {
34
- title: name !== null && name !== void 0 ? name : '',
35
- collapse: {
36
- open: !isCollapsed
37
- }
38
- },
39
- items: groupIndex === undefined ? [] : (_items = (ref = layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.spec.items) !== null && _items !== void 0 ? _items : []
40
- }
41
- };
42
- updateLayout(newLayout, groupIndex);
43
- closePanelGroupDialog();
16
+ import { useState } from 'react';
17
+ import { usePanelGroupEditor } from '../../context';
18
+ import { PanelGroupEditorForm, panelGroupEditorFormId } from './PanelGroupEditorForm';
19
+ /**
20
+ * A dialog for adding or editing a Panel Group. Open and initial state is controlled by the DashboardStore.
21
+ */ export function PanelGroupDialog() {
22
+ const panelGroupEditor = usePanelGroupEditor();
23
+ // When the user clicks close, start closing but don't call the store yet to keep values stable during animtation
24
+ const [isClosing, setIsClosing] = useState(false);
25
+ const handleClose = ()=>setIsClosing(true);
26
+ // Don't call close on the store until the Dialog has completely transitioned out
27
+ const handleExited = ()=>{
28
+ panelGroupEditor === null || panelGroupEditor === void 0 ? void 0 : panelGroupEditor.close();
29
+ setIsClosing(false);
44
30
  };
45
- const handleSelectCollapsedStateChange = (e)=>{
46
- const isCollapsed = e.target.value === 'Close';
47
- setIsCollapsed(isCollapsed);
31
+ // Dialog is open if we have a model and we're not transitioning out
32
+ const isOpen = panelGroupEditor !== undefined && isClosing === false;
33
+ const handleSubmit = (values)=>{
34
+ // This shouldn't happen since we don't render the submit button until we have a model, but check to make TS happy
35
+ if (panelGroupEditor === undefined) {
36
+ throw new Error('Cannot apply changes');
37
+ }
38
+ panelGroupEditor.applyChanges(values);
39
+ handleClose();
48
40
  };
49
- return /*#__PURE__*/ _jsxs(Dialog, {
50
- open: true,
51
- children: [
52
- /*#__PURE__*/ _jsx(DialogTitle, {
53
- children: "Panel Group"
54
- }),
55
- /*#__PURE__*/ _jsx(IconButton, {
56
- "aria-label": "Close",
57
- onClick: ()=>closePanelGroupDialog(),
58
- sx: (theme)=>({
59
- position: 'absolute',
60
- top: theme.spacing(0.5),
61
- right: theme.spacing(0.5)
62
- }),
63
- children: /*#__PURE__*/ _jsx(CloseIcon, {})
64
- }),
65
- /*#__PURE__*/ _jsxs("form", {
66
- onSubmit: handleSubmit,
67
- children: [
68
- /*#__PURE__*/ _jsx(DialogContent, {
69
- sx: {
70
- width: '500px'
71
- },
72
- children: /*#__PURE__*/ _jsxs(Stack, {
73
- spacing: 2,
74
- children: [
75
- /*#__PURE__*/ _jsx(FormControl, {
76
- children: /*#__PURE__*/ _jsx(TextField, {
77
- required: true,
78
- label: "Name",
79
- variant: "outlined",
80
- value: name,
81
- onChange: (e)=>setName(e.target.value)
82
- })
83
- }),
84
- /*#__PURE__*/ _jsxs(Box, {
85
- sx: {
86
- display: 'flex',
87
- alignItems: 'center',
88
- width: '100%',
89
- justifyContent: 'space-between'
90
- },
91
- children: [
92
- /*#__PURE__*/ _jsx(InputLabel, {
93
- children: "Collapse State"
94
- }),
95
- /*#__PURE__*/ _jsxs(Select, {
96
- required: true,
97
- displayEmpty: true,
98
- labelId: "select-collapse-state",
99
- size: "small",
100
- value: isCollapsed ? 'Close' : 'Open',
101
- onChange: handleSelectCollapsedStateChange,
102
- children: [
103
- /*#__PURE__*/ _jsx(MenuItem, {
104
- value: 'Open',
105
- children: "Open"
106
- }, 'open'),
107
- /*#__PURE__*/ _jsx(MenuItem, {
108
- value: 'Close',
109
- children: "Close"
110
- }, 'close')
111
- ]
112
- })
113
- ]
114
- })
115
- ]
116
- })
117
- }),
118
- /*#__PURE__*/ _jsxs(DialogActions, {
119
- children: [
120
- /*#__PURE__*/ _jsx(Button, {
121
- variant: "contained",
122
- type: "submit",
123
- children: isEditingPanelGroup ? 'Apply' : 'Add'
124
- }),
125
- /*#__PURE__*/ _jsx(Button, {
126
- onClick: ()=>closePanelGroupDialog(),
127
- children: "Cancel"
128
- })
129
- ]
41
+ return /*#__PURE__*/ _jsx(Dialog, {
42
+ open: isOpen,
43
+ TransitionProps: {
44
+ onExited: handleExited
45
+ },
46
+ children: panelGroupEditor !== undefined && /*#__PURE__*/ _jsxs(_Fragment, {
47
+ children: [
48
+ /*#__PURE__*/ _jsxs(DialogTitle, {
49
+ children: [
50
+ panelGroupEditor.mode,
51
+ " Panel Group"
52
+ ]
53
+ }),
54
+ /*#__PURE__*/ _jsx(IconButton, {
55
+ "aria-label": "Close",
56
+ onClick: panelGroupEditor.close,
57
+ sx: (theme)=>({
58
+ position: 'absolute',
59
+ top: theme.spacing(0.5),
60
+ right: theme.spacing(0.5)
61
+ }),
62
+ children: /*#__PURE__*/ _jsx(CloseIcon, {})
63
+ }),
64
+ /*#__PURE__*/ _jsx(DialogContent, {
65
+ sx: {
66
+ width: '500px'
67
+ },
68
+ children: /*#__PURE__*/ _jsx(PanelGroupEditorForm, {
69
+ initialValues: panelGroupEditor.initialValues,
70
+ onSubmit: handleSubmit
130
71
  })
131
- ]
132
- })
133
- ]
72
+ }),
73
+ /*#__PURE__*/ _jsxs(DialogActions, {
74
+ children: [
75
+ /*#__PURE__*/ _jsx(Button, {
76
+ variant: "contained",
77
+ type: "submit",
78
+ form: panelGroupEditorFormId,
79
+ children: panelGroupEditor.mode === 'Edit' ? 'Apply' : 'Add'
80
+ }),
81
+ /*#__PURE__*/ _jsx(Button, {
82
+ onClick: panelGroupEditor.close,
83
+ children: "Cancel"
84
+ })
85
+ ]
86
+ })
87
+ ]
88
+ })
134
89
  });
135
- };
136
- export default PanelGroupDialog;
90
+ }
137
91
 
138
92
  //# sourceMappingURL=PanelGroupDialog.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/PanelGroupDialog/PanelGroupDialog.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 { FormEvent, useState } from 'react';\nimport {\n IconButton,\n Dialog,\n DialogTitle,\n DialogContent,\n FormControl,\n InputLabel,\n TextField,\n Stack,\n Box,\n DialogActions,\n Button,\n Select,\n SelectChangeEvent,\n MenuItem,\n} from '@mui/material';\nimport { LayoutDefinition } from '@perses-dev/core';\nimport CloseIcon from 'mdi-material-ui/Close';\nimport { useDashboardApp, useLayouts } from '../../context';\n\nconst PanelGroupDialog = () => {\n const { layouts, updateLayout } = useLayouts();\n const { panelGroupDialog, closePanelGroupDialog } = useDashboardApp();\n\n const groupIndex = panelGroupDialog?.groupIndex;\n\n const isEditingPanelGroup = groupIndex !== undefined;\n\n const [isCollapsed, setIsCollapsed] = useState(\n isEditingPanelGroup && !layouts[groupIndex]?.spec.display?.collapse?.open\n );\n const [name, setName] = useState(isEditingPanelGroup ? layouts[groupIndex]?.spec.display?.title : '');\n\n const handleSubmit = (e: FormEvent) => {\n e.preventDefault();\n const newLayout: LayoutDefinition = {\n kind: 'Grid',\n spec: {\n display: {\n title: name ?? '',\n collapse: {\n open: !isCollapsed,\n },\n },\n items: groupIndex === undefined ? [] : layouts[groupIndex]?.spec.items ?? [],\n },\n };\n updateLayout(newLayout, groupIndex);\n closePanelGroupDialog();\n };\n\n const handleSelectCollapsedStateChange = (e: SelectChangeEvent<string>) => {\n const isCollapsed = e.target.value === 'Close';\n setIsCollapsed(isCollapsed);\n };\n\n return (\n <Dialog open>\n <DialogTitle>Panel Group</DialogTitle>\n <IconButton\n aria-label=\"Close\"\n onClick={() => closePanelGroupDialog()}\n sx={(theme) => ({\n position: 'absolute',\n top: theme.spacing(0.5),\n right: theme.spacing(0.5),\n })}\n >\n <CloseIcon />\n </IconButton>\n <form onSubmit={handleSubmit}>\n <DialogContent sx={{ width: '500px' }}>\n <Stack spacing={2}>\n <FormControl>\n <TextField\n required\n label=\"Name\"\n variant=\"outlined\"\n value={name}\n onChange={(e) => setName(e.target.value)}\n />\n </FormControl>\n <Box sx={{ display: 'flex', alignItems: 'center', width: '100%', justifyContent: 'space-between' }}>\n <InputLabel>Collapse State</InputLabel>\n <Select\n required\n displayEmpty\n labelId=\"select-collapse-state\"\n size=\"small\"\n value={isCollapsed ? 'Close' : 'Open'}\n onChange={handleSelectCollapsedStateChange}\n >\n <MenuItem key={'open'} value={'Open'}>\n Open\n </MenuItem>\n <MenuItem key={'close'} value={'Close'}>\n Close\n </MenuItem>\n </Select>\n </Box>\n </Stack>\n </DialogContent>\n <DialogActions>\n <Button variant=\"contained\" type=\"submit\">\n {isEditingPanelGroup ? 'Apply' : 'Add'}\n </Button>\n <Button onClick={() => closePanelGroupDialog()}>Cancel</Button>\n </DialogActions>\n </form>\n </Dialog>\n );\n};\n\nexport default PanelGroupDialog;\n"],"names":["useState","IconButton","Dialog","DialogTitle","DialogContent","FormControl","InputLabel","TextField","Stack","Box","DialogActions","Button","Select","MenuItem","CloseIcon","useDashboardApp","useLayouts","PanelGroupDialog","layouts","updateLayout","panelGroupDialog","closePanelGroupDialog","groupIndex","isEditingPanelGroup","undefined","isCollapsed","setIsCollapsed","spec","display","collapse","open","name","setName","title","handleSubmit","e","preventDefault","newLayout","kind","items","handleSelectCollapsedStateChange","target","value","aria-label","onClick","sx","theme","position","top","spacing","right","form","onSubmit","width","required","label","variant","onChange","alignItems","justifyContent","displayEmpty","labelId","size","type"],"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,SAAoBA,QAAQ,QAAQ,OAAO,CAAC;AAC5C,SACEC,UAAU,EACVC,MAAM,EACNC,WAAW,EACXC,aAAa,EACbC,WAAW,EACXC,UAAU,EACVC,SAAS,EACTC,KAAK,EACLC,GAAG,EACHC,aAAa,EACbC,MAAM,EACNC,MAAM,EAENC,QAAQ,QACH,eAAe,CAAC;AAEvB,OAAOC,SAAS,MAAM,uBAAuB,CAAC;AAC9C,SAASC,eAAe,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAE5D,MAAMC,gBAAgB,GAAG,IAAM;QASHC,GAAmB,cAEUA,IAAmB;IAV1E,MAAM,EAAEA,OAAO,CAAA,EAAEC,YAAY,CAAA,EAAE,GAAGH,UAAU,EAAE,AAAC;IAC/C,MAAM,EAAEI,gBAAgB,CAAA,EAAEC,qBAAqB,CAAA,EAAE,GAAGN,eAAe,EAAE,AAAC;IAEtE,MAAMO,UAAU,GAAGF,gBAAgB,aAAhBA,gBAAgB,WAAY,GAA5BA,KAAAA,CAA4B,GAA5BA,gBAAgB,CAAEE,UAAU,AAAC;IAEhD,MAAMC,mBAAmB,GAAGD,UAAU,KAAKE,SAAS,AAAC;IAErD,MAAM,CAACC,WAAW,EAAEC,cAAc,CAAC,GAAG1B,QAAQ,CAC5CuB,mBAAmB,IAAI,CAACL,CAAAA,QAAAA,CAAAA,GAAmB,GAAnBA,OAAO,CAACI,UAAU,CAAC,cAAnBJ,GAAmB,WAAM,GAAzBA,KAAAA,CAAyB,GAAzBA,GAAmB,CAAES,IAAI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AO;4CACZpB,KAAK,EAAEjB,WAAW,GAAG,OAAO,GAAG,MAAM;4CACrCgC,QAAQ,EAAEjB,gCAAgC;;8DAE1C,KAAC3B,QAAQ;oDAAc6B,KAAK,EAAE,MAAM;8DAAE,MAEtC;mDAFe,MAAM,CAEV;8DACX,KAAC7B,QAAQ;oDAAe6B,KAAK,EAAE,OAAO;8DAAE,OAExC;mDAFe,OAAO,CAEX;;0CACJ;;kCACL;;0BACA;sBACM;kCAChB,MAAChC,aAAa;;0CACZ,KAACC,MAAM;gCAAC6C,OAAO,EAAC,WAAW;gCAACO,IAAI,EAAC,QAAQ;0CACtCxC,mBAAmB,GAAG,OAAO,GAAG,KAAK;8BAC/B;0CACT,KAACZ,MAAM;gCAACiC,OAAO,EAAE,IAAMvB,qBAAqB,EAAE;0CAAE,QAAM;8BAAS;;sBACjD;;cACX;;MACA,CACT;AACJ,CAAC,AAAC;AAEF,eAAeJ,gBAAgB,CAAC"}
1
+ {"version":3,"sources":["../../../src/components/PanelGroupDialog/PanelGroupDialog.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 { IconButton, Dialog, DialogTitle, DialogContent, DialogActions, Button } from '@mui/material';\nimport CloseIcon from 'mdi-material-ui/Close';\nimport { useState } from 'react';\nimport { usePanelGroupEditor } from '../../context';\nimport { PanelGroupEditorForm, panelGroupEditorFormId, PanelGroupEditorFormProps } from './PanelGroupEditorForm';\n\n/**\n * A dialog for adding or editing a Panel Group. Open and initial state is controlled by the DashboardStore.\n */\nexport function PanelGroupDialog() {\n const panelGroupEditor = usePanelGroupEditor();\n\n // When the user clicks close, start closing but don't call the store yet to keep values stable during animtation\n const [isClosing, setIsClosing] = useState(false);\n const handleClose = () => setIsClosing(true);\n\n // Don't call close on the store until the Dialog has completely transitioned out\n const handleExited = () => {\n panelGroupEditor?.close();\n setIsClosing(false);\n };\n\n // Dialog is open if we have a model and we're not transitioning out\n const isOpen = panelGroupEditor !== undefined && isClosing === false;\n\n const handleSubmit: PanelGroupEditorFormProps['onSubmit'] = (values) => {\n // This shouldn't happen since we don't render the submit button until we have a model, but check to make TS happy\n if (panelGroupEditor === undefined) {\n throw new Error('Cannot apply changes');\n }\n panelGroupEditor.applyChanges(values);\n handleClose();\n };\n\n return (\n <Dialog open={isOpen} TransitionProps={{ onExited: handleExited }}>\n {panelGroupEditor !== undefined && (\n <>\n <DialogTitle>{panelGroupEditor.mode} Panel Group</DialogTitle>\n <IconButton\n aria-label=\"Close\"\n onClick={panelGroupEditor.close}\n sx={(theme) => ({\n position: 'absolute',\n top: theme.spacing(0.5),\n right: theme.spacing(0.5),\n })}\n >\n <CloseIcon />\n </IconButton>\n <DialogContent sx={{ width: '500px' }}>\n <PanelGroupEditorForm initialValues={panelGroupEditor.initialValues} onSubmit={handleSubmit} />\n </DialogContent>\n <DialogActions>\n <Button variant=\"contained\" type=\"submit\" form={panelGroupEditorFormId}>\n {panelGroupEditor.mode === 'Edit' ? 'Apply' : 'Add'}\n </Button>\n <Button onClick={panelGroupEditor.close}>Cancel</Button>\n </DialogActions>\n </>\n )}\n </Dialog>\n );\n}\n"],"names":["IconButton","Dialog","DialogTitle","DialogContent","DialogActions","Button","CloseIcon","useState","usePanelGroupEditor","PanelGroupEditorForm","panelGroupEditorFormId","PanelGroupDialog","panelGroupEditor","isClosing","setIsClosing","handleClose","handleExited","close","isOpen","undefined","handleSubmit","values","Error","applyChanges","open","TransitionProps","onExited","mode","aria-label","onClick","sx","theme","position","top","spacing","right","width","initialValues","onSubmit","variant","type","form"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,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,AAAC;IAEF,qBACE,KAACd,MAAM;QAACuB,IAAI,EAAEN,MAAM;QAAEO,eAAe,EAAE;YAAEC,QAAQ,EAAEV,YAAY;SAAE;kBAC9DJ,gBAAgB,KAAKO,SAAS,kBAC7B;;8BACE,MAACjB,WAAW;;wBAAEU,gBAAgB,CAACe,IAAI;wBAAC,cAAY;;kBAAc;8BAC9D,KAAC3B,UAAU;oBACT4B,YAAU,EAAC,OAAO;oBAClBC,OAAO,EAAEjB,gBAAgB,CAACK,KAAK;oBAC/Ba,EAAE,EAAE,CAACC,KAAK,GAAM,CAAA;4BACdC,QAAQ,EAAE,UAAU;4BACpBC,GAAG,EAAEF,KAAK,CAACG,OAAO,CAAC,GAAG,CAAC;4BACvBC,KAAK,EAAEJ,KAAK,CAACG,OAAO,CAAC,GAAG,CAAC;yBAC1B,CAAA,AAAC;8BAEF,cAAA,KAAC5B,SAAS,KAAG;kBACF;8BACb,KAACH,aAAa;oBAAC2B,EAAE,EAAE;wBAAEM,KAAK,EAAE,OAAO;qBAAE;8BACnC,cAAA,KAAC3B,oBAAoB;wBAAC4B,aAAa,EAAEzB,gBAAgB,CAACyB,aAAa;wBAAEC,QAAQ,EAAElB,YAAY;sBAAI;kBACjF;8BAChB,MAAChB,aAAa;;sCACZ,KAACC,MAAM;4BAACkC,OAAO,EAAC,WAAW;4BAACC,IAAI,EAAC,QAAQ;4BAACC,IAAI,EAAE/B,sBAAsB;sCACnEE,gBAAgB,CAACe,IAAI,KAAK,MAAM,GAAG,OAAO,GAAG,KAAK;0BAC5C;sCACT,KAACtB,MAAM;4BAACwB,OAAO,EAAEjB,gBAAgB,CAACK,KAAK;sCAAE,QAAM;0BAAS;;kBAC1C;;UACf,AACJ;MACM,CACT;AACJ,CAAC"}
@@ -16,7 +16,8 @@ import userEvent from '@testing-library/user-event';
16
16
  import { act } from 'react-dom/test-utils';
17
17
  import { DashboardProvider } from '../../context';
18
18
  import { createDashboardProviderSpy, getTestDashboard, renderWithContext } from '../../test';
19
- import PanelGroupDialog from './PanelGroupDialog';
19
+ import testDashboard from '../../test/testDashboard';
20
+ import { PanelGroupDialog } from './PanelGroupDialog';
20
21
  describe('Add Panel Group', ()=>{
21
22
  const renderDialog = ()=>{
22
23
  const { store , DashboardProviderSpy } = createDashboardProviderSpy();
@@ -37,56 +38,40 @@ describe('Add Panel Group', ()=>{
37
38
  return storeApi;
38
39
  };
39
40
  it('should add new panel group', async ()=>{
40
- // jest.spyOn(dashboardAppSlice, 'useDashboardApp').mockReturnValue(dashboardApp);
41
41
  const storeApi = renderDialog();
42
42
  // Open the dialog for a new panel group
43
- act(()=>storeApi.getState().openPanelGroupDialog());
43
+ act(()=>storeApi.getState().openAddPanelGroup());
44
44
  const nameInput = await screen.findByLabelText(/Name/);
45
45
  userEvent.type(nameInput, 'New Panel Group');
46
46
  userEvent.click(screen.getByText('Add'));
47
- const layouts = storeApi.getState().layouts;
48
- expect(layouts).toContainEqual({
49
- kind: 'Grid',
50
- spec: {
51
- display: {
52
- title: 'New Panel Group',
53
- collapse: {
54
- open: true
55
- }
56
- },
47
+ // TODO: Figure out how to test this without coupling to the store state
48
+ const panelGroups = storeApi.getState().panelGroups;
49
+ expect(panelGroups).toMatchObject({
50
+ '3': {
51
+ id: 3,
52
+ title: 'New Panel Group',
53
+ isCollapsed: false,
57
54
  items: []
58
55
  }
59
56
  });
60
57
  });
61
58
  it('should edit existing panel group', async ()=>{
59
+ var ref;
62
60
  const storeApi = renderDialog();
63
61
  // Open the dialog for an existing panel group
64
- act(()=>storeApi.getState().openPanelGroupDialog(0));
62
+ act(()=>storeApi.getState().openEditPanelGroup(0));
65
63
  const nameInput = await screen.findByLabelText(/Name/);
66
64
  userEvent.clear(nameInput);
67
65
  userEvent.type(nameInput, 'New Name');
68
66
  userEvent.click(screen.getByText('Apply'));
69
- const layouts = storeApi.getState().layouts;
70
- expect(layouts).toContainEqual({
71
- kind: 'Grid',
72
- spec: {
73
- display: {
74
- title: 'New Name',
75
- collapse: {
76
- open: true
77
- }
78
- },
79
- items: [
80
- {
81
- content: {
82
- $ref: '#/spec/panels/cpu'
83
- },
84
- height: 4,
85
- width: 12,
86
- x: 0,
87
- y: 0
88
- }
89
- ]
67
+ // TODO: Figure out how to test this without coupling to the store state
68
+ const panelGroups = storeApi.getState().panelGroups;
69
+ expect(panelGroups).toMatchObject({
70
+ '0': {
71
+ id: 0,
72
+ title: 'New Name',
73
+ isCollapsed: false,
74
+ items: (ref = testDashboard.spec.layouts[0]) === null || ref === void 0 ? void 0 : ref.spec.items
90
75
  }
91
76
  });
92
77
  });
@@ -1 +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 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 // jest.spyOn(dashboardAppSlice, 'useDashboardApp').mockReturnValue(dashboardApp);\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 kind: 'Grid',\n spec: {\n display: {\n title: 'New Panel Group',\n collapse: {\n open: true,\n },\n },\n items: [],\n },\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 kind: 'Grid',\n spec: {\n display: {\n title: 'New Name',\n collapse: {\n open: true,\n },\n },\n items: [{ content: { $ref: '#/spec/panels/cpu' }, height: 4, width: 12, x: 0, y: 0 }],\n },\n });\n });\n});\n"],"names":["screen","userEvent","act","DashboardProvider","createDashboardProviderSpy","getTestDashboard","renderWithContext","PanelGroupDialog","describe","renderDialog","store","DashboardProviderSpy","initialState","dashboardSpec","spec","isEditMode","value","storeApi","undefined","Error","it","getState","openPanelGroupDialog","nameInput","findByLabelText","type","click","getByText","layouts","expect","toContainEqual","kind","display","title","collapse","open","items","clear","content","$ref","height","width","x","y"],"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,CA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AAC;AACL,CAAC,CAAC,CAAC"}
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().openAddPanelGroup());\n\n const nameInput = await screen.findByLabelText(/Name/);\n userEvent.type(nameInput, 'New Panel Group');\n userEvent.click(screen.getByText('Add'));\n\n // TODO: Figure out how to test this without coupling to the store state\n const panelGroups = storeApi.getState().panelGroups;\n expect(panelGroups).toMatchObject({\n '3': {\n id: 3,\n title: 'New Panel Group',\n isCollapsed: false,\n items: [],\n },\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().openEditPanelGroup(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 // TODO: Figure out how to test this without coupling to the store state\n const panelGroups = storeApi.getState().panelGroups;\n expect(panelGroups).toMatchObject({\n '0': {\n id: 0,\n title: 'New Name',\n isCollapsed: false,\n items: testDashboard.spec.layouts[0]?.spec.items,\n },\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","openAddPanelGroup","nameInput","findByLabelText","type","click","getByText","panelGroups","expect","toMatchObject","id","title","isCollapsed","items","openEditPanelGroup","clear","layouts"],"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,SAASC,gBAAgB,QAAQ,oBAAoB,CAAC;AAEtDC,QAAQ,CAAC,iBAAiB,EAAE,IAAM;IAChC,MAAMC,YAAY,GAAG,IAAM;QACzB,MAAM,EAAEC,KAAK,CAAA,EAAEC,oBAAoB,CAAA,EAAE,GAAGR,0BAA0B,EAAE,AAAC;QAErEE,iBAAiB,eACf,MAACH,iBAAiB;YAACU,Y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GAAG,CAAC,IAAMgB,QAAQ,CAACI,QAAQ,EAAE,CAACc,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC;QAErD,MAAMZ,SAAS,GAAG,MAAMxB,MAAM,CAACyB,eAAe,QAAQ,AAAC;QACvDxB,SAAS,CAACoC,KAAK,CAACb,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,wEAAwE;QACxE,MAAMC,WAAW,GAAGX,QAAQ,CAACI,QAAQ,EAAE,CAACO,WAAW,AAAC;QACpDC,MAAM,CAACD,WAAW,CAAC,CAACE,aAAa,CAAC;YAChC,GAAG,EAAE;gBACHC,EAAE,EAAE,CAAC;gBACLC,KAAK,EAAE,UAAU;gBACjBC,WAAW,EAAE,KAAK;gBAClBC,KAAK,EAAE5B,CAAAA,GAA6B,GAA7BA,aAAa,CAACQ,IAAI,CAACuB,OAAO,CAAC,CAAC,CAAC,cAA7B/B,GAA6B,WAAM,GAAnCA,KAAAA,CAAmC,GAAnCA,GAA6B,CAAEQ,IAAI,CAACoB,KAAK;aACjD;SACF,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { PanelGroupEditorValues } from '../../context';
3
+ export interface PanelGroupEditorFormProps {
4
+ initialValues: PanelGroupEditorValues;
5
+ onSubmit: (next: PanelGroupEditorValues) => void;
6
+ }
7
+ export declare function PanelGroupEditorForm(props: PanelGroupEditorFormProps): JSX.Element;
8
+ /**
9
+ * The `id` attribute added to the `PanelGroupEditorForm` component, allowing submit buttons to live outside the form.
10
+ */
11
+ export declare const panelGroupEditorFormId = "panel-group-editor-form";
12
+ //# sourceMappingURL=PanelGroupEditorForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PanelGroupEditorForm.d.ts","sourceRoot":"","sources":["../../../src/components/PanelGroupDialog/PanelGroupEditorForm.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAIvD,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,sBAAsB,CAAC;IACtC,QAAQ,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;CAClD;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,eAsCpE;AAED;;GAEG;AACH,eAAO,MAAM,sBAAsB,4BAA4B,CAAC"}
@@ -0,0 +1,82 @@
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 { useState } from 'react';
15
+ import { FormControl, InputLabel, TextField, Select, MenuItem } from '@mui/material';
16
+ export function PanelGroupEditorForm(props) {
17
+ const { initialValues , onSubmit } = props;
18
+ const [title, setTitle] = useState(initialValues.title);
19
+ const [isCollapsed, setIsCollapsed] = useState(initialValues.isCollapsed);
20
+ const handleCollapsedChange = (e)=>{
21
+ const next = e.target.value;
22
+ setIsCollapsed(next === 'Closed');
23
+ };
24
+ const handleSubmit = (e)=>{
25
+ e.preventDefault();
26
+ onSubmit({
27
+ title,
28
+ isCollapsed
29
+ });
30
+ };
31
+ return /*#__PURE__*/ _jsxs("form", {
32
+ id: panelGroupEditorFormId,
33
+ onSubmit: handleSubmit,
34
+ children: [
35
+ /*#__PURE__*/ _jsx(FormControl, {
36
+ fullWidth: true,
37
+ margin: "normal",
38
+ children: /*#__PURE__*/ _jsx(TextField, {
39
+ required: true,
40
+ label: "Name",
41
+ variant: "outlined",
42
+ value: title,
43
+ onChange: (e)=>setTitle(e.target.value)
44
+ })
45
+ }),
46
+ /*#__PURE__*/ _jsxs(FormControl, {
47
+ fullWidth: true,
48
+ margin: "normal",
49
+ children: [
50
+ /*#__PURE__*/ _jsx(InputLabel, {
51
+ id: "select-collapse-state",
52
+ children: "Collapse State"
53
+ }),
54
+ /*#__PURE__*/ _jsxs(Select, {
55
+ required: true,
56
+ displayEmpty: true,
57
+ labelId: "select-collapse-state",
58
+ label: "Collapse State",
59
+ size: "small",
60
+ value: isCollapsed ? 'Closed' : 'Open',
61
+ onChange: handleCollapsedChange,
62
+ children: [
63
+ /*#__PURE__*/ _jsx(MenuItem, {
64
+ value: "Open",
65
+ children: "Open"
66
+ }),
67
+ /*#__PURE__*/ _jsx(MenuItem, {
68
+ value: "Closed",
69
+ children: "Closed"
70
+ })
71
+ ]
72
+ })
73
+ ]
74
+ })
75
+ ]
76
+ });
77
+ }
78
+ /**
79
+ * The `id` attribute added to the `PanelGroupEditorForm` component, allowing submit buttons to live outside the form.
80
+ */ export const panelGroupEditorFormId = 'panel-group-editor-form';
81
+
82
+ //# sourceMappingURL=PanelGroupEditorForm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/PanelGroupDialog/PanelGroupEditorForm.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 { FormEventHandler, useState } from 'react';\nimport { FormControl, InputLabel, TextField, Select, SelectProps, MenuItem } from '@mui/material';\nimport { PanelGroupEditorValues } from '../../context';\n\ntype CollapsedState = 'Open' | 'Closed';\n\nexport interface PanelGroupEditorFormProps {\n initialValues: PanelGroupEditorValues;\n onSubmit: (next: PanelGroupEditorValues) => void;\n}\n\nexport function PanelGroupEditorForm(props: PanelGroupEditorFormProps) {\n const { initialValues, onSubmit } = props;\n\n const [title, setTitle] = useState(initialValues.title);\n const [isCollapsed, setIsCollapsed] = useState(initialValues.isCollapsed);\n\n const handleCollapsedChange: SelectProps<CollapsedState>['onChange'] = (e) => {\n const next = e.target.value;\n setIsCollapsed(next === 'Closed');\n };\n\n const handleSubmit: FormEventHandler = (e) => {\n e.preventDefault();\n onSubmit({ title, isCollapsed });\n };\n\n return (\n <form id={panelGroupEditorFormId} onSubmit={handleSubmit}>\n <FormControl fullWidth margin=\"normal\">\n <TextField required label=\"Name\" variant=\"outlined\" value={title} onChange={(e) => setTitle(e.target.value)} />\n </FormControl>\n <FormControl fullWidth margin=\"normal\">\n <InputLabel id=\"select-collapse-state\">Collapse State</InputLabel>\n <Select<CollapsedState>\n required\n displayEmpty\n labelId=\"select-collapse-state\"\n label=\"Collapse State\"\n size=\"small\"\n value={isCollapsed ? 'Closed' : 'Open'}\n onChange={handleCollapsedChange}\n >\n <MenuItem value=\"Open\">Open</MenuItem>\n <MenuItem value=\"Closed\">Closed</MenuItem>\n </Select>\n </FormControl>\n </form>\n );\n}\n\n/**\n * The `id` attribute added to the `PanelGroupEditorForm` component, allowing submit buttons to live outside the form.\n */\nexport const panelGroupEditorFormId = 'panel-group-editor-form';\n"],"names":["useState","FormControl","InputLabel","TextField","Select","MenuItem","PanelGroupEditorForm","props","initialValues","onSubmit","title","setTitle","isCollapsed","setIsCollapsed","handleCollapsedChange","e","next","target","value","handleSubmit","preventDefault","form","id","panelGroupEditorFormId","fullWidth","margin","required","label","variant","onChange","displayEmpty","labelId","size"],"mappings":"AAAA,oCAAoC;AACp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EAAE,CAACd,CAAC,GAAKJ,QAAQ,CAACI,CAAC,CAACE,MAAM,CAACC,KAAK,CAAC;kBAAI;cACnG;0BACd,MAACjB,WAAW;gBAACuB,SAAS;gBAACC,MAAM,EAAC,QAAQ;;kCACpC,KAACvB,UAAU;wBAACoB,EAAE,EAAC,uBAAuB;kCAAC,gBAAc;sBAAa;kCAClE,MAAClB,MAAM;wBACLsB,QAAQ;wBACRI,YAAY;wBACZC,OAAO,EAAC,uBAAuB;wBAC/BJ,KAAK,EAAC,gBAAgB;wBACtBK,IAAI,EAAC,OAAO;wBACZd,KAAK,EAAEN,WAAW,GAAG,QAAQ,GAAG,MAAM;wBACtCiB,QAAQ,EAAEf,qBAAqB;;0CAE/B,KAACT,QAAQ;gCAACa,KAAK,EAAC,MAAM;0CAAC,MAAI;8BAAW;0CACtC,KAACb,QAAQ;gCAACa,KAAK,EAAC,QAAQ;0CAAC,QAAM;8BAAW;;sBACnC;;cACG;;MACT,CACP;AACJ,CAAC;AAED;;CAEC,GACD,OAAO,MAAMK,sBAAsB,GAAG,yBAAyB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export * from './PanelGroupDialog';
2
+ export * from './DeletePanelGroupDialog';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/PanelGroupDialog/index.ts"],"names":[],"mappings":"AAaA,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
@@ -0,0 +1,16 @@
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 './PanelGroupDialog';
14
+ export * from './DeletePanelGroupDialog';
15
+
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/components/PanelGroupDialog/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 './PanelGroupDialog';\nexport * from './DeletePanelGroupDialog';\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,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"TimeRangeControls.d.ts","sourceRoot":"","sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAyC,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAY3F,eAAO,MAAM,YAAY,EAAE,UAAU,EAUpC,CAAC;AAEF,wBAAgB,iBAAiB,gBA2DhC"}
1
+ {"version":3,"file":"TimeRangeControls.d.ts","sourceRoot":"","sources":["../../../src/components/TimeRangeControls/TimeRangeControls.tsx"],"names":[],"mappings":";AAeA,OAAO,EAAyC,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAW3F,eAAO,MAAM,YAAY,EAAE,UAAU,EAUpC,CAAC;AAEF,wBAAgB,iBAAiB,gBAsDhC"}
@@ -11,12 +11,11 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- import { useRef, useState } from 'react';
14
+ import { useRef, useState, useMemo } from 'react';
15
15
  import { Box, FormControl, Popover, Stack } from '@mui/material';
16
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 { useDashboard } from '../../context';
17
+ import { isRelativeTimeRange, toAbsoluteTimeRange } from '@perses-dev/core';
18
+ import { useDashboardTimeRange } from '../../context';
20
19
  // TODO: add time shortcut if one does not match duration
21
20
  export const TIME_OPTIONS = [
22
21
  {
@@ -75,14 +74,14 @@ export const TIME_OPTIONS = [
75
74
  }
76
75
  ];
77
76
  export function TimeRangeControls() {
78
- const { timeRange , setTimeRange } = useTimeRange();
79
- const { dashboard } = useDashboard();
80
- const { queryString } = useQueryString();
81
- const defaultTimeRange = getDefaultTimeRange(dashboard.duration, queryString);
82
- // selected form value can be relative or absolute, timeRange from plugin-system is only absolute
83
- const [selectedTimeRange, setSelectedTimeRange] = useState(defaultTimeRange);
77
+ const { timeRange , setTimeRange } = useDashboardTimeRange();
84
78
  const [showCustomDateSelector, setShowCustomDateSelector] = useState(false);
85
79
  const anchorEl = useRef();
80
+ const convertedTimeRange = useMemo(()=>{
81
+ return isRelativeTimeRange(timeRange) ? toAbsoluteTimeRange(timeRange) : timeRange;
82
+ }, [
83
+ timeRange
84
+ ]);
86
85
  return /*#__PURE__*/ _jsxs(Stack, {
87
86
  direction: "row",
88
87
  spacing: 1,
@@ -99,10 +98,9 @@ export function TimeRangeControls() {
99
98
  padding: theme.spacing(2)
100
99
  }),
101
100
  children: /*#__PURE__*/ _jsx(AbsoluteTimePicker, {
102
- initialTimeRange: timeRange,
101
+ initialTimeRange: convertedTimeRange,
103
102
  onChange: (timeRange)=>{
104
103
  setTimeRange(timeRange);
105
- setSelectedTimeRange(timeRange);
106
104
  setShowCustomDateSelector(false);
107
105
  }
108
106
  })
@@ -113,7 +111,7 @@ export function TimeRangeControls() {
113
111
  ref: anchorEl,
114
112
  children: /*#__PURE__*/ _jsx(TimeRangeSelector, {
115
113
  timeOptions: TIME_OPTIONS,
116
- value: selectedTimeRange,
114
+ value: timeRange,
117
115
  onSelectChange: (event)=>{
118
116
  const duration = event.target.value;
119
117
  const relativeTimeInput = {
@@ -121,7 +119,6 @@ export function TimeRangeControls() {
121
119
  end: new Date()
122
120
  };
123
121
  setTimeRange(relativeTimeInput);
124
- setSelectedTimeRange(relativeTimeInput);
125
122
  setShowCustomDateSelector(false);
126
123
  },
127
124
  onCustomClick: ()=>{