@perses-dev/dashboards 0.12.0 → 0.13.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 (197) hide show
  1. package/dist/cjs/components/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
  2. package/dist/cjs/components/Dashboard/index.js +28 -0
  3. package/dist/cjs/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +9 -23
  4. package/dist/cjs/components/DashboardToolbar/index.js +28 -0
  5. package/dist/cjs/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +2 -3
  6. package/dist/cjs/components/DeletePanelDialog/index.js +28 -0
  7. package/dist/cjs/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
  8. package/dist/cjs/components/DeletePanelGroupDialog/index.js +28 -0
  9. package/dist/cjs/components/GridLayout/GridItemContent.js +11 -1
  10. package/dist/cjs/components/Panel/Panel.js +30 -89
  11. package/dist/cjs/components/Panel/Panel.test.js +93 -47
  12. package/dist/cjs/components/Panel/PanelHeader.js +116 -0
  13. package/dist/cjs/components/Panel/index.js +0 -1
  14. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +9 -15
  15. package/dist/cjs/components/PanelDrawer/PanelPreview.js +13 -20
  16. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
  17. package/dist/cjs/components/PanelGroupDialog/index.js +0 -1
  18. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
  19. package/dist/cjs/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +67 -0
  20. package/dist/cjs/components/UnsavedChangesConfirmationDialog/index.js +28 -0
  21. package/dist/cjs/components/Variables/Variable.js +18 -11
  22. package/dist/cjs/components/index.js +4 -0
  23. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +24 -18
  24. package/dist/cjs/context/DashboardProvider/common.js +3 -3
  25. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +2 -4
  26. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +47 -52
  27. package/dist/cjs/context/DashboardProvider/panel-slice.js +2 -13
  28. package/dist/cjs/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
  29. package/dist/cjs/context/TemplateVariableProvider/index.js +28 -0
  30. package/dist/cjs/context/TemplateVariableProvider/query-params.js +79 -0
  31. package/dist/cjs/context/TemplateVariableProvider/query-params.test.js +82 -0
  32. package/dist/cjs/context/index.js +1 -1
  33. package/dist/cjs/context/{useDashboardSpec.js → useDashboard.js} +20 -16
  34. package/dist/cjs/test/plugin-registry.js +14 -54
  35. package/dist/cjs/test/render.js +6 -1
  36. package/dist/cjs/utils/component-ids.js +31 -0
  37. package/dist/cjs/views/ViewDashboard/DashboardApp.js +40 -10
  38. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +1 -1
  39. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +1 -1
  40. package/dist/components/{Dashboard.d.ts → Dashboard/Dashboard.d.ts} +0 -0
  41. package/dist/components/Dashboard/Dashboard.d.ts.map +1 -0
  42. package/dist/components/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
  43. package/dist/components/Dashboard/Dashboard.js.map +1 -0
  44. package/dist/components/Dashboard/index.d.ts +2 -0
  45. package/dist/components/Dashboard/index.d.ts.map +1 -0
  46. package/dist/components/Dashboard/index.js +15 -0
  47. package/dist/components/Dashboard/index.js.map +1 -0
  48. package/dist/components/{DashboardToolbar.d.ts → DashboardToolbar/DashboardToolbar.d.ts} +2 -0
  49. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -0
  50. package/dist/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +5 -19
  51. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -0
  52. package/dist/components/DashboardToolbar/index.d.ts +2 -0
  53. package/dist/components/DashboardToolbar/index.d.ts.map +1 -0
  54. package/dist/components/DashboardToolbar/index.js +15 -0
  55. package/dist/components/DashboardToolbar/index.js.map +1 -0
  56. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts +3 -0
  57. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -0
  58. package/dist/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +1 -2
  59. package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -0
  60. package/dist/components/DeletePanelDialog/index.d.ts +2 -0
  61. package/dist/components/DeletePanelDialog/index.d.ts.map +1 -0
  62. package/dist/components/DeletePanelDialog/index.js +15 -0
  63. package/dist/components/DeletePanelDialog/index.js.map +1 -0
  64. package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.d.ts +0 -0
  65. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
  66. package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
  67. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
  68. package/dist/components/DeletePanelGroupDialog/index.d.ts +2 -0
  69. package/dist/components/DeletePanelGroupDialog/index.d.ts.map +1 -0
  70. package/dist/components/DeletePanelGroupDialog/index.js +15 -0
  71. package/dist/components/DeletePanelGroupDialog/index.js.map +1 -0
  72. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  73. package/dist/components/GridLayout/GridItemContent.js +12 -2
  74. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  75. package/dist/components/Panel/Panel.d.ts +3 -3
  76. package/dist/components/Panel/Panel.d.ts.map +1 -1
  77. package/dist/components/Panel/Panel.js +32 -91
  78. package/dist/components/Panel/Panel.js.map +1 -1
  79. package/dist/components/Panel/Panel.test.js +95 -49
  80. package/dist/components/Panel/Panel.test.js.map +1 -1
  81. package/dist/components/Panel/PanelHeader.d.ts +16 -0
  82. package/dist/components/Panel/PanelHeader.d.ts.map +1 -0
  83. package/dist/components/Panel/PanelHeader.js +105 -0
  84. package/dist/components/Panel/PanelHeader.js.map +1 -0
  85. package/dist/components/Panel/index.d.ts +0 -1
  86. package/dist/components/Panel/index.d.ts.map +1 -1
  87. package/dist/components/Panel/index.js +0 -1
  88. package/dist/components/Panel/index.js.map +1 -1
  89. package/dist/components/PanelDrawer/PanelDrawer.test.js +10 -16
  90. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  91. package/dist/components/PanelDrawer/PanelPreview.d.ts +2 -2
  92. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
  93. package/dist/components/PanelDrawer/PanelPreview.js +13 -20
  94. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  95. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
  96. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
  97. package/dist/components/PanelGroupDialog/index.d.ts +0 -1
  98. package/dist/components/PanelGroupDialog/index.d.ts.map +1 -1
  99. package/dist/components/PanelGroupDialog/index.js +0 -1
  100. package/dist/components/PanelGroupDialog/index.js.map +1 -1
  101. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
  102. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  103. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts +8 -0
  104. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts.map +1 -0
  105. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +56 -0
  106. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js.map +1 -0
  107. package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts +2 -0
  108. package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts.map +1 -0
  109. package/dist/components/UnsavedChangesConfirmationDialog/index.js +15 -0
  110. package/dist/components/UnsavedChangesConfirmationDialog/index.js.map +1 -0
  111. package/dist/components/Variables/Variable.d.ts.map +1 -1
  112. package/dist/components/Variables/Variable.js +19 -12
  113. package/dist/components/Variables/Variable.js.map +1 -1
  114. package/dist/components/index.d.ts +4 -0
  115. package/dist/components/index.d.ts.map +1 -1
  116. package/dist/components/index.js +4 -0
  117. package/dist/components/index.js.map +1 -1
  118. package/dist/context/DashboardProvider/DashboardProvider.d.ts +4 -4
  119. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  120. package/dist/context/DashboardProvider/DashboardProvider.js +26 -20
  121. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  122. package/dist/context/DashboardProvider/common.d.ts +1 -1
  123. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  124. package/dist/context/DashboardProvider/common.js +4 -4
  125. package/dist/context/DashboardProvider/common.js.map +1 -1
  126. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -2
  127. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  128. package/dist/context/DashboardProvider/dashboard-provider-api.js +2 -4
  129. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  130. package/dist/context/DashboardProvider/index.d.ts +1 -0
  131. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  132. package/dist/context/DashboardProvider/index.js.map +1 -1
  133. package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -15
  134. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  135. package/dist/context/DashboardProvider/panel-group-slice.js +38 -49
  136. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  137. package/dist/context/DashboardProvider/panel-slice.d.ts +0 -9
  138. package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -1
  139. package/dist/context/DashboardProvider/panel-slice.js +2 -13
  140. package/dist/context/DashboardProvider/panel-slice.js.map +1 -1
  141. package/dist/context/{TemplateVariableProvider.d.ts → TemplateVariableProvider/TemplateVariableProvider.d.ts} +0 -0
  142. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -0
  143. package/dist/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
  144. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -0
  145. package/dist/context/TemplateVariableProvider/index.d.ts +2 -0
  146. package/dist/context/TemplateVariableProvider/index.d.ts.map +1 -0
  147. package/dist/context/TemplateVariableProvider/index.js +15 -0
  148. package/dist/context/TemplateVariableProvider/index.js.map +1 -0
  149. package/dist/context/TemplateVariableProvider/query-params.d.ts +12 -0
  150. package/dist/context/TemplateVariableProvider/query-params.d.ts.map +1 -0
  151. package/dist/context/TemplateVariableProvider/query-params.js +64 -0
  152. package/dist/context/TemplateVariableProvider/query-params.js.map +1 -0
  153. package/dist/context/TemplateVariableProvider/query-params.test.d.ts +2 -0
  154. package/dist/context/TemplateVariableProvider/query-params.test.d.ts.map +1 -0
  155. package/dist/context/TemplateVariableProvider/query-params.test.js +80 -0
  156. package/dist/context/TemplateVariableProvider/query-params.test.js.map +1 -0
  157. package/dist/context/index.d.ts +1 -1
  158. package/dist/context/index.d.ts.map +1 -1
  159. package/dist/context/index.js +1 -1
  160. package/dist/context/index.js.map +1 -1
  161. package/dist/context/useDashboard.d.ts +6 -0
  162. package/dist/context/useDashboard.d.ts.map +1 -0
  163. package/dist/context/{useDashboardSpec.js → useDashboard.js} +19 -15
  164. package/dist/context/useDashboard.js.map +1 -0
  165. package/dist/test/plugin-registry.d.ts +2 -11
  166. package/dist/test/plugin-registry.d.ts.map +1 -1
  167. package/dist/test/plugin-registry.js +12 -49
  168. package/dist/test/plugin-registry.js.map +1 -1
  169. package/dist/test/render.d.ts.map +1 -1
  170. package/dist/test/render.js +6 -1
  171. package/dist/test/render.js.map +1 -1
  172. package/dist/utils/component-ids.d.ts +8 -0
  173. package/dist/utils/component-ids.d.ts.map +1 -0
  174. package/dist/utils/component-ids.js +27 -0
  175. package/dist/utils/component-ids.js.map +1 -0
  176. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  177. package/dist/views/ViewDashboard/DashboardApp.js +40 -5
  178. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  179. package/dist/views/ViewDashboard/ViewDashboard.js +1 -1
  180. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  181. package/dist/views/ViewDashboard/tests/panelGroups.test.js +1 -1
  182. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  183. package/package.json +4 -4
  184. package/dist/components/Dashboard.d.ts.map +0 -1
  185. package/dist/components/Dashboard.js.map +0 -1
  186. package/dist/components/DashboardToolbar.d.ts.map +0 -1
  187. package/dist/components/DashboardToolbar.js.map +0 -1
  188. package/dist/components/Panel/DeletePanelDialog.d.ts +0 -4
  189. package/dist/components/Panel/DeletePanelDialog.d.ts.map +0 -1
  190. package/dist/components/Panel/DeletePanelDialog.js.map +0 -1
  191. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +0 -1
  192. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +0 -1
  193. package/dist/context/TemplateVariableProvider.d.ts.map +0 -1
  194. package/dist/context/TemplateVariableProvider.js.map +0 -1
  195. package/dist/context/useDashboardSpec.d.ts +0 -11
  196. package/dist/context/useDashboardSpec.d.ts.map +0 -1
  197. package/dist/context/useDashboardSpec.js.map +0 -1
