@perses-dev/dashboards 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/dist/cjs/components/Dashboard.js +7 -11
  2. package/dist/cjs/components/DashboardToolbar.js +4 -4
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +13 -13
  4. package/dist/cjs/components/GridLayout/GridLayout.js +24 -21
  5. package/dist/cjs/components/GridLayout/GridTitle.js +27 -5
  6. package/dist/cjs/components/Panel/DeletePanelDialog.js +91 -0
  7. package/dist/cjs/components/Panel/Panel.js +16 -5
  8. package/dist/cjs/components/Panel/Panel.test.js +12 -4
  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 +8 -12
  12. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +77 -35
  13. package/dist/cjs/components/PanelDrawer/PanelPreview.js +48 -0
  14. package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +86 -0
  15. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +12 -19
  16. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +10 -31
  17. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +2 -2
  18. package/dist/cjs/components/Variables/Variable.js +19 -11
  19. package/dist/cjs/components/Variables/VariableEditor.js +207 -0
  20. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +236 -0
  21. package/dist/cjs/components/Variables/VariableEditorForm/index.js +28 -0
  22. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +88 -0
  23. package/dist/cjs/components/Variables/VariableList.js +50 -69
  24. package/dist/cjs/components/Variables/index.js +1 -0
  25. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +70 -0
  26. package/dist/cjs/context/DashboardProvider/common.js +18 -0
  27. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +71 -0
  28. package/dist/cjs/context/DashboardProvider/index.js +29 -0
  29. package/dist/cjs/context/DashboardProvider/layout-slice.js +200 -0
  30. package/dist/cjs/context/DashboardProvider/panel-editing-slice.js +156 -0
  31. package/dist/{context/DashboardAppSlice.js → cjs/context/DashboardProvider/panel-group-slice.js} +18 -25
  32. package/dist/cjs/context/DatasourceStoreProvider.js +109 -7
  33. package/dist/cjs/context/TemplateVariableProvider.js +8 -1
  34. package/dist/cjs/context/index.js +0 -2
  35. package/dist/cjs/test/testDashboard.js +13 -1
  36. package/dist/cjs/views/ViewDashboard/DashboardApp.js +6 -7
  37. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +165 -0
  38. package/dist/components/Dashboard.d.ts +1 -4
  39. package/dist/components/Dashboard.d.ts.map +1 -1
  40. package/dist/components/Dashboard.js +8 -12
  41. package/dist/components/Dashboard.js.map +1 -1
  42. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  43. package/dist/components/DashboardToolbar.js +5 -5
  44. package/dist/components/DashboardToolbar.js.map +1 -1
  45. package/dist/components/GridLayout/GridItemContent.d.ts +3 -3
  46. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  47. package/dist/components/GridLayout/GridItemContent.js +14 -14
  48. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  49. package/dist/components/GridLayout/GridLayout.d.ts +2 -3
  50. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  51. package/dist/components/GridLayout/GridLayout.js +24 -21
  52. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  53. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  54. package/dist/components/GridLayout/GridTitle.js +28 -6
  55. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  56. package/dist/components/Panel/DeletePanelDialog.d.ts +5 -0
  57. package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -0
  58. package/dist/components/Panel/DeletePanelDialog.js +80 -0
  59. package/dist/components/Panel/DeletePanelDialog.js.map +1 -0
  60. package/dist/components/Panel/Panel.d.ts +1 -1
  61. package/dist/components/Panel/Panel.d.ts.map +1 -1
  62. package/dist/components/Panel/Panel.js +17 -6
  63. package/dist/components/Panel/Panel.js.map +1 -1
  64. package/dist/components/Panel/Panel.test.js +7 -4
  65. package/dist/components/Panel/Panel.test.js.map +1 -1
  66. package/dist/components/Panel/PanelContent.d.ts +4 -1
  67. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  68. package/dist/components/Panel/PanelContent.js +3 -2
  69. package/dist/components/Panel/PanelContent.js.map +1 -1
  70. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  71. package/dist/components/PanelDrawer/PanelDrawer.js +14 -13
  72. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  73. package/dist/components/PanelDrawer/PanelDrawer.test.js +8 -12
  74. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  75. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +3 -3
  76. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  77. package/dist/components/PanelDrawer/PanelEditorForm.js +78 -36
  78. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  79. package/dist/components/PanelDrawer/PanelPreview.d.ts +4 -0
  80. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -0
  81. package/dist/components/PanelDrawer/PanelPreview.js +42 -0
  82. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -0
  83. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +4 -0
  84. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
  85. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +75 -0
  86. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
  87. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  88. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +13 -20
  89. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  90. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +10 -31
  91. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
  92. package/dist/components/TimeRangeControls/TimeRangeControls.js +3 -3
  93. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  94. package/dist/components/Variables/Variable.js +21 -13
  95. package/dist/components/Variables/Variable.js.map +1 -1
  96. package/dist/components/Variables/VariableEditor.d.ts +8 -0
  97. package/dist/components/Variables/VariableEditor.d.ts.map +1 -0
  98. package/dist/components/Variables/VariableEditor.js +196 -0
  99. package/dist/components/Variables/VariableEditor.js.map +1 -0
  100. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +8 -0
  101. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
  102. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +225 -0
  103. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
  104. package/dist/components/Variables/VariableEditorForm/index.d.ts +2 -0
  105. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
  106. package/dist/components/Variables/VariableEditorForm/index.js +15 -0
  107. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
  108. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +21 -0
  109. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
  110. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +76 -0
  111. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
  112. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  113. package/dist/components/Variables/VariableList.js +48 -72
  114. package/dist/components/Variables/VariableList.js.map +1 -1
  115. package/dist/components/Variables/index.d.ts +1 -0
  116. package/dist/components/Variables/index.d.ts.map +1 -1
  117. package/dist/components/Variables/index.js +1 -0
  118. package/dist/components/Variables/index.js.map +1 -1
  119. package/dist/context/DashboardProvider/DashboardProvider.d.ts +23 -0
  120. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -0
  121. package/dist/context/DashboardProvider/DashboardProvider.js +52 -0
  122. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -0
  123. package/dist/context/DashboardProvider/common.d.ts +5 -0
  124. package/dist/context/DashboardProvider/common.d.ts.map +1 -0
  125. package/dist/context/DashboardProvider/common.js +17 -0
  126. package/dist/context/DashboardProvider/common.js.map +1 -0
  127. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +32 -0
  128. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -0
  129. package/dist/context/DashboardProvider/dashboard-provider-api.js +56 -0
  130. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -0
  131. package/dist/context/DashboardProvider/index.d.ts +3 -0
  132. package/dist/context/DashboardProvider/index.d.ts.map +1 -0
  133. package/dist/context/DashboardProvider/index.js +16 -0
  134. package/dist/context/DashboardProvider/index.js.map +1 -0
  135. package/dist/context/DashboardProvider/layout-slice.d.ts +57 -0
  136. package/dist/context/DashboardProvider/layout-slice.d.ts.map +1 -0
  137. package/dist/context/DashboardProvider/layout-slice.js +196 -0
  138. package/dist/context/DashboardProvider/layout-slice.js.map +1 -0
  139. package/dist/context/DashboardProvider/panel-editing-slice.d.ts +70 -0
  140. package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +1 -0
  141. package/dist/context/DashboardProvider/panel-editing-slice.js +152 -0
  142. package/dist/context/DashboardProvider/panel-editing-slice.js.map +1 -0
  143. package/dist/context/DashboardProvider/panel-group-slice.d.ts +15 -0
  144. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -0
  145. package/dist/context/DashboardProvider/panel-group-slice.js +32 -0
  146. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -0
  147. package/dist/context/DatasourceStoreProvider.d.ts +10 -2
  148. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  149. package/dist/context/DatasourceStoreProvider.js +111 -9
  150. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  151. package/dist/context/TemplateVariableProvider.d.ts +2 -0
  152. package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
  153. package/dist/context/TemplateVariableProvider.js +8 -1
  154. package/dist/context/TemplateVariableProvider.js.map +1 -1
  155. package/dist/context/index.d.ts +0 -2
  156. package/dist/context/index.d.ts.map +1 -1
  157. package/dist/context/index.js +0 -2
  158. package/dist/context/index.js.map +1 -1
  159. package/dist/test/plugin-registry.d.ts +2 -2
  160. package/dist/test/plugin-registry.d.ts.map +1 -1
  161. package/dist/test/plugin-registry.js.map +1 -1
  162. package/dist/test/testDashboard.d.ts.map +1 -1
  163. package/dist/test/testDashboard.js +13 -1
  164. package/dist/test/testDashboard.js.map +1 -1
  165. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  166. package/dist/views/ViewDashboard/DashboardApp.js +6 -7
  167. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  168. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +2 -0
  169. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +1 -0
  170. package/dist/views/ViewDashboard/tests/panelGroups.test.js +158 -0
  171. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -0
  172. package/package.json +4 -4
  173. package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +0 -40
  174. package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +0 -38
  175. package/dist/cjs/components/PanelDrawer/panel-editor-model.js +0 -140
  176. package/dist/cjs/context/DashboardAppSlice.js +0 -57
  177. package/dist/cjs/context/DashboardProvider.js +0 -128
  178. package/dist/cjs/context/LayoutsSlice.js +0 -55
  179. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +0 -7
  180. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +0 -1
  181. package/dist/components/PanelDrawer/PanelSpecEditor.js +0 -34
  182. package/dist/components/PanelDrawer/PanelSpecEditor.js.map +0 -1
  183. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +0 -8
  184. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +0 -1
  185. package/dist/components/PanelDrawer/PanelTypeSelect.js +0 -34
  186. package/dist/components/PanelDrawer/PanelTypeSelect.js.map +0 -1
  187. package/dist/components/PanelDrawer/panel-editor-model.d.ts +0 -27
  188. package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +0 -1
  189. package/dist/components/PanelDrawer/panel-editor-model.js +0 -133
  190. package/dist/components/PanelDrawer/panel-editor-model.js.map +0 -1
  191. package/dist/context/DashboardAppSlice.d.ts +0 -26
  192. package/dist/context/DashboardAppSlice.d.ts.map +0 -1
  193. package/dist/context/DashboardAppSlice.js.map +0 -1
  194. package/dist/context/DashboardProvider.d.ts +0 -36
  195. package/dist/context/DashboardProvider.d.ts.map +0 -1
  196. package/dist/context/DashboardProvider.js +0 -107
  197. package/dist/context/DashboardProvider.js.map +0 -1
  198. package/dist/context/LayoutsSlice.d.ts +0 -12
  199. package/dist/context/LayoutsSlice.d.ts.map +0 -1
  200. package/dist/context/LayoutsSlice.js +0 -43
  201. package/dist/context/LayoutsSlice.js.map +0 -1
