@perses-dev/dashboards 0.11.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 (231) 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 -16
  4. package/dist/cjs/components/DashboardToolbar/index.js +28 -0
  5. package/dist/cjs/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +4 -7
  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/GridLayout/GridLayout.js +14 -16
  11. package/dist/cjs/components/Panel/Panel.js +30 -90
  12. package/dist/cjs/components/Panel/Panel.test.js +93 -46
  13. package/dist/cjs/components/Panel/PanelHeader.js +116 -0
  14. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +21 -19
  15. package/dist/cjs/components/PanelDrawer/PanelPreview.js +13 -20
  16. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +16 -16
  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/Variables/VariableEditor.js +7 -6
  23. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
  24. package/dist/cjs/components/index.js +4 -0
  25. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +32 -20
  26. package/dist/cjs/context/DashboardProvider/common.js +10 -0
  27. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +14 -16
  28. package/dist/cjs/context/DashboardProvider/delete-panel-group-slice.js +70 -0
  29. package/dist/cjs/context/DashboardProvider/delete-panel-slice.js +85 -0
  30. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +74 -67
  31. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +6 -19
  32. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +54 -164
  33. package/dist/cjs/context/DashboardProvider/panel-slice.js +25 -0
  34. package/dist/cjs/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
  35. package/dist/cjs/context/TemplateVariableProvider/index.js +28 -0
  36. package/dist/cjs/context/TemplateVariableProvider/query-params.js +79 -0
  37. package/dist/cjs/context/TemplateVariableProvider/query-params.test.js +82 -0
  38. package/dist/cjs/context/index.js +1 -1
  39. package/dist/cjs/context/useDashboard.js +94 -0
  40. package/dist/cjs/test/plugin-registry.js +14 -54
  41. package/dist/cjs/test/render.js +6 -1
  42. package/dist/cjs/utils/component-ids.js +31 -0
  43. package/dist/cjs/utils/time-range-params.js +14 -8
  44. package/dist/cjs/views/ViewDashboard/DashboardApp.js +40 -11
  45. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +1 -1
  46. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +1 -1
  47. package/dist/components/{Dashboard.d.ts → Dashboard/Dashboard.d.ts} +0 -0
  48. package/dist/components/Dashboard/Dashboard.d.ts.map +1 -0
  49. package/dist/components/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
  50. package/dist/components/Dashboard/Dashboard.js.map +1 -0
  51. package/dist/components/Dashboard/index.d.ts +2 -0
  52. package/dist/components/Dashboard/index.d.ts.map +1 -0
  53. package/dist/components/Dashboard/index.js +15 -0
  54. package/dist/components/Dashboard/index.js.map +1 -0
  55. package/dist/components/{DashboardToolbar.d.ts → DashboardToolbar/DashboardToolbar.d.ts} +2 -0
  56. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -0
  57. package/dist/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +5 -12
  58. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -0
  59. package/dist/components/DashboardToolbar/index.d.ts +2 -0
  60. package/dist/components/DashboardToolbar/index.d.ts.map +1 -0
  61. package/dist/components/DashboardToolbar/index.js +15 -0
  62. package/dist/components/DashboardToolbar/index.js.map +1 -0
  63. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts +3 -0
  64. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -0
  65. package/dist/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +3 -6
  66. package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -0
  67. package/dist/components/DeletePanelDialog/index.d.ts +2 -0
  68. package/dist/components/DeletePanelDialog/index.d.ts.map +1 -0
  69. package/dist/components/DeletePanelDialog/index.js +15 -0
  70. package/dist/components/DeletePanelDialog/index.js.map +1 -0
  71. package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.d.ts +0 -0
  72. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
  73. package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
  74. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
  75. package/dist/components/DeletePanelGroupDialog/index.d.ts +2 -0
  76. package/dist/components/DeletePanelGroupDialog/index.d.ts.map +1 -0
  77. package/dist/components/DeletePanelGroupDialog/index.js +15 -0
  78. package/dist/components/DeletePanelGroupDialog/index.js.map +1 -0
  79. package/dist/components/GridLayout/GridItemContent.d.ts +2 -2
  80. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  81. package/dist/components/GridLayout/GridItemContent.js +12 -2
  82. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  83. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  84. package/dist/components/GridLayout/GridLayout.js +16 -18
  85. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  86. package/dist/components/Panel/Panel.d.ts +3 -3
  87. package/dist/components/Panel/Panel.d.ts.map +1 -1
  88. package/dist/components/Panel/Panel.js +32 -92
  89. package/dist/components/Panel/Panel.js.map +1 -1
  90. package/dist/components/Panel/Panel.test.js +95 -48
  91. package/dist/components/Panel/Panel.test.js.map +1 -1
  92. package/dist/components/Panel/PanelHeader.d.ts +16 -0
  93. package/dist/components/Panel/PanelHeader.d.ts.map +1 -0
  94. package/dist/components/Panel/PanelHeader.js +105 -0
  95. package/dist/components/Panel/PanelHeader.js.map +1 -0
  96. package/dist/components/PanelDrawer/PanelDrawer.test.js +22 -20
  97. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  98. package/dist/components/PanelDrawer/PanelPreview.d.ts +2 -2
  99. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
  100. package/dist/components/PanelDrawer/PanelPreview.js +13 -20
  101. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  102. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +16 -16
  103. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
  104. package/dist/components/PanelGroupDialog/index.d.ts +0 -1
  105. package/dist/components/PanelGroupDialog/index.d.ts.map +1 -1
  106. package/dist/components/PanelGroupDialog/index.js +0 -1
  107. package/dist/components/PanelGroupDialog/index.js.map +1 -1
  108. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
  109. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  110. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts +8 -0
  111. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts.map +1 -0
  112. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +56 -0
  113. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js.map +1 -0
  114. package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts +2 -0
  115. package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts.map +1 -0
  116. package/dist/components/UnsavedChangesConfirmationDialog/index.js +15 -0
  117. package/dist/components/UnsavedChangesConfirmationDialog/index.js.map +1 -0
  118. package/dist/components/Variables/Variable.d.ts.map +1 -1
  119. package/dist/components/Variables/Variable.js +19 -12
  120. package/dist/components/Variables/Variable.js.map +1 -1
  121. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  122. package/dist/components/Variables/VariableEditor.js +7 -6
  123. package/dist/components/Variables/VariableEditor.js.map +1 -1
  124. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  125. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +9 -5
  126. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  127. package/dist/components/index.d.ts +4 -0
  128. package/dist/components/index.d.ts.map +1 -1
  129. package/dist/components/index.js +4 -0
  130. package/dist/components/index.js.map +1 -1
  131. package/dist/context/DashboardProvider/DashboardProvider.d.ts +8 -5
  132. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  133. package/dist/context/DashboardProvider/DashboardProvider.js +34 -22
  134. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  135. package/dist/context/DashboardProvider/common.d.ts +7 -0
  136. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  137. package/dist/context/DashboardProvider/common.js +8 -1
  138. package/dist/context/DashboardProvider/common.js.map +1 -1
  139. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +6 -6
  140. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  141. package/dist/context/DashboardProvider/dashboard-provider-api.js +14 -16
  142. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  143. package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts +23 -0
  144. package/dist/context/DashboardProvider/delete-panel-group-slice.d.ts.map +1 -0
  145. package/dist/context/DashboardProvider/delete-panel-group-slice.js +64 -0
  146. package/dist/context/DashboardProvider/delete-panel-group-slice.js.map +1 -0
  147. package/dist/context/DashboardProvider/delete-panel-slice.d.ts +36 -0
  148. package/dist/context/DashboardProvider/delete-panel-slice.d.ts.map +1 -0
  149. package/dist/context/DashboardProvider/delete-panel-slice.js +81 -0
  150. package/dist/context/DashboardProvider/delete-panel-slice.js.map +1 -0
  151. package/dist/context/DashboardProvider/index.d.ts +3 -1
  152. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  153. package/dist/context/DashboardProvider/index.js.map +1 -1
  154. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +6 -35
  155. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  156. package/dist/context/DashboardProvider/panel-editor-slice.js +74 -67
  157. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  158. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +1 -8
  159. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
  160. package/dist/context/DashboardProvider/panel-group-editor-slice.js +6 -19
  161. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  162. package/dist/context/DashboardProvider/panel-group-slice.d.ts +14 -44
  163. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  164. package/dist/context/DashboardProvider/panel-group-slice.js +46 -162
  165. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  166. package/dist/context/DashboardProvider/panel-slice.d.ts +14 -0
  167. package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -0
  168. package/dist/context/DashboardProvider/panel-slice.js +21 -0
  169. package/dist/context/DashboardProvider/panel-slice.js.map +1 -0
  170. package/dist/context/{TemplateVariableProvider.d.ts → TemplateVariableProvider/TemplateVariableProvider.d.ts} +0 -0
  171. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -0
  172. package/dist/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
  173. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -0
  174. package/dist/context/TemplateVariableProvider/index.d.ts +2 -0
  175. package/dist/context/TemplateVariableProvider/index.d.ts.map +1 -0
  176. package/dist/context/TemplateVariableProvider/index.js +15 -0
  177. package/dist/context/TemplateVariableProvider/index.js.map +1 -0
  178. package/dist/context/TemplateVariableProvider/query-params.d.ts +12 -0
  179. package/dist/context/TemplateVariableProvider/query-params.d.ts.map +1 -0
  180. package/dist/context/TemplateVariableProvider/query-params.js +64 -0
  181. package/dist/context/TemplateVariableProvider/query-params.js.map +1 -0
  182. package/dist/context/TemplateVariableProvider/query-params.test.d.ts +2 -0
  183. package/dist/context/TemplateVariableProvider/query-params.test.d.ts.map +1 -0
  184. package/dist/context/TemplateVariableProvider/query-params.test.js +80 -0
  185. package/dist/context/TemplateVariableProvider/query-params.test.js.map +1 -0
  186. package/dist/context/index.d.ts +1 -1
  187. package/dist/context/index.d.ts.map +1 -1
  188. package/dist/context/index.js +1 -1
  189. package/dist/context/index.js.map +1 -1
  190. package/dist/context/useDashboard.d.ts +6 -0
  191. package/dist/context/useDashboard.d.ts.map +1 -0
  192. package/dist/context/useDashboard.js +88 -0
  193. package/dist/context/useDashboard.js.map +1 -0
  194. package/dist/test/plugin-registry.d.ts +2 -11
  195. package/dist/test/plugin-registry.d.ts.map +1 -1
  196. package/dist/test/plugin-registry.js +12 -49
  197. package/dist/test/plugin-registry.js.map +1 -1
  198. package/dist/test/render.d.ts.map +1 -1
  199. package/dist/test/render.js +6 -1
  200. package/dist/test/render.js.map +1 -1
  201. package/dist/utils/component-ids.d.ts +8 -0
  202. package/dist/utils/component-ids.d.ts.map +1 -0
  203. package/dist/utils/component-ids.js +27 -0
  204. package/dist/utils/component-ids.js.map +1 -0
  205. package/dist/utils/time-range-params.d.ts.map +1 -1
  206. package/dist/utils/time-range-params.js +15 -9
  207. package/dist/utils/time-range-params.js.map +1 -1
  208. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  209. package/dist/views/ViewDashboard/DashboardApp.js +40 -6
  210. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  211. package/dist/views/ViewDashboard/ViewDashboard.js +1 -1
  212. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  213. package/dist/views/ViewDashboard/tests/panelGroups.test.js +1 -1
  214. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  215. package/package.json +4 -4
  216. package/dist/cjs/context/useDashboardSpec.js +0 -61
  217. package/dist/components/Dashboard.d.ts.map +0 -1
  218. package/dist/components/Dashboard.js.map +0 -1
  219. package/dist/components/DashboardToolbar.d.ts.map +0 -1
  220. package/dist/components/DashboardToolbar.js.map +0 -1
  221. package/dist/components/Panel/DeletePanelDialog.d.ts +0 -5
  222. package/dist/components/Panel/DeletePanelDialog.d.ts.map +0 -1
  223. package/dist/components/Panel/DeletePanelDialog.js.map +0 -1
  224. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +0 -1
  225. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +0 -1
  226. package/dist/context/TemplateVariableProvider.d.ts.map +0 -1
  227. package/dist/context/TemplateVariableProvider.js.map +0 -1
  228. package/dist/context/useDashboardSpec.d.ts +0 -3
  229. package/dist/context/useDashboardSpec.d.ts.map +0 -1
  230. package/dist/context/useDashboardSpec.js +0 -55
  231. package/dist/context/useDashboardSpec.js.map +0 -1