@@ -0,0 +1,116 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "PanelHeader", {
18
+ enumerable: true,
19
+ get: ()=>PanelHeader
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _components = require("@perses-dev/components");
24
+ const _informationOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/InformationOutline"));
25
+ const _pencilOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/PencilOutline"));
26
+ const _deleteOutline = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/DeleteOutline"));
27
+ const _dragVertical = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/DragVertical"));
28
+ function _interopRequireDefault(obj) {
29
+ return obj && obj.__esModule ? obj : {
30
+ default: obj
31
+ };
32
+ }
33
+ function PanelHeader({ id , title , description , editHandlers , isHovered , sx , ...rest }) {
34
+ const titleElementId = `${id}-title`;
35
+ const descriptionTooltipId = `${id}-description`;
36
+ // Don't show any actions unless panel is hovered
37
+ let action = undefined;
38
+ if (isHovered) {
39
+ if (editHandlers !== undefined) {
40
+ // If there are edit handlers, always just show the edit buttons
41
+ action = /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
42
+ direction: "row",
43
+ alignItems: "center",
44
+ spacing: 0.5,
45
+ children: [
46
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(HeaderIconButton, {
47
+ "aria-label": "edit panel",
48
+ size: "small",
49
+ onClick: editHandlers.onEditPanelClick,
50
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pencilOutline.default, {})
51
+ }),
52
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(HeaderIconButton, {
53
+ "aria-label": "delete panel",
54
+ size: "small",
55
+ onClick: editHandlers.onDeletePanelClick,
56
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_deleteOutline.default, {})
57
+ }),
58
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(HeaderIconButton, {
59
+ "aria-label": "drag handle",
60
+ size: "small",
61
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_dragVertical.default, {
62
+ className: "drag-handle",
63
+ sx: {
64
+ cursor: 'grab'
65
+ }
66
+ })
67
+ })
68
+ ]
69
+ });
70
+ } else if (description !== undefined) {
71
+ // If there aren't edit handlers and we have a description, show a button with a tooltip for the panel description
72
+ action = /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.InfoTooltip, {
73
+ id: descriptionTooltipId,
74
+ description: description,
75
+ placement: _components.TooltipPlacement.Bottom,
76
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(HeaderIconButton, {
77
+ "aria-label": "Panel Description",
78
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_informationOutline.default, {
79
+ "aria-describedby": "info-tooltip",
80
+ "aria-hidden": false,
81
+ sx: {
82
+ color: (theme)=>theme.palette.grey[700]
83
+ }
84
+ })
85
+ })
86
+ });
87
+ }
88
+ }
89
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.CardHeader, {
90
+ id: id,
91
+ component: "header",
92
+ "aria-labelledby": titleElementId,
93
+ "aria-describedby": descriptionTooltipId,
94
+ disableTypography: true,
95
+ title: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
96
+ id: titleElementId,
97
+ variant: "subtitle1",
98
+ sx: {
99
+ whiteSpace: 'nowrap',
100
+ overflow: 'hidden',
101
+ textOverflow: 'ellipsis'
102
+ },
103
+ children: title
104
+ }),
105
+ action: action,
106
+ sx: (0, _components.combineSx)((theme)=>({
107
+ padding: theme.spacing(1),
108
+ borderBottom: `solid 1px ${theme.palette.divider}`
109
+ }), sx),
110
+ ...rest
111
+ });
112
+ }
113
+ const HeaderIconButton = (0, _material.styled)(_material.IconButton)(({ theme })=>({
114
+ borderRadius: theme.shape.borderRadius,
115
+ padding: '4px'
116
+ }));
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _exportStar(require("./Panel"), exports);
18
- _exportStar(require("./DeletePanelDialog"), exports);
19
18
  function _exportStar(from, to) {
20
19
  Object.keys(from).forEach(function(k) {
21
20
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  const _jsxRuntime = require("react/jsx-runtime");
18
- const _pluginSystem = require("@perses-dev/plugin-system");
19
18
  const _react = require("@testing-library/react");
20
19
  const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
21
20
  const _testUtils = require("react-dom/test-utils");
@@ -29,21 +28,16 @@ function _interopRequireDefault(obj) {
29
28
  }
30
29
  describe('Panel Drawer', ()=>{
31
30
  const renderPanelDrawer = ()=>{
32
- const { addMockPlugin , pluginRegistryProps } = (0, _test.mockPluginRegistryProps)();
33
- addMockPlugin('Panel', 'TimeSeriesChart', _test.FAKE_PANEL_PLUGIN);
34
31
  const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
35
- (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.PluginRegistry, {
36
- ...pluginRegistryProps,
37
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_dashboardProvider.DashboardProvider, {
38
- initialState: {
39
- dashboardSpec: (0, _test.getTestDashboard)().spec,
40
- isEditMode: true
41
- },
42
- children: [
43
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardProviderSpy, {}),
44
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelDrawer.PanelDrawer, {})
45
- ]
46
- })
32
+ (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_dashboardProvider.DashboardProvider, {
33
+ initialState: {
34
+ dashboardResource: (0, _test.getTestDashboard)(),
35
+ isEditMode: true
36
+ },
37
+ children: [
38
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardProviderSpy, {}),
39
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelDrawer.PanelDrawer, {})
40
+ ]
47
41
  }));
48
42
  const { value: storeApi } = store;
49
43
  if (storeApi === undefined) {
@@ -21,34 +21,27 @@ Object.defineProperty(exports, "PanelPreview", {
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _material = require("@mui/material");
23
23
  const _panel = require("../Panel");
24
- function PanelPreview({ name , description , kind , spec , groupId }) {
25
- const previewValues = {
26
- definition: {
27
- kind: 'Panel',
28
- spec: {
29
- display: {
30
- name,
31
- description
32
- },
33
- plugin: {
34
- kind,
35
- spec
36
- }
24
+ function PanelPreview({ name , description , kind , spec }) {
25
+ const definition = {
26
+ kind: 'Panel',
27
+ spec: {
28
+ display: {
29
+ name,
30
+ description: description === '' ? undefined : description
31
+ },
32
+ plugin: {
33
+ kind,
34
+ spec
37
35
  }
38
- },
39
- // TODO: this shouldn't be necessary for preview
40
- panelGroupItemId: {
41
- panelGroupId: groupId,
42
- panelGroupItemLayoutId: ''
43
36
  }
44
37
  };
45
- if (!kind) {
38
+ if (kind === '') {
46
39
  return null;
47
40
  }
48
41
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
49
42
  height: 300,
50
43
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panel.Panel, {
51
- ...previewValues
44
+ definition: definition
52
45
  })
53
46
  });
54
47
  }
@@ -31,7 +31,7 @@ describe('Add Panel Group', ()=>{
31
31
  const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
32
32
  (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_context.DashboardProvider, {
33
33
  initialState: {
34
- dashboardSpec: (0, _test.getTestDashboard)().spec,
34
+ dashboardResource: (0, _test.getTestDashboard)(),
35
35
  isEditMode: true
36
36
  },
37
37
  children: [
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _exportStar(require("./PanelGroupDialog"), exports);
18
- _exportStar(require("./DeletePanelGroupDialog"), exports);
19
18
  function _exportStar(from, to) {
20
19
  Object.keys(from).forEach(function(k) {
21
20
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -42,7 +42,7 @@ describe('TimeRangeControls', ()=>{
42
42
  };
43
43
  beforeEach(()=>{
44
44
  initialState = {
45
- dashboardSpec: _testDashboard.default.spec
45
+ dashboardResource: _testDashboard.default
46
46
  };
47
47
  });
48
48
  const renderTimeRangeControls = ()=>{
@@ -0,0 +1,67 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "UnsavedChangesConfirmationDialog", {
18
+ enumerable: true,
19
+ get: ()=>UnsavedChangesConfirmationDialog
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _close = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Close"));
24
+ function _interopRequireDefault(obj) {
25
+ return obj && obj.__esModule ? obj : {
26
+ default: obj
27
+ };
28
+ }
29
+ const UnsavedChangesConfirmationDialog = ({ isOpen , onSave , onClose })=>{
30
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Dialog, {
31
+ open: isOpen,
32
+ children: [
33
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogTitle, {
34
+ children: "Unsaved Changes"
35
+ }),
36
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
37
+ "aria-label": "Close",
38
+ onClick: onClose,
39
+ sx: (theme)=>({
40
+ position: 'absolute',
41
+ top: theme.spacing(0.5),
42
+ right: theme.spacing(0.5)
43
+ }),
44
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_close.default, {})
45
+ }),
46
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogContent, {
47
+ sx: {
48
+ width: '500px'
49
+ },
50
+ children: "You have unsaved changes in this dashboard. Would you like to save these changes?"
51
+ }),
52
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.DialogActions, {
53
+ children: [
54
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
55
+ variant: "contained",
56
+ onClick: onSave,
57
+ children: "Save"
58
+ }),
59
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
60
+ onClick: onClose,
61
+ children: "Cancel"
62
+ })
63
+ ]
64
+ })
65
+ ]
66
+ });
67
+ };
@@ -0,0 +1,28 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./UnsavedChangesConfirmationDialog"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -75,14 +75,17 @@ function ListVariable({ name }) {
75
75
  });
76
76
  }
77
77
  const variablesValueKey = getVariableValuesKey(variables);
78
+ const { timeRange } = (0, _pluginSystem.useTimeRange)();
78
79
  const variablesOptionsQuery = (0, _reactQuery.useQuery)([
79
80
  name,
80
81
  definition,
81
- variablesValueKey
82
+ variablesValueKey,
83
+ timeRange
82
84
  ], async ()=>{
83
85
  const resp = await (variablePlugin === null || variablePlugin === void 0 ? void 0 : variablePlugin.getVariableOptions(spec, {
84
86
  datasourceStore,
85
- variables
87
+ variables,
88
+ timeRange
86
89
  }));
87
90
  var ref;
88
91
  return (ref = resp === null || resp === void 0 ? void 0 : resp.data) !== null && ref !== void 0 ? ref : [];
@@ -128,22 +131,26 @@ function ListVariable({ name }) {
128
131
  options,
129
132
  allowAllValue
130
133
  ]);
131
- (0, _react.useEffect)(()=>{
132
- const firstOption = finalOptions === null || finalOptions === void 0 ? void 0 : finalOptions[0];
133
- const valueIsInOptions = Boolean(finalOptions.find((v)=>{
134
+ const valueIsInOptions = (0, _react.useMemo)(()=>Boolean(finalOptions.find((v)=>{
134
135
  if (allowMultiple) {
135
136
  return value.includes(v.value);
136
137
  }
137
138
  return value === v.value;
138
- }));
139
+ })), [
140
+ finalOptions,
141
+ value,
142
+ allowMultiple
143
+ ]);
144
+ let selectValue = value;
145
+ if (!valueIsInOptions) {
146
+ selectValue = allowMultiple ? [] : '';
147
+ }
148
+ (0, _react.useEffect)(()=>{
149
+ const firstOption = finalOptions === null || finalOptions === void 0 ? void 0 : finalOptions[0];
139
150
  // If there is no value but there are options, set the value to the first option.
140
151
  if (!value && firstOption) {
141
152
  setVariableValue(name, firstOption.value);
142
153
  }
143
- // If there is a value but it's not in the options, select the first value or set to null
144
- if (value && !valueIsInOptions && !definition.spec.default_value) {
145
- setVariableValue(name, (firstOption === null || firstOption === void 0 ? void 0 : firstOption.value) || null);
146
- }
147
154
  }, [
148
155
  finalOptions,
149
156
  setVariableValue,
@@ -167,7 +174,7 @@ function ListVariable({ name }) {
167
174
  },
168
175
  id: name,
169
176
  label: name,
170
- value: value !== null && value !== void 0 ? value : '',
177
+ value: selectValue,
171
178
  onChange: (e)=>{
172
179
  // Must be selected
173
180
  if (e.target.value === null || e.target.value.length === 0) {
@@ -15,11 +15,15 @@ Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
17
  _exportStar(require("./Dashboard"), exports);
18
+ _exportStar(require("./DashboardToolbar"), exports);
19
+ _exportStar(require("./DeletePanelDialog"), exports);
20
+ _exportStar(require("./DeletePanelGroupDialog"), exports);
18
21
  _exportStar(require("./GridLayout"), exports);
19
22
  _exportStar(require("./Panel"), exports);
20
23
  _exportStar(require("./PanelDrawer"), exports);
21
24
  _exportStar(require("./PanelGroupDialog"), exports);
22
25
  _exportStar(require("./TimeRangeControls"), exports);
26
+ _exportStar(require("./UnsavedChangesConfirmationDialog"), exports);
23
27
  _exportStar(require("./Variables"), exports);
24
28
  function _exportStar(from, to) {
25
29
  Object.keys(from).forEach(function(k) {
@@ -51,10 +51,20 @@ function useDashboardStore(selector) {
51
51
  return (0, _zustand.useStore)(store, selector, _shallow.default);
52
52
  }
53
53
  function DashboardProvider(props) {
54
- const { children , initialState: { dashboardSpec , isEditMode } , } = props;
55
- const { layouts , panels } = dashboardSpec;
56
- const dashboardStore = (0, _zustand.createStore)()((0, _immer.immer)((0, _middleware.devtools)((...args)=>{
57
- const [set, get] = args;
54
+ const createDashboardStore = (0, _react.useCallback)(initStore, [
55
+ props
56
+ ]);
57
+ const [store] = (0, _react.useState)(createDashboardStore(props)); // prevent calling createDashboardStore every time it rerenders
58
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardContext.Provider, {
59
+ value: store,
60
+ children: props.children
61
+ });
62
+ }
63
+ function initStore(props) {
64
+ const { initialState: { dashboardResource , isEditMode } , } = props;
65
+ const { spec: { layouts , panels , duration } , metadata , } = dashboardResource;
66
+ const store = (0, _zustand.createStore)()((0, _immer.immer)((0, _middleware.devtools)((...args)=>{
67
+ const [set] = args;
58
68
  return {
59
69
  ...(0, _panelGroupSlice.createPanelGroupSlice)(layouts)(...args),
60
70
  ...(0, _panelSlice.createPanelSlice)(panels)(...args),
@@ -62,27 +72,23 @@ function DashboardProvider(props) {
62
72
  ...(0, _deletePanelGroupSlice.createDeletePanelGroupSlice)(...args),
63
73
  ...(0, _panelEditorSlice.createPanelEditorSlice)()(...args),
64
74
  ...(0, _deletePanelSlice.createDeletePanelSlice)()(...args),
75
+ metadata,
65
76
  defaultTimeRange: {
66
- pastDuration: dashboardSpec.duration
77
+ pastDuration: duration
67
78
  },
68
79
  isEditMode: !!isEditMode,
69
80
  setEditMode: (isEditMode)=>set({
70
81
  isEditMode
71
82
  }),
72
- reset: ()=>{
73
- const { resetPanels , resetPanelGroups } = get();
74
- resetPanels();
75
- resetPanelGroups();
76
- },
77
- save: ()=>{
78
- const { savePanels , savePanelGroups } = get();
79
- savePanels();
80
- savePanelGroups();
83
+ setDashboard: ({ spec: { panels , layouts } })=>{
84
+ set((state)=>{
85
+ const { panelGroups , panelGroupOrder } = (0, _panelGroupSlice.convertLayoutsToPanelGroups)(layouts);
86
+ state.panels = panels;
87
+ state.panelGroups = panelGroups;
88
+ state.panelGroupOrder = panelGroupOrder;
89
+ });
81
90
  }
82
91
  };
83
92
  })));
84
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardContext.Provider, {
85
- value: dashboardStore,
86
- children: children
87
- });
93
+ return store;
88
94
  }
@@ -20,9 +20,9 @@ Object.defineProperty(exports, "generateId", {
20
20
  enumerable: true,
21
21
  get: ()=>generateId
22
22
  });
23
+ if (globalThis.dashboardStoreId === undefined) {
24
+ globalThis.dashboardStoreId = 0;
25
+ }
23
26
  function generateId() {
24
- if (globalThis.dashboardStoreId === undefined) {
25
- globalThis.dashboardStoreId = -1;
26
- }
27
27
  return globalThis.dashboardStoreId++;
28
28
  }
@@ -44,13 +44,11 @@ function useEditMode() {
44
44
  }));
45
45
  }
46
46
  function useDashboardActions() {
47
- const save = (0, _dashboardProvider.useDashboardStore)((store)=>store.save);
48
- const reset = (0, _dashboardProvider.useDashboardStore)((store)=>store.reset);
47
+ const setDashboard = (0, _dashboardProvider.useDashboardStore)((store)=>store.setDashboard);
49
48
  const openAddPanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanelGroup);
50
49
  const openAddPanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanel);
51
50
  return {
52
- save,
53
- reset,
51
+ setDashboard,
54
52
  openAddPanelGroup,
55
53
  openAddPanel: ()=>openAddPanel(undefined)
56
54
  };
@@ -14,65 +14,24 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "createPanelGroupSlice", {
18
- enumerable: true,
19
- get: ()=>createPanelGroupSlice
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ createPanelGroupSlice: ()=>createPanelGroupSlice,
25
+ convertLayoutsToPanelGroups: ()=>convertLayoutsToPanelGroups
20
26
  });
21
27
  const _core = require("@perses-dev/core");
22
28
  const _common = require("./common");
23
29
  function createPanelGroupSlice(layouts) {
24
- // Convert the initial layouts from the JSON
25
- const panelGroups = {};
26
- const panelGroupIdOrder = [];
27
- for (const layout of layouts){
28
- var ref, ref1, ref2;
29
- const itemLayouts = [];
30
- const itemPanelKeys = {};
31
- // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
32
- for (const item of layout.spec.items){
33
- const panelGroupLayoutId = (0, _common.generateId)().toString();
34
- itemLayouts.push({
35
- i: panelGroupLayoutId,
36
- w: item.width,
37
- h: item.height,
38
- x: item.x,
39
- y: item.y
40
- });
41
- itemPanelKeys[panelGroupLayoutId] = (0, _core.getPanelKeyFromRef)(item.content);
42
- }
43
- // Create the panel group and keep track of the ID order
44
- const panelGroupId = (0, _common.generateId)();
45
- panelGroups[panelGroupId] = {
46
- id: panelGroupId,
47
- isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
48
- title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
49
- itemLayouts,
50
- itemPanelKeys
51
- };
52
- panelGroupIdOrder.push(panelGroupId);
53
- }
30
+ const { panelGroups , panelGroupOrder } = convertLayoutsToPanelGroups(layouts);
54
31
  // Return the state creator function for Zustand
55
32
  return (set)=>({
56
33
  panelGroups,
57
- panelGroupOrder: panelGroupIdOrder,
58
- previousPanelGroupState: {
59
- panelGroups,
60
- panelGroupIdOrder
61
- },
62
- savePanelGroups () {
63
- set((state)=>{
64
- state.previousPanelGroupState = {
65
- panelGroups: state.panelGroups,
66
- panelGroupIdOrder: state.panelGroupOrder
67
- };
68
- });
69
- },
70
- resetPanelGroups () {
71
- set((state)=>{
72
- state.panelGroups = state.previousPanelGroupState.panelGroups;
73
- state.panelGroupOrder = state.previousPanelGroupState.panelGroupIdOrder;
74
- });
75
- },
34
+ panelGroupOrder,
76
35
  swapPanelGroups (x, y) {
77
36
  set((state)=>{
78
37
  if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {
@@ -101,3 +60,39 @@ function createPanelGroupSlice(layouts) {
101
60
  }
102
61
  });
103
62
  }
63
+ function convertLayoutsToPanelGroups(layouts) {
64
+ // Convert the initial layouts from the JSON
65
+ const panelGroups = {};
66
+ const panelGroupIdOrder = [];
67
+ for (const layout of layouts){
68
+ var ref, ref1, ref2;
69
+ const itemLayouts = [];
70
+ const itemPanelKeys = {};
71
+ // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
72
+ for (const item of layout.spec.items){
73
+ const panelGroupLayoutId = (0, _common.generateId)().toString();
74
+ itemLayouts.push({
75
+ i: panelGroupLayoutId,
76
+ w: item.width,
77
+ h: item.height,
78
+ x: item.x,
79
+ y: item.y
80
+ });
81
+ itemPanelKeys[panelGroupLayoutId] = (0, _core.getPanelKeyFromRef)(item.content);
82
+ }
83
+ // Create the panel group and keep track of the ID order
84
+ const panelGroupId = (0, _common.generateId)();
85
+ panelGroups[panelGroupId] = {
86
+ id: panelGroupId,
87
+ isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
88
+ title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
89
+ itemLayouts,
90
+ itemPanelKeys
91
+ };
92
+ panelGroupIdOrder.push(panelGroupId);
93
+ }
94
+ return {
95
+ panelGroups,
96
+ panelGroupOrder: panelGroupIdOrder
97
+ };
98
+ }
@@ -19,18 +19,7 @@ Object.defineProperty(exports, "createPanelSlice", {
19
19
  get: ()=>createPanelSlice
20
20
  });
21
21
  function createPanelSlice(panels) {
22
- return (set)=>({
23
- panels,
24
- previousPanels: panels,
25
- resetPanels () {
26
- set((state)=>{
27
- state.panels = state.previousPanels;
28
- });
29
- },
30
- savePanels () {
31
- set((state)=>{
32
- state.previousPanels = state.panels;
33
- });
34
- }
22
+ return ()=>({
23
+ panels
35
24
  });
36
25
  }