@@ -21,92 +21,73 @@ Object.defineProperty(exports, "TemplateVariableList", {
21
21
  const _jsxRuntime = require("react/jsx-runtime");
22
22
  const _react = require("react");
23
23
  const _material = require("@mui/material");
24
+ const _eye = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Eye"));
25
+ const _pencil = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Pencil"));
24
26
  const _context = require("../../context");
25
27
  const _variable = require("./Variable");
28
+ const _variableEditor = require("./VariableEditor");
29
+ function _interopRequireDefault(obj) {
30
+ return obj && obj.__esModule ? obj : {
31
+ default: obj
32
+ };
33
+ }
26
34
  function TemplateVariableList() {
27
35
  const [isEditing, setIsEditing] = (0, _react.useState)(false);
28
36
  const variableDefinitions = (0, _context.useTemplateVariableDefinitions)();
29
37
  const { isEditMode } = (0, _context.useEditMode)();
30
- return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
38
+ const [showVariablesInEditMode, setShowVariablesInEditMode] = (0, _react.useState)(true);
39
+ const showVariables = isEditMode ? showVariablesInEditMode : true;
40
+ const { setVariableDefinitions } = (0, _context.useTemplateVariableActions)();
41
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
42
+ m: 2,
31
43
  children: [
32
44
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Drawer, {
33
45
  anchor: 'right',
34
46
  open: isEditing,
35
- onClose: ()=>setIsEditing(false),
36
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
37
- width: 900,
38
- p: 4,
39
- children: [
40
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableContainer, {
41
- component: _material.Paper,
42
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Table, {
43
- sx: {
44
- minWidth: 650
45
- },
46
- "aria-label": "simple table",
47
- children: [
48
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableHead, {
49
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.TableRow, {
50
- children: [
51
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
52
- children: "Variable Name"
53
- }),
54
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
55
- align: "right",
56
- children: "Type"
57
- })
58
- ]
59
- })
60
- }),
61
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableBody, {
62
- children: variableDefinitions.map((v)=>/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.TableRow, {
63
- sx: {
64
- '&:last-child td, &:last-child th': {
65
- border: 0
66
- }
67
- },
68
- children: [
69
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
70
- component: "th",
71
- scope: "row",
72
- sx: {
73
- fontWeight: 'bold'
74
- },
75
- children: v.spec.name
76
- }),
77
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableCell, {
78
- align: "right",
79
- children: v.kind
80
- })
81
- ]
82
- }, v.spec.name))
83
- })
84
- ]
85
- })
86
- }),
87
- /*#__PURE__*/ (0, _jsxRuntime.jsx)("pre", {
88
- children: JSON.stringify(variableDefinitions, null, 2)
89
- })
90
- ]
47
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variableEditor.VariableEditor, {
48
+ onCancel: ()=>{
49
+ setIsEditing(false);
50
+ },
51
+ variableDefinitions: variableDefinitions,
52
+ onChange: (v)=>{
53
+ setVariableDefinitions(v);
54
+ setIsEditing(false);
55
+ }
91
56
  })