@@ -16,3 +16,13 @@
16
16
  Object.defineProperty(exports, "__esModule", {
17
17
  value: true
18
18
  });
19
+ Object.defineProperty(exports, "generateId", {
20
+ enumerable: true,
21
+ get: ()=>generateId
22
+ });
23
+ if (globalThis.dashboardStoreId === undefined) {
24
+ globalThis.dashboardStoreId = 0;
25
+ }
26
+ function generateId() {
27
+ return globalThis.dashboardStoreId++;
28
+ }
@@ -35,7 +35,6 @@ _export(exports, {
35
35
  useDeletePanelDialog: ()=>useDeletePanelDialog,
36
36
  useDefaultTimeRange: ()=>useDefaultTimeRange
37
37
  });
38
- const _core = require("@perses-dev/core");
39
38
  const _react = require("react");
40
39
  const _dashboardProvider = require("./DashboardProvider");
41
40
  function useEditMode() {
@@ -45,19 +44,17 @@ function useEditMode() {
45
44
  }));
46
45
  }
47
46
  function useDashboardActions() {
48
- const save = (0, _dashboardProvider.useDashboardStore)((store)=>store.save);
49
- const reset = (0, _dashboardProvider.useDashboardStore)((store)=>store.reset);
47
+ const setDashboard = (0, _dashboardProvider.useDashboardStore)((store)=>store.setDashboard);
50
48
  const openAddPanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanelGroup);