92
57
  }),
58
+ isEditMode && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
59
+ pb: 2,
60
+ children: [
61
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Button, {
62
+ onClick: ()=>setShowVariablesInEditMode(!showVariablesInEditMode),
63
+ startIcon: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_eye.default, {}),
64
+ children: [
65
+ showVariablesInEditMode ? 'Hide' : 'Show',
66
+ " Variables"
67
+ ]
68
+ }),
69
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
70
+ onClick: ()=>setIsEditing(true),
71
+ startIcon: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pencil.default, {}),
72
+ children: "Edit Variables"
73
+ })
74
+ ]
75
+ }),
93
76
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
94
77
  display: 'flex',
95
78
  justifyContent: "space-between",
96
- children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
79
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Stack, {
97
80
  direction: 'row',
98
81
  spacing: 2,
99
- children: [
100
- variableDefinitions.map((v)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
101
- children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variable.TemplateVariable, {
102
- name: v.spec.name
103
- }, v.spec.name)
104
- }, v.spec.name)),
105
- isEditMode && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
106
- onClick: ()=>setIsEditing(true),
107
- children: "Modify Variables"
108
- })
109
- ]
82
+ children: showVariables && variableDefinitions.map((v)=>{
83
+ var ref;
84
+ /*#__PURE__*/ return (0, _jsxRuntime.jsx)(_material.Box, {
85
+ display: ((ref = v.spec.display) === null || ref === void 0 ? void 0 : ref.hidden) ? 'none' : undefined,
86
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_variable.TemplateVariable, {
87
+ name: v.spec.name
88
+ }, v.spec.name)
89
+ }, v.spec.name);
90
+ })
110
91
  })