51
49
  const openAddPanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanel);
52
50
  return {
53
- save,
54
- reset,
51
+ setDashboard,
55
52
  openAddPanelGroup,
56
53
  openAddPanel: ()=>openAddPanel(undefined)
57
54
  };
58
55
  }
59
56
  function usePanelGroupIds() {
60
- return (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupIdOrder);
57
+ return (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupOrder);
61
58
  }
62
59
  function useListPanelGroups() {
63
60
  const panelGroupIds = usePanelGroupIds();
@@ -87,20 +84,22 @@ function usePanelGroupActions(panelGroupId) {
87
84
  const openEditPanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openEditPanelGroup);
88
85
  const deletePanelGroup = (0, _dashboardProvider.useDashboardStore)((store)=>store.openDeletePanelGroupDialog);
89
86
  const openAddPanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.openAddPanel);
87
+ const updatePanelGroupLayouts = (0, _dashboardProvider.useDashboardStore)((store)=>store.updatePanelGroupLayouts);
90
88
  return {
91
89
  openEditPanelGroup: ()=>openEditPanelGroup(panelGroupId),
92
90
  deletePanelGroup: ()=>deletePanelGroup(panelGroupId),
93
91
  openAddPanel: ()=>openAddPanel(panelGroupId),
94
92
  moveUp,
95
- moveDown
93
+ moveDown,
94
+ updatePanelGroupLayouts: (itemLayouts)=>updatePanelGroupLayouts(panelGroupId, itemLayouts)
96
95
  };
97
96
  }
98
97
  /**
99
98
  * Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be
100
99
  * moved in that direction.
101
100
  */ function useMovePanelGroup(panelGroupId) {
102
- const currentIndex = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupIdOrder.findIndex((id)=>id === panelGroupId));
103
- const panelGroupsLength = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupIdOrder.length);
101
+ const currentIndex = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupOrder.findIndex((id)=>id === panelGroupId));
102
+ const panelGroupsLength = (0, _dashboardProvider.useDashboardStore)((store)=>store.panelGroupOrder.length);
104
103
  const swapPanelGroups = (0, _dashboardProvider.useDashboardStore)((store)=>store.swapPanelGroups);
105
104
  if (currentIndex < 0) {
106
105
  throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);
@@ -124,12 +123,11 @@ function useDeletePanelGroupDialog() {
124
123
  }));
125
124
  }
126
125
  function usePanel(panelGroupItemId) {
127
- const { panelGroupId , itemIndex } = panelGroupItemId;
126
+ const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
128
127
  const panel = (0, _dashboardProvider.useDashboardStore)((store)=>{
129
- var ref, ref1;
130
- const panelRef = (ref1 = (ref = store.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.items[itemIndex]) === null || ref1 === void 0 ? void 0 : ref1.content;
131
- if (panelRef === undefined) return;
132
- const panelKey = (0, _core.getPanelKeyFromRef)(panelRef);
128
+ var ref;
129
+ const panelKey = (ref = store.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.itemPanelKeys[panelGroupLayoutId];
130
+ if (panelKey === undefined) return;
133
131
  return store.panels[panelKey];
134
132
  });
135
133
  if (panel === undefined) {
@@ -151,11 +149,11 @@ function usePanelEditor() {
151
149
  function useDeletePanelDialog() {
152
150
  const deletePanelDialog = (0, _dashboardProvider.useDashboardStore)((store)=>store.deletePanelDialog);
153
151
  // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself
154
- const deletePanels = (0, _dashboardProvider.useDashboardStore)((store)=>store.deletePanels);
152
+ const deletePanel = (0, _dashboardProvider.useDashboardStore)((store)=>store.deletePanel);
155
153
  const closeDeletePanelDialog = (0, _dashboardProvider.useDashboardStore)((store)=>store.closeDeletePanelDialog);
156
154
  return {
157
155
  deletePanelDialog,
158
- deletePanels,
156
+ deletePanel,
159
157
  closeDeletePanelDialog
160
158
  };
161
159
  }
@@ -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
+ Object.defineProperty(exports, "createDeletePanelGroupSlice", {
18
+ enumerable: true,
19
+ get: ()=>createDeletePanelGroupSlice
20
+ });
21
+ const createDeletePanelGroupSlice = (set, get)=>({
22
+ deletePanelGroup (panelGroupId) {
23
+ const { panelGroups , panelGroupOrder } = get();
24
+ const group = panelGroups[panelGroupId];
25
+ const idIndex = panelGroupOrder.findIndex((id)=>id === panelGroupId);
26
+ if (group === undefined || idIndex === -1) {
27
+ throw new Error(`Panel group ${panelGroupId} not found`);
28
+ }
29
+ // Get the panel keys for all the panel items in the group we're going to delete
30
+ const panelKeys = Object.values(group.itemPanelKeys);
31
+ set((draft)=>{
32
+ // Delete the panel group which also deletes all its items
33
+ delete draft.panelGroups[panelGroupId];
34
+ draft.panelGroupOrder.splice(idIndex, 1);
35
+ // Get all remaining panel keys in use
36
+ const usedPanelKeys = getUsedPanelKeys(draft.panelGroups);
37
+ // For the panel keys of the items that were just deleted, see if they're still used and if not, also delete the
38
+ // panel definition
39
+ for (const panelKey of panelKeys){
40
+ if (usedPanelKeys.has(panelKey)) continue;
41
+ delete draft.panels[panelKey];
42
+ }
43
+ });
44
+ },
45
+ openDeletePanelGroupDialog: (panelGroupId)=>{
46
+ const panelGroup = get().panelGroups[panelGroupId];
47
+ if (panelGroup === undefined) {
48
+ throw new Error(`Panel group with Id ${panelGroupId} not found`);
49
+ }
50
+ set((state)=>{
51
+ state.deletePanelGroupDialog = {
52
+ panelGroupId,
53
+ panelGroupName: panelGroup.title
54
+ };
55
+ });
56
+ },
57
+ closeDeletePanelGroupDialog: ()=>set((state)=>{
58
+ state.deletePanelGroupDialog = undefined;
59
+ })
60
+ });
61
+ // Helper to get the panel keys of all groups, returning a set to eliminate duplicates
62
+ function getUsedPanelKeys(panelGroups) {
63
+ const usedPanelKeys = new Set();
64
+ for (const group of Object.values(panelGroups)){
65
+ for (const panelKey of Object.values(group.itemPanelKeys)){
66
+ usedPanelKeys.add(panelKey);
67
+ }
68
+ }
69
+ return usedPanelKeys;
70
+ }
@@ -0,0 +1,85 @@
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, "createDeletePanelSlice", {
18
+ enumerable: true,
19
+ get: ()=>createDeletePanelSlice
20
+ });
21
+ function createDeletePanelSlice() {
22
+ // Return the state creator function for Zustand that uses the panels provided as intitial state
23
+ return (set, get)=>({
24
+ deletePanel (panelGroupItemId) {
25
+ set((draft)=>{
26
+ const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
27
+ const existingGroup = draft.panelGroups[panelGroupId];
28
+ if (existingGroup === undefined) {
29
+ throw new Error(`Missing panel group ${panelGroupId}`);
30
+ }
31
+ const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout)=>layout.i === panelGroupLayoutId);
32
+ const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];
33
+ if (existingLayoutIdx === -1 || existingPanelKey === undefined) {
34
+ throw new Error(`Missing panel group item ${panelGroupLayoutId}`);
35
+ }
36
+ // remove panel from panel group
37
+ existingGroup.itemLayouts.splice(existingLayoutIdx, 1);
38
+ delete existingGroup.itemPanelKeys[panelGroupLayoutId];
39
+ // See if panel key is still used and if not, delete it
40
+ if (isPanelKeyStillUsed(draft.panelGroups, existingPanelKey) === false) {
41
+ delete draft.panels[existingPanelKey];
42
+ }
43
+ });
44
+ },
45
+ openDeletePanelDialog (panelGroupItemId) {
46
+ const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
47
+ const { panels , panelGroups } = get();
48
+ const panelGroup = panelGroups[panelGroupId];
49
+ if (panelGroup === undefined) {
50
+ throw new Error(`Panel group not found ${panelGroupId}`);
51
+ }
52
+ const panelKey = panelGroup.itemPanelKeys[panelGroupLayoutId];
53
+ if (panelKey === undefined) {
54
+ throw new Error(`Could not find Panel Group item ${panelGroupLayoutId}`);
55
+ }
56
+ const panel = panels[panelKey];
57
+ if (panel === undefined) {
58
+ throw new Error(`Could not find panel ${panelKey}`);
59
+ }
60
+ set((state)=>{
61
+ var _title;
62
+ state.deletePanelDialog = {
63
+ panelGroupItemId: panelGroupItemId,
64
+ panelName: panel.spec.display.name,
65
+ panelGroupName: (_title = panelGroup.title) !== null && _title !== void 0 ? _title : ''
66
+ };
67
+ });
68
+ },
69
+ closeDeletePanelDialog () {
70
+ set((state)=>{
71
+ state.deletePanelDialog = undefined;
72
+ });
73
+ }
74
+ });
75
+ }
76
+ // Helper function to determine if a panel key is still being used somewhere in Panel Groups
77
+ function isPanelKeyStillUsed(panelGroups, panelKey) {
78
+ for (const group of Object.values(panelGroups)){
79
+ const found = Object.values(group.itemPanelKeys).find((key)=>key === panelKey);
80
+ if (found !== undefined) {
81
+ return true;
82
+ }
83
+ }
84
+ return false;
85
+ }
@@ -19,27 +19,21 @@ Object.defineProperty(exports, "createPanelEditorSlice", {
19
19
  get: ()=>createPanelEditorSlice
20
20
  });
21
21
  const _functions = require("../../utils/functions");
22
- function createPanelEditorSlice(panels) {
22
+ const _common = require("./common");
23
+ function createPanelEditorSlice() {
23
24
  // Return the state creator function for Zustand that uses the panels provided as intitial state
24
25
  return (set, get)=>{
25
26
  return {
26
- previousPanels: panels,
27
- panels,
28
27
  panelEditor: undefined,
29
- savePanels () {
30
- set((state)=>{
31
- state.previousPanels = state.panels;
32
- });
33
- },
34
- resetPanels () {
35
- set((state)=>{
36
- state.panels = state.previousPanels;
37
- });
38
- },
39
- openEditPanel (item) {
40
- const { panels , getPanelKey } = get();
41
- // Ask the layout store for the panel key at that location
42
- const panelKey = getPanelKey(item);
28
+ openEditPanel (panelGroupItemId) {
29
+ var ref;
30
+ const { panels , panelGroups } = get();
31
+ // Figure out the panel key at that location
32
+ const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
33
+ const panelKey = (ref = panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.itemPanelKeys[panelGroupLayoutId];
34
+ if (panelKey === undefined) {
35
+ throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);
36
+ }
43
37
  // Find the panel to edit
44
38
  const panelToEdit = panels[panelKey];
45
39
  if (panelToEdit === undefined) {
@@ -51,19 +45,46 @@ function createPanelEditorSlice(panels) {
51
45
  initialValues: {
52
46
  name: panelToEdit.spec.display.name,
53
47
  description: (_description = panelToEdit.spec.display.description) !== null && _description !== void 0 ? _description : '',
54
- groupId: item.panelGroupId,
48
+ groupId: panelGroupItemId.panelGroupId,
55
49
  kind: panelToEdit.spec.plugin.kind,
56
50
  spec: panelToEdit.spec.plugin.spec
57
51
  },
58
52
  applyChanges: (next)=>{
59
53
  const panelDefinititon = createPanelDefinitionFromEditorValues(next);
60
- set((state)=>{
61
- state.panels[panelKey] = panelDefinititon;
54
+ set((draft)=>{
55
+ draft.panels[panelKey] = panelDefinititon;
56
+ // If the panel didn't change groups, nothing else to do
57
+ if (next.groupId === panelGroupId) {
58
+ return;
59
+ }
60
+ // Move panel to the new group
61
+ const existingGroup = draft.panelGroups[panelGroupId];
62
+ if (existingGroup === undefined) {
63
+ throw new Error(`Missing panel group ${panelGroupId}`);
64
+ }
65
+ const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout)=>layout.i === panelGroupLayoutId);
66
+ const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];
67
+ const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];
68
+ if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {
69
+ throw new Error(`Missing panel group item ${panelGroupLayoutId}`);
70
+ }
71
+ // Remove item from the old group
72
+ existingGroup.itemLayouts.splice(existingLayoutIdx, 1);
73
+ delete existingGroup.itemPanelKeys[panelGroupLayoutId];
74
+ // Add item to the end of the new group
75
+ const newGroup = draft.panelGroups[next.groupId];
76
+ if (newGroup === undefined) {
77
+ throw new Error(`Could not find new group ${next.groupId}`);
78
+ }
79
+ newGroup.itemLayouts.push({
80
+ i: existingLayout.i,
81
+ x: 0,
82
+ y: getYForNewRow(newGroup),
83
+ w: existingLayout.w,
84
+ h: existingLayout.h
85
+ });
86
+ newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;
62
87
  });
63
- // Move the panel to another group if it changed
64
- if (next.groupId !== item.panelGroupId) {
65
- get().movePanelToGroup(item, next.groupId);
66
- }
67
88
  },
68
89
  close: ()=>{
69
90
  set((state)=>{
@@ -79,7 +100,7 @@ function createPanelEditorSlice(panels) {
79
100
  openAddPanel (panelGroupId) {
80
101
  // If a panel group isn't supplied, add to the first group
81
102
  if (panelGroupId === undefined) {
82
- const firstGroupId = get().panelGroupIdOrder[0];
103
+ const firstGroupId = get().panelGroupOrder[0];
83
104
  if (firstGroupId === undefined) {
84
105
  throw new Error('No panel groups to add a panel to');
85
106
  }
@@ -99,10 +120,24 @@ function createPanelEditorSlice(panels) {
99
120
  applyChanges: (next)=>{
100
121
  const panelDef = createPanelDefinitionFromEditorValues(next);
101
122
  const panelKey = (0, _functions.removeWhiteSpacesAndSpecialCharacters)(next.name);
102
- set((state)=>{
103
- state.panels[panelKey] = panelDef;
123
+ set((draft)=>{
124
+ // Add a panel
125
+ draft.panels[panelKey] = panelDef;
126
+ // Also add a panel group item referencing the panel
127
+ const group = draft.panelGroups[next.groupId];
128
+ if (group === undefined) {
129
+ throw new Error(`Missing panel group ${next.groupId}`);
130
+ }
131
+ const layout = {
132
+ i: (0, _common.generateId)().toString(),
133
+ x: 0,
134
+ y: getYForNewRow(group),
135
+ w: 12,
136
+ h: 6
137
+ };
138
+ group.itemLayouts.push(layout);
139
+ group.itemPanelKeys[layout.i] = panelKey;
104
140
  });
105
- get().addPanelToGroup(panelKey, next.groupId);
106
141
  },
107
142
  close: ()=>{
108
143
  set((state)=>{
@@ -114,45 +149,6 @@ function createPanelEditorSlice(panels) {
114
149
  set((state)=>{
115
150
  state.panelEditor = editorState;
116
151
  });
117
- },
118
- deletePanels (items) {
119
- const { mapPanelToPanelGroups , deletePanelInPanelGroup , getPanelKey } = get();
120
- const map = mapPanelToPanelGroups();
121
- // get panel key first before deleting panel from panel group since getPanelKey relies on index
122
- const panels = items.map((panel)=>{
123
- return {
124
- ...panel,
125
- panelKey: getPanelKey(panel)
126
- };
127
- });
128
- panels.forEach(({ panelKey , ...panel })=>{
129
- var ref;
130
- deletePanelInPanelGroup(panel);
131
- // make sure panel is only referenced in one panel group before deleting it from state.panels
132
- if (map[panelKey] && ((ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.length) === 1) {
133
- set((state)=>{
134
- delete state.panels[panelKey];
135
- });
136
- }
137
- });
138
- },
139
- openDeletePanelDialog (item) {
140
- const { panels , getPanelKey , panelGroups } = get();
141
- const panelKey = getPanelKey(item);
142
- set((state)=>{
143
- var ref, ref1;
144
- var _name, ref2;
145
- state.deletePanelDialog = {
146
- panelGroupItemId: item,
147
- panelName: (_name = (ref = panels[panelKey]) === null || ref === void 0 ? void 0 : ref.spec.display.name) !== null && _name !== void 0 ? _name : '',
148
- panelGroupName: (ref2 = (ref1 = panelGroups[item.panelGroupId]) === null || ref1 === void 0 ? void 0 : ref1.title) !== null && ref2 !== void 0 ? ref2 : ''
149
- };
150
- });
151
- },
152
- closeDeletePanelDialog () {
153
- set((state)=>{
154
- state.deletePanelDialog = undefined;
155
- });
156
152
  }
157
153
  };
158
154
  };
@@ -173,3 +169,14 @@ function createPanelDefinitionFromEditorValues(editorValues) {
173
169
  }
174
170
  };
175
171
  }
172
+ // Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present
173
+ function getYForNewRow(group) {
174
+ let newRowY = 0;
175
+ for (const layout of group.itemLayouts){
176
+ const itemMaxY = layout.y + layout.h;
177
+ if (itemMaxY > newRowY) {
178
+ newRowY = itemMaxY;
179
+ }
180
+ }
181
+ return newRowY;
182
+ }
@@ -18,6 +18,7 @@ Object.defineProperty(exports, "createPanelGroupEditorSlice", {
18
18
  enumerable: true,
19
19
  get: ()=>createPanelGroupEditorSlice
20
20
  });
21
+ const _common = require("./common");
21
22
  const createPanelGroupEditorSlice = (set, get)=>({
22
23
  panelGroupEditor: undefined,
23
24
  openAddPanelGroup: ()=>{
@@ -30,13 +31,14 @@ const createPanelGroupEditorSlice = (set, get)=>({
30
31
  },
31
32
  applyChanges (next) {
32
33
  const newGroup = {
33
- id: get().createPanelGroupId(),
34
- items: [],
34
+ id: (0, _common.generateId)(),
35
+ itemLayouts: [],
36
+ itemPanelKeys: {},
35
37
  ...next
36
38
  };
37
39
  set((draft)=>{
38
40
  draft.panelGroups[newGroup.id] = newGroup;
39
- draft.panelGroupIdOrder.unshift(newGroup.id);
41
+ draft.panelGroupOrder.unshift(newGroup.id);
40
42
  });
41
43
  },
42
44
  close () {
@@ -83,20 +85,5 @@ const createPanelGroupEditorSlice = (set, get)=>({
83
85
  set((draft)=>{
84
86
  draft.panelGroupEditor = editor;
85
87
  });
86
- },
87
- openDeletePanelGroupDialog: (panelGroupId)=>{
88
- const panelGroup = get().panelGroups[panelGroupId];
89
- if (panelGroup === undefined) {
90
- throw new Error(`Panel group with Id ${panelGroupId} not found`);
91
- }
92
- set((state)=>{
93
- state.deletePanelGroupDialog = {
94
- panelGroupId,
95
- panelGroupName: panelGroup.title
96
- };
97
- });
98
- },
99
- closeDeletePanelGroupDialog: ()=>set((state)=>{
100
- state.deletePanelGroupDialog = undefined;
101
- })
88
+ }
102
89
  });