111
92
  })
112
93
  ]
@@ -16,6 +16,7 @@ Object.defineProperty(exports, "__esModule", {
16
16
  });
17
17
  _exportStar(require("./Variable"), exports);
18
18
  _exportStar(require("./VariableList"), exports);
19
+ _exportStar(require("./VariableEditorForm"), exports);
19
20
  function _exportStar(from, to) {
20
21
  Object.keys(from).forEach(function(k) {
21
22
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -0,0 +1,70 @@
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
+ 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
+ DashboardContext: ()=>DashboardContext,
25
+ useDashboardStore: ()=>useDashboardStore,
26
+ DashboardProvider: ()=>DashboardProvider
27
+ });
28
+ const _jsxRuntime = require("react/jsx-runtime");
29
+ const _zustand = require("zustand");
30
+ const _middleware = require("zustand/middleware");
31
+ const _immer = require("zustand/middleware/immer");
32
+ const _shallow = /*#__PURE__*/ _interopRequireDefault(require("zustand/shallow"));
33
+ const _react = require("react");
34
+ const _panelGroupSlice = require("./panel-group-slice");
35
+ const _layoutSlice = require("./layout-slice");
36
+ const _panelEditingSlice = require("./panel-editing-slice");
37
+ function _interopRequireDefault(obj) {
38
+ return obj && obj.__esModule ? obj : {
39
+ default: obj
40
+ };
41
+ }
42
+ const DashboardContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
43
+ function useDashboardStore(selector) {
44
+ const store = (0, _react.useContext)(DashboardContext);
45
+ if (store === undefined) {
46
+ throw new Error('No DashboardContext found. Did you forget a Provider?');
47
+ }
48
+ return (0, _zustand.useStore)(store, selector, _shallow.default);
49
+ }
50
+ function DashboardProvider(props) {
51
+ const { children , initialState: { dashboardSpec , isEditMode } , } = props;
52
+ const { layouts , panels } = dashboardSpec;
53
+ const dashboardStore = (0, _zustand.createStore)()((0, _immer.immer)((0, _middleware.devtools)((...args)=>{
54
+ const [set] = args;
55
+ return {
56
+ ...(0, _panelGroupSlice.createPanelGroupSlice)(...args),
57
+ ...(0, _layoutSlice.createLayoutSlice)(layouts)(...args),
58
+ ...(0, _panelEditingSlice.createPanelEditorSlice)(panels)(...args),
59
+ defaultTimeRange: dashboardSpec.duration,
60
+ isEditMode: !!isEditMode,
61
+ setEditMode: (isEditMode)=>set({
62
+ isEditMode
63
+ })
64
+ };
65
+ })));
66
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardContext.Provider, {
67
+ value: dashboardStore,
68
+ children: children
69
+ });
70
+ }
@@ -0,0 +1,18 @@
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
+ /**
14
+ * The middleware applied to the DashboardStore (can be used as generic argument in StateCreator).
15
+ */ "use strict";
16
+ Object.defineProperty(exports, "__esModule", {
17
+ value: true
18
+ });
@@ -0,0 +1,71 @@
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
+ 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
+ useEditMode: ()=>useEditMode,
25
+ useLayouts: ()=>useLayouts,
26
+ usePanelGroupDialog: ()=>usePanelGroupDialog,
27
+ usePanels: ()=>usePanels,
28
+ useDefaultTimeRange: ()=>useDefaultTimeRange
29
+ });
30
+ const _dashboardProvider = require("./DashboardProvider");
31
+ function useEditMode() {
32
+ return (0, _dashboardProvider.useDashboardStore)(({ isEditMode , setEditMode })=>({
33
+ isEditMode,
34
+ setEditMode
35
+ }));
36
+ }
37
+ function useLayouts() {
38
+ return (0, _dashboardProvider.useDashboardStore)(({ layouts , addPanelToGroup , movePanelToGroup , updatePanelGroup , swapPanelGroups , deletePanelGroup })=>({
39
+ layouts,
40
+ addPanelToGroup,
41
+ movePanelToGroup,
42
+ updatePanelGroup,
43
+ swapPanelGroups,
44
+ deletePanelGroup
45
+ }));
46
+ }
47
+ function usePanelGroupDialog() {
48
+ return (0, _dashboardProvider.useDashboardStore)(({ panelGroupDialog , openPanelGroupDialog , closePanelGroupDialog , deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , })=>({
49
+ panelGroupDialog,
50
+ openPanelGroupDialog,
51
+ closePanelGroupDialog,
52
+ deletePanelGroupDialog,
53
+ openDeletePanelGroupDialog,
54
+ closeDeletePanelGroupDialog
55
+ }));
56
+ }
57
+ function usePanels() {
58
+ return (0, _dashboardProvider.useDashboardStore)(({ panels , panelEditor , addPanel , editPanel , deletePanelDialog , deletePanels , openDeletePanelDialog , closeDeletePanelDialog , })=>({
59
+ panels,
60
+ panelEditor,
61
+ addPanel,
62
+ editPanel,
63
+ deletePanels,
64
+ deletePanelDialog,
65
+ openDeletePanelDialog,
66
+ closeDeletePanelDialog
67
+ }));
68
+ }
69
+ function useDefaultTimeRange() {
70
+ return (0, _dashboardProvider.useDashboardStore)((state)=>state.defaultTimeRange);
71
+ }
@@ -0,0 +1,29 @@
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("./dashboard-provider-api"), exports);
18
+ _exportStar(require("./DashboardProvider"), exports);
19
+ function _exportStar(from, to) {
20
+ Object.keys(from).forEach(function(k) {
21
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ });
28
+ return from;
29
+ }
@@ -0,0 +1,200 @@
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, "createLayoutSlice", {
18
+ enumerable: true,
19
+ get: ()=>createLayoutSlice
20
+ });
21
+ const _core = require("@perses-dev/core");
22
+ function createLayoutSlice(layouts) {
23
+ // Return the state creator function for Zustand that uses the layouts provided as initial state
24
+ let id = -1;
25
+ function createPanelGroupId() {
26
+ id++;
27
+ return id;
28
+ }
29
+ var ref;
30
+ return (set, get)=>{
31
+ return {
32
+ layouts: layouts.map((layout)=>{
33
+ var ref1, ref2, ref3;
34
+ return {
35
+ ...layout,
36
+ id: createPanelGroupId(),
37
+ title: (ref1 = layout.spec.display) === null || ref1 === void 0 ? void 0 : ref1.title,
38
+ isCollapsed: (ref = !((ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.collapse) === null || ref3 === void 0 ? void 0 : ref3.open)) !== null && ref !== void 0 ? ref : false,
39
+ items: layout.spec.items
40
+ };
41
+ }),
42
+ getPanelKey ({ groupIndex , itemIndex }) {
43
+ const { layouts } = get();
44
+ const group = findGroup(layouts, groupIndex);
45
+ const item = findItem(group, itemIndex);
46
+ return (0, _core.getPanelKeyFromRef)(item.content);
47
+ },
48
+ addPanelToGroup (panelKey, groupIndex) {
49
+ const { layouts } = get();
50
+ const group = findGroup(layouts, groupIndex);
51
+ const gridItem = {
52
+ x: 0,
53
+ y: getYForNewRow(group),
54
+ width: 12,
55
+ height: 6,
56
+ content: (0, _core.createPanelRef)(panelKey)
57
+ };
58
+ set((state)=>{
59
+ var ref;
60
+ (ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.items.push(gridItem);
61
+ });
62
+ },
63
+ movePanelToGroup ({ groupIndex , itemIndex }, newGroupIndex) {
64
+ const { layouts } = get();
65
+ // Find the existing item to make sure it exists
66
+ const group = findGroup(layouts, groupIndex);
67
+ const item = findItem(group, itemIndex);
68
+ // Find the new group and figure out where a new row should go
69
+ const newGroup = findGroup(layouts, newGroupIndex);
70
+ const newGroupY = getYForNewRow(newGroup);
71
+ set((state)=>{
72
+ var // Remove the item from its current group
73
+ ref, // Add a new item to the new group
74
+ ref1;
75
+ (ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.items.splice(itemIndex, 1);
76
+ (ref1 = state.layouts[newGroupIndex]) === null || ref1 === void 0 ? void 0 : ref1.items.push({
77
+ x: 0,
78
+ y: newGroupY,
79
+ width: item.width,
80
+ height: item.height,
81
+ content: item.content
82
+ });
83
+ });
84
+ },
85
+ // TODO: Maybe combine this into some kind of groupEditor state
86
+ updatePanelGroup (next, groupIndex) {
87
+ set((state)=>{
88
+ if (groupIndex === undefined) {
89
+ state.layouts.unshift({
90
+ ...next,
91
+ id: createPanelGroupId()
92
+ });
93
+ } else {
94
+ const layout = state.layouts[groupIndex];
95
+ if (layout === undefined) {
96
+ throw new Error(`No layout at index ${groupIndex}`);
97
+ }
98
+ state.layouts[groupIndex] = {
99
+ ...next,
100
+ id: layout.id
101
+ };
102
+ }
103
+ });
104
+ },
105
+ swapPanelGroups (x, y) {
106
+ set((state)=>{
107
+ if (x < 0 || x >= state.layouts.length || y < 0 || y >= state.layouts.length) {
108
+ throw new Error('index out of bound');
109
+ }
110
+ const xPanelGroup = state.layouts[x];
111
+ const yPanelGroup = state.layouts[y];
112
+ if (xPanelGroup === undefined || yPanelGroup === undefined) {
113
+ throw new Error('panel group is undefined');
114
+ }
115
+ // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups
116
+ [state.layouts[x], state.layouts[y]] = [
117
+ yPanelGroup,
118
+ xPanelGroup
119
+ ];
120
+ });
121
+ },
122
+ deletePanelInPanelGroup ({ groupIndex , itemIndex }) {
123
+ set((state)=>{
124
+ const group = state.layouts[groupIndex];
125
+ if (group === undefined) {
126
+ throw new Error(`No panel group found: ${groupIndex}`);
127
+ }
128
+ // remove panel from panel group
129
+ group.items.splice(itemIndex, 1);
130
+ });
131
+ },
132
+ deletePanelGroup (groupIndex) {
133
+ const { layouts , deletePanels } = get();
134
+ const group = layouts[groupIndex];
135
+ if (group === undefined) {
136
+ throw new Error(`No panel group found: ${groupIndex}`);
137
+ }
138
+ // remove panels from group first
139
+ const panelsToBeDeleted = [];
140
+ for(let i = 0; i < group.items.length; i++){
141
+ panelsToBeDeleted.push({
142
+ groupIndex,
143
+ itemIndex: i
144
+ });
145
+ }
146
+ deletePanels(panelsToBeDeleted);
147
+ // remove group from state.layouts
148
+ set((state)=>{
149
+ state.layouts.splice(groupIndex, 1);
150
+ });
151
+ },
152
+ // Return an object that maps each panel to the groups it belongs
153
+ mapPanelToPanelGroups () {
154
+ const map = {}; // { panel key: [group ids] }
155
+ get().layouts.forEach((group)=>{
156
+ // for each panel in a group, add the group id to map[panelKey]
157
+ group.items.forEach((panel)=>{
158
+ const panelKey = (0, _core.getPanelKeyFromRef)(panel.content);
159
+ if (map[panelKey]) {
160
+ var ref;
161
+ (ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.push(group.id);
162
+ } else {
163
+ map[panelKey] = [
164
+ group.id
165
+ ];
166
+ }
167
+ });
168
+ });
169
+ return map;
170
+ }
171
+ };
172
+ };
173
+ }
174
+ // Helper to find a group and throw if not found
175
+ function findGroup(layouts, groupIndex) {
176
+ const group = layouts[groupIndex];
177
+ if (group === undefined) {
178
+ throw new Error(`No layout at index ${groupIndex}`);
179
+ }
180
+ return group;
181
+ }
182
+ // Helper to get an item in a group and throw if not found
183
+ function findItem(group, itemIndex) {
184
+ const item = group.items[itemIndex];
185
+ if (item === undefined) {
186
+ throw new Error(`No grid item found at position ${itemIndex}`);
187
+ }
188
+ return item;
189
+ }
190
+ // Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present
191
+ function getYForNewRow(group) {
192
+ let newRowY = 0;
193
+ for (const item of group.items){
194
+ const itemMaxY = item.y + item.height;
195
+ if (itemMaxY > newRowY) {
196
+ newRowY = itemMaxY;
197
+ }
198
+ }
199
+ return newRowY;
200
+ }