@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
@@ -11,29 +11,23 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
14
+ import { generateId } from './common';
14
15
  /**
15
16
  * Curried function for creating the PanelEditorSlice.
16
- */ export function createPanelEditorSlice(panels) {
17
+ */ export function createPanelEditorSlice() {
17
18
  // Return the state creator function for Zustand that uses the panels provided as intitial state
18
19
  return (set, get)=>{
19
20
  return {
20
- previousPanels: panels,
21
- panels,
22
21
  panelEditor: undefined,
23
- savePanels () {
24
- set((state)=>{
25
- state.previousPanels = state.panels;
26
- });
27
- },
28
- resetPanels () {
29
- set((state)=>{
30
- state.panels = state.previousPanels;
31
- });
32
- },
33
- openEditPanel (item) {
34
- const { panels , getPanelKey } = get();
35
- // Ask the layout store for the panel key at that location
36
- const panelKey = getPanelKey(item);
22
+ openEditPanel (panelGroupItemId) {
23
+ var ref;
24
+ const { panels , panelGroups } = get();
25
+ // Figure out the panel key at that location
26
+ const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
27
+ const panelKey = (ref = panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.itemPanelKeys[panelGroupLayoutId];
28
+ if (panelKey === undefined) {
29
+ throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);
30
+ }
37
31
  // Find the panel to edit
38
32
  const panelToEdit = panels[panelKey];
39
33
  if (panelToEdit === undefined) {
@@ -45,19 +39,46 @@ import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
45
39
  initialValues: {
46
40
  name: panelToEdit.spec.display.name,
47
41
  description: (_description = panelToEdit.spec.display.description) !== null && _description !== void 0 ? _description : '',
48
- groupId: item.panelGroupId,
42
+ groupId: panelGroupItemId.panelGroupId,
49
43
  kind: panelToEdit.spec.plugin.kind,
50
44
  spec: panelToEdit.spec.plugin.spec
51
45
  },
52
46
  applyChanges: (next)=>{
53
47
  const panelDefinititon = createPanelDefinitionFromEditorValues(next);
54
- set((state)=>{
55
- state.panels[panelKey] = panelDefinititon;
48
+ set((draft)=>{
49
+ draft.panels[panelKey] = panelDefinititon;
50
+ // If the panel didn't change groups, nothing else to do
51
+ if (next.groupId === panelGroupId) {
52
+ return;
53
+ }
54
+ // Move panel to the new group
55
+ const existingGroup = draft.panelGroups[panelGroupId];
56
+ if (existingGroup === undefined) {
57
+ throw new Error(`Missing panel group ${panelGroupId}`);
58
+ }
59
+ const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout)=>layout.i === panelGroupLayoutId);
60
+ const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];
61
+ const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];
62
+ if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {
63
+ throw new Error(`Missing panel group item ${panelGroupLayoutId}`);
64
+ }
65
+ // Remove item from the old group
66
+ existingGroup.itemLayouts.splice(existingLayoutIdx, 1);
67
+ delete existingGroup.itemPanelKeys[panelGroupLayoutId];
68
+ // Add item to the end of the new group
69
+ const newGroup = draft.panelGroups[next.groupId];
70
+ if (newGroup === undefined) {
71
+ throw new Error(`Could not find new group ${next.groupId}`);
72
+ }
73
+ newGroup.itemLayouts.push({
74
+ i: existingLayout.i,
75
+ x: 0,
76
+ y: getYForNewRow(newGroup),
77
+ w: existingLayout.w,
78
+ h: existingLayout.h
79
+ });
80
+ newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;
56
81
  });
57
- // Move the panel to another group if it changed
58
- if (next.groupId !== item.panelGroupId) {
59
- get().movePanelToGroup(item, next.groupId);
60
- }
61
82
  },
62
83
  close: ()=>{
63
84
  set((state)=>{
@@ -73,7 +94,7 @@ import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
73
94
  openAddPanel (panelGroupId) {
74
95
  // If a panel group isn't supplied, add to the first group
75
96
  if (panelGroupId === undefined) {
76
- const firstGroupId = get().panelGroupIdOrder[0];
97
+ const firstGroupId = get().panelGroupOrder[0];
77
98
  if (firstGroupId === undefined) {
78
99
  throw new Error('No panel groups to add a panel to');
79
100
  }
@@ -93,10 +114,24 @@ import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
93
114
  applyChanges: (next)=>{
94
115
  const panelDef = createPanelDefinitionFromEditorValues(next);
95
116
  const panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);
96
- set((state)=>{
97
- state.panels[panelKey] = panelDef;
117
+ set((draft)=>{
118
+ // Add a panel
119
+ draft.panels[panelKey] = panelDef;
120
+ // Also add a panel group item referencing the panel
121
+ const group = draft.panelGroups[next.groupId];
122
+ if (group === undefined) {
123
+ throw new Error(`Missing panel group ${next.groupId}`);
124
+ }
125
+ const layout = {
126
+ i: generateId().toString(),
127
+ x: 0,
128
+ y: getYForNewRow(group),
129
+ w: 12,
130
+ h: 6
131
+ };
132
+ group.itemLayouts.push(layout);
133
+ group.itemPanelKeys[layout.i] = panelKey;
98
134
  });
99
- get().addPanelToGroup(panelKey, next.groupId);
100
135
  },
101
136
  close: ()=>{
102
137
  set((state)=>{
@@ -108,45 +143,6 @@ import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
108
143
  set((state)=>{
109
144
  state.panelEditor = editorState;
110
145
  });
111
- },
112
- deletePanels (items) {
113
- const { mapPanelToPanelGroups , deletePanelInPanelGroup , getPanelKey } = get();
114
- const map = mapPanelToPanelGroups();
115
- // get panel key first before deleting panel from panel group since getPanelKey relies on index
116
- const panels = items.map((panel)=>{
117
- return {
118
- ...panel,
119
- panelKey: getPanelKey(panel)
120
- };
121
- });
122
- panels.forEach(({ panelKey , ...panel })=>{
123
- var ref;
124
- deletePanelInPanelGroup(panel);
125
- // make sure panel is only referenced in one panel group before deleting it from state.panels
126
- if (map[panelKey] && ((ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.length) === 1) {
127
- set((state)=>{
128
- delete state.panels[panelKey];
129
- });
130
- }
131
- });
132
- },
133
- openDeletePanelDialog (item) {
134
- const { panels , getPanelKey , panelGroups } = get();
135
- const panelKey = getPanelKey(item);
136
- set((state)=>{
137
- var ref, ref1;
138
- var _name, ref2;
139
- state.deletePanelDialog = {
140
- panelGroupItemId: item,
141
- panelName: (_name = (ref = panels[panelKey]) === null || ref === void 0 ? void 0 : ref.spec.display.name) !== null && _name !== void 0 ? _name : '',
142
- panelGroupName: (ref2 = (ref1 = panelGroups[item.panelGroupId]) === null || ref1 === void 0 ? void 0 : ref1.title) !== null && ref2 !== void 0 ? ref2 : ''
143
- };
144
- });
145
- },
146
- closeDeletePanelDialog () {
147
- set((state)=>{
148
- state.deletePanelDialog = undefined;
149
- });
150
146
  }
151
147
  };
152
148
  };
@@ -167,5 +163,16 @@ function createPanelDefinitionFromEditorValues(editorValues) {
167
163
  }
168
164
  };
169
165
  }
166
+ // Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present
167
+ function getYForNewRow(group) {
168
+ let newRowY = 0;
169
+ for (const layout of group.itemLayouts){
170
+ const itemMaxY = layout.y + layout.h;
171
+ if (itemMaxY > newRowY) {
172
+ newRowY = itemMaxY;
173
+ }
174
+ }
175
+ return newRowY;
176
+ }
170
177
 
171
178
  //# sourceMappingURL=panel-editor-slice.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition, UnknownSpec } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupItemId, PanelGroupId } from './panel-group-slice';\n\n/**\n * Slice that handles the visual editor state and actions for Panels (i.e. add, edit, delete).\n */\nexport interface PanelEditorSlice {\n // TODO: Move panels state to its own slice so that other slices can depend on it (and modify the state)\n panels: Record<string, PanelDefinition>;\n previousPanels: Record<string, PanelDefinition>;\n\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (item: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n\n /**\n * Delete panels\n */\n deletePanels: (panels: PanelGroupItemId[]) => void;\n\n /**\n * Reset panels to previous state\n */\n resetPanels: () => void;\n\n /**\n * Save panels\n */\n savePanels: () => void;\n\n /**\n * State for the delete panel dialog when it's open, otherwise undefined when it's closed.\n */\n deletePanelDialog?: DeletePanelDialog;\n\n /**\n * Open delete panel dialog\n */\n openDeletePanelDialog: (item: PanelGroupItemId) => void;\n\n /**\n * Close delete panel dialog\n */\n closeDeletePanelDialog: () => void;\n}\n\nexport interface DeletePanelDialog {\n panelGroupItemId: PanelGroupItemId;\n panelName: string;\n panelGroupName: string;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: 'Add' | 'Edit';\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Panel values that can be edited in the panel editor.\n */\nexport interface PanelEditorValues {\n name: string;\n description: string;\n groupId: PanelGroupId;\n kind: string;\n spec: UnknownSpec;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(\n panels: PanelEditorSlice['panels']\n): StateCreator<PanelEditorSlice & PanelGroupSlice, Middleware, [], PanelEditorSlice> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n previousPanels: panels,\n panels,\n\n panelEditor: undefined,\n\n savePanels() {\n set((state) => {\n state.previousPanels = state.panels;\n });\n },\n\n resetPanels() {\n set((state) => {\n state.panels = state.previousPanels;\n });\n },\n\n openEditPanel(item) {\n const { panels, getPanelKey } = get();\n\n // Ask the layout store for the panel key at that location\n const panelKey = getPanelKey(item);\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'Edit',\n initialValues: {\n name: panelToEdit.spec.display.name,\n description: panelToEdit.spec.display.description ?? '',\n groupId: item.panelGroupId,\n kind: panelToEdit.spec.plugin.kind,\n spec: panelToEdit.spec.plugin.spec,\n },\n applyChanges: (next) => {\n const panelDefinititon = createPanelDefinitionFromEditorValues(next);\n set((state) => {\n state.panels[panelKey] = panelDefinititon;\n });\n\n // Move the panel to another group if it changed\n if (next.groupId !== item.panelGroupId) {\n get().movePanelToGroup(item, next.groupId);\n }\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId) {\n // If a panel group isn't supplied, add to the first group\n if (panelGroupId === undefined) {\n const firstGroupId = get().panelGroupIdOrder[0];\n if (firstGroupId === undefined) {\n throw new Error('No panel groups to add a panel to');\n }\n panelGroupId = firstGroupId;\n }\n\n const editorState: PanelEditorState = {\n mode: 'Add',\n initialValues: {\n name: '',\n description: '',\n groupId: panelGroupId,\n // TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to\n // set a smarter default here?\n kind: '',\n spec: {},\n },\n applyChanges: (next) => {\n const panelDef = createPanelDefinitionFromEditorValues(next);\n const panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);\n set((state) => {\n state.panels[panelKey] = panelDef;\n });\n get().addPanelToGroup(panelKey, next.groupId);\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n deletePanels(items: PanelGroupItemId[]) {\n const { mapPanelToPanelGroups, deletePanelInPanelGroup, getPanelKey } = get();\n const map = mapPanelToPanelGroups();\n // get panel key first before deleting panel from panel group since getPanelKey relies on index\n const panels = items.map((panel) => {\n return { ...panel, panelKey: getPanelKey(panel) };\n });\n panels.forEach(({ panelKey, ...panel }) => {\n deletePanelInPanelGroup(panel);\n // make sure panel is only referenced in one panel group before deleting it from state.panels\n if (map[panelKey] && map[panelKey]?.length === 1) {\n set((state) => {\n delete state.panels[panelKey];\n });\n }\n });\n },\n\n openDeletePanelDialog(item: PanelGroupItemId) {\n const { panels, getPanelKey, panelGroups } = get();\n const panelKey = getPanelKey(item);\n set((state) => {\n state.deletePanelDialog = {\n panelGroupItemId: item,\n panelName: panels[panelKey]?.spec.display.name ?? '',\n panelGroupName: panelGroups[item.panelGroupId]?.title ?? '',\n };\n });\n },\n\n closeDeletePanelDialog() {\n set((state) => {\n state.deletePanelDialog = undefined;\n });\n },\n });\n}\n\n// Helper to create PanelDefinitions when saving\nfunction createPanelDefinitionFromEditorValues(editorValues: PanelEditorValues): PanelDefinition {\n return {\n kind: 'Panel',\n spec: {\n display: {\n name: editorValues.name,\n description: editorValues.description !== '' ? editorValues.description : undefined,\n },\n plugin: {\n kind: editorValues.kind,\n spec: editorValues.spec,\n },\n },\n };\n}\n"],"names":["removeWhiteSpacesAndSpecialCharacters","createPanelEditorSlice","panels","set","get","previousPanels","panelEditor","undefined","savePanels","state","resetPanels","openEditPanel","item","getPanelKey","panelKey","panelToEdit","Error","editorState","mode","initialValues","name","spec","display","description","groupId","panelGroupId","kind","plugin","applyChanges","next","panelDefinititon","createPanelDefinitionFromEditorValues","movePanelToGroup","close","openAddPanel","firstGroupId","panelGroupIdOrder","panelDef","addPanelToGroup","deletePanels","items","mapPanelToPanelGroups","deletePanelInPanelGroup","map","panel","forEach","length","openDeletePanelDialog","panelGroups","deletePanelDialog","panelGroupItemId","panelName","panelGroupName","title","closeDeletePanelDialog","editorValues"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEA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Q,CAAC,cAAhBZ,GAAgB,WAAM,GAAtBA,KAAAA,CAAsB,GAAtBA,GAAgB,CAAEmB,IAAI,CAACC,OAAO,CAACF,IAAI,cAAnClB,KAAmC,cAAnCA,KAAmC,GAAI,EAAE;wBACpDkD,cAAc,EAAEJ,CAAAA,IAAqC,GAArCA,CAAAA,IAA8B,GAA9BA,WAAW,CAACpC,IAAI,CAACa,YAAY,CAAC,cAA9BuB,IAA8B,WAAO,GAArCA,KAAAA,CAAqC,GAArCA,IAA8B,CAAEK,KAAK,cAArCL,IAAqC,cAArCA,IAAqC,GAAI,EAAE;qBAC5D,CAAC;gBACJ,CAAC,CAAC,CAAC;YACL,CAAC;YAEDM,sBAAsB,IAAG;gBACvBnD,GAAG,CAAC,CAACM,KAAK,GAAK;oBACbA,KAAK,CAACwC,iBAAiB,GAAG1C,SAAS,CAAC;gBACtC,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAA;KAAC,CAAC;AACL,CAAC;AAED,gDAAgD;AAChD,SAASwB,qCAAqC,CAACwB,YAA+B,EAAmB;IAC/F,OAAO;QACL7B,IAAI,EAAE,OAAO;QACbL,IAAI,EAAE;YACJC,OAAO,EAAE;gBACPF,IAAI,EAAEmC,YAAY,CAACnC,IAAI;gBACvBG,WAAW,EAAEgC,YAAY,CAAChC,WAAW,KAAK,EAAE,GAAGgC,YAAY,CAAChC,WAAW,GAAGhB,SAAS;aACpF;YACDoB,MAAM,EAAE;gBACND,IAAI,EAAE6B,YAAY,CAAC7B,IAAI;gBACvBL,IAAI,EAAEkC,YAAY,CAAClC,IAAI;aACxB;SACF;KACF,CAAC;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition, UnknownSpec } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';\nimport { generateId, Middleware } from './common';\nimport {\n PanelGroupSlice,\n PanelGroupItemId,\n PanelGroupId,\n PanelGroupDefinition,\n PanelGroupItemLayout,\n} from './panel-group-slice';\nimport { PanelSlice } from './panel-slice';\n\n/**\n * Slice that handles the visual editor state and actions for adding or editing Panels.\n */\nexport interface PanelEditorSlice {\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Opens the editor for editing an existing panel by providing its layout coordinates.\n */\n openEditPanel: (panelGroupItemId: PanelGroupItemId) => void;\n\n /**\n * Opens the editor for adding a new Panel to a panel group.\n */\n openAddPanel: (panelGroupId?: PanelGroupId) => void;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: 'Add' | 'Edit';\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Panel values that can be edited in the panel editor.\n */\nexport interface PanelEditorValues {\n name: string;\n description: string;\n groupId: PanelGroupId;\n kind: string;\n spec: UnknownSpec;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(): StateCreator<\n // Actions in here need to modify both Panels and Panel Groups state\n PanelEditorSlice & PanelSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelEditorSlice\n> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panelEditor: undefined,\n\n openEditPanel(panelGroupItemId) {\n const { panels, panelGroups } = get();\n\n // Figure out the panel key at that location\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panelKey = panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) {\n throw new Error(`Could not find Panel Group item ${panelGroupItemId}`);\n }\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'Edit',\n initialValues: {\n name: panelToEdit.spec.display.name,\n description: panelToEdit.spec.display.description ?? '',\n groupId: panelGroupItemId.panelGroupId,\n kind: panelToEdit.spec.plugin.kind,\n spec: panelToEdit.spec.plugin.spec,\n },\n applyChanges: (next) => {\n const panelDefinititon = createPanelDefinitionFromEditorValues(next);\n set((draft) => {\n draft.panels[panelKey] = panelDefinititon;\n\n // If the panel didn't change groups, nothing else to do\n if (next.groupId === panelGroupId) {\n return;\n }\n\n // Move panel to the new group\n const existingGroup = draft.panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Missing panel group ${panelGroupId}`);\n }\n\n const existingLayoutIdx = existingGroup.itemLayouts.findIndex((layout) => layout.i === panelGroupLayoutId);\n const existingLayout = existingGroup.itemLayouts[existingLayoutIdx];\n const existingPanelKey = existingGroup.itemPanelKeys[panelGroupLayoutId];\n if (existingLayoutIdx === -1 || existingLayout === undefined || existingPanelKey === undefined) {\n throw new Error(`Missing panel group item ${panelGroupLayoutId}`);\n }\n\n // Remove item from the old group\n existingGroup.itemLayouts.splice(existingLayoutIdx, 1);\n delete existingGroup.itemPanelKeys[panelGroupLayoutId];\n\n // Add item to the end of the new group\n const newGroup = draft.panelGroups[next.groupId];\n if (newGroup === undefined) {\n throw new Error(`Could not find new group ${next.groupId}`);\n }\n\n newGroup.itemLayouts.push({\n i: existingLayout.i,\n x: 0,\n y: getYForNewRow(newGroup),\n w: existingLayout.w,\n h: existingLayout.h,\n });\n newGroup.itemPanelKeys[existingLayout.i] = existingPanelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n openAddPanel(panelGroupId) {\n // If a panel group isn't supplied, add to the first group\n if (panelGroupId === undefined) {\n const firstGroupId = get().panelGroupOrder[0];\n if (firstGroupId === undefined) {\n throw new Error('No panel groups to add a panel to');\n }\n panelGroupId = firstGroupId;\n }\n\n const editorState: PanelEditorState = {\n mode: 'Add',\n initialValues: {\n name: '',\n description: '',\n groupId: panelGroupId,\n // TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to\n // set a smarter default here?\n kind: '',\n spec: {},\n },\n applyChanges: (next) => {\n const panelDef = createPanelDefinitionFromEditorValues(next);\n const panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);\n set((draft) => {\n // Add a panel\n draft.panels[panelKey] = panelDef;\n\n // Also add a panel group item referencing the panel\n const group = draft.panelGroups[next.groupId];\n if (group === undefined) {\n throw new Error(`Missing panel group ${next.groupId}`);\n }\n const layout: PanelGroupItemLayout = {\n i: generateId().toString(),\n x: 0,\n y: getYForNewRow(group),\n w: 12,\n h: 6,\n };\n group.itemLayouts.push(layout);\n group.itemPanelKeys[layout.i] = panelKey;\n });\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n });\n}\n\n// Helper to create PanelDefinitions when saving\nfunction createPanelDefinitionFromEditorValues(editorValues: PanelEditorValues): PanelDefinition {\n return {\n kind: 'Panel',\n spec: {\n display: {\n name: editorValues.name,\n description: editorValues.description !== '' ? editorValues.description : undefined,\n },\n plugin: {\n kind: editorValues.kind,\n spec: editorValues.spec,\n },\n },\n };\n}\n\n// Given a PanelGroup, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nfunction getYForNewRow(group: PanelGroupDefinition) {\n let newRowY = 0;\n for (const layout of group.itemLayouts) {\n const itemMaxY = layout.y + layout.h;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n"],"names":["removeWhiteSpacesAndSpecialCharacters","generateId","createPanelEditorSlice","set","get","panelEditor","undefined","openEditPanel","panelGroupItemId","panelGroups","panels","panelGroupId","panelGroupItemLayoutId","panelGroupLayoutId","panelKey","itemPanelKeys","Error","panelToEdit","editorState","mode","initialValues","name","spec","display","description","groupId","kind","plugin","applyChanges","next","panelDefinititon","createPanelDefinitionFromEditorValues","draft","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","getYForNewRow","w","h","close","state","openAddPanel","firstGroupId","panelGroupOrder","panelDef","group","toString","editorValues","newRowY","itemMaxY"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SAASA,qCAAqC,QAAQ,uBAAuB,CAAC;AAC9E,SAASC,UAAU,QAAoB,UAAU,CAAC;AA+DlD;;CAEC,GACD,OAAO,SAASC,sBAAsB,GAMpC;IACA,gGAAgG;IAChG,OAAO,CAACC,GAAG,EAAEC,GAAG;QAAM,OAAA;YACpBC,WAAW,EAAEC,SAAS;YAEtBC,aAAa,EAACC,gBAAgB,EAAE;oBAKbC,GAAyB;gBAJ1C,MAAM,EAAEC,MAAM,CAAA,EAAED,WAAW,CAAA,EAAE,GAAGL,GAAG,EAAE,AAAC;gBAEtC,4CAA4C;gBAC5C,MAAM,EAAEO,YAAY,CAAA,EAAEC,sBAAsB,EAAEC,kBAAkB,CAAA,EAAE,GAAGL,gBAAgB,AAAC;gBACtF,MAAMM,QAAQ,GAAGL,CAAAA,GAAyB,GAAzBA,WAAW,CAACE,YAAY,CAAC,c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a,qCAAqC,CAAC0B,YAA+B,EAAmB;IAC/F,OAAO;QACL/B,IAAI,EAAE,OAAO;QACbJ,IAAI,EAAE;YACJC,OAAO,EAAE;gBACPF,IAAI,EAAEoC,YAAY,CAACpC,IAAI;gBACvBG,WAAW,EAAEiC,YAAY,CAACjC,WAAW,KAAK,EAAE,GAAGiC,YAAY,CAACjC,WAAW,GAAGlB,SAAS;aACpF;YACDqB,MAAM,EAAE;gBACND,IAAI,EAAE+B,YAAY,CAAC/B,IAAI;gBACvBJ,IAAI,EAAEmC,YAAY,CAACnC,IAAI;aACxB;SACF;KACF,CAAC;AACJ,CAAC;AAED,yHAAyH;AACzH,SAASwB,aAAa,CAACS,KAA2B,EAAE;IAClD,IAAIG,OAAO,GAAG,CAAC,AAAC;IAChB,KAAK,MAAMrB,MAAM,IAAIkB,KAAK,CAACpB,WAAW,CAAE;QACtC,MAAMwB,QAAQ,GAAGtB,MAAM,CAACQ,CAAC,GAAGR,MAAM,CAACW,CAAC,AAAC;QACrC,IAAIW,QAAQ,GAAGD,OAAO,EAAE;YACtBA,OAAO,GAAGC,QAAQ,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAOD,OAAO,CAAC;AACjB,CAAC"}
@@ -11,12 +11,8 @@ export interface PanelGroupEditorValues {
11
11
  title: string;
12
12
  isCollapsed: boolean;
13
13
  }
14
- export interface DeletePanelGroupDialog {
15
- panelGroupId: PanelGroupId;
16
- panelGroupName?: string;
17
- }
18
14
  /**
19
- * Slice that handles the visual editor state and actions for Panel Groups (i.e. add, edit, delete).
15
+ * Slice that handles the visual editor state and related actions for adding or editing Panel Groups.
20
16
  */
21
17
  export interface PanelGroupEditorSlice {
22
18
  /**
@@ -31,9 +27,6 @@ export interface PanelGroupEditorSlice {
31
27
  * Opens the panel group editor to edit an existing panel group.
32
28
  */
33
29
  openEditPanelGroup: (panelGroupId: PanelGroupId) => void;
34
- deletePanelGroupDialog?: DeletePanelGroupDialog;
35
- openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;
36
- closeDeletePanelGroupDialog: () => void;
37
30
  }
38
31
  export declare const createPanelGroupEditorSlice: StateCreator<PanelGroupEditorSlice & PanelGroupSlice, Middleware, [
39
32
  ], PanelGroupEditorSlice>;
@@ -1 +1 @@
1
- {"version":3,"file":"panel-group-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAwB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE1F,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,sBAAsB,CAAC;IACtC,YAAY,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACrD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,YAAY,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAE9B;;OAEG;IACH,kBAAkB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IAEzD,sBAAsB,CAAC,EAAE,sBAAsB,CAAC;IAChD,0BAA0B,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;IACjE,2BAA2B,EAAE,MAAM,IAAI,CAAC;CACzC;AAED,eAAO,MAAM,2BAA2B,EAAE,YAAY,CACpD,qBAAqB,GAAG,eAAe,EACvC,UAAU,EACV;CAAE,EACF,qBAAqB,CAqFrB,CAAC"}
1
+ {"version":3,"file":"panel-group-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EAAE,eAAe,EAAwB,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAE1F,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IACrB,aAAa,EAAE,sBAAsB,CAAC;IACtC,YAAY,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,CAAC;IACrD,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,sBAAsB;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,OAAO,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;OAEG;IACH,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IAEpC;;OAEG;IACH,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAE9B;;OAEG;IACH,kBAAkB,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,CAAC;CAC1D;AAED,eAAO,MAAM,2BAA2B,EAAE,YAAY,CAEpD,qBAAqB,GAAG,eAAe,EACvC,UAAU,EACV;CAAE,EACF,qBAAqB,CAwErB,CAAC"}
@@ -10,6 +10,7 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
+ import { generateId } from './common';
13
14
  export const createPanelGroupEditorSlice = (set, get)=>({
14
15
  panelGroupEditor: undefined,
15
16
  openAddPanelGroup: ()=>{
@@ -22,13 +23,14 @@ export const createPanelGroupEditorSlice = (set, get)=>({
22
23
  },
23
24
  applyChanges (next) {
24
25
  const newGroup = {
25
- id: get().createPanelGroupId(),
26
- items: [],
26
+ id: generateId(),
27
+ itemLayouts: [],
28
+ itemPanelKeys: {},
27
29
  ...next
28
30
  };
29
31
  set((draft)=>{
30
32
  draft.panelGroups[newGroup.id] = newGroup;
31
- draft.panelGroupIdOrder.unshift(newGroup.id);
33
+ draft.panelGroupOrder.unshift(newGroup.id);
32
34
  });
33
35
  },
34
36
  close () {
@@ -75,22 +77,7 @@ export const createPanelGroupEditorSlice = (set, get)=>({
75
77
  set((draft)=>{
76
78
  draft.panelGroupEditor = editor;
77
79
  });
78
- },
79
- openDeletePanelGroupDialog: (panelGroupId)=>{
80
- const panelGroup = get().panelGroups[panelGroupId];
81
- if (panelGroup === undefined) {
82
- throw new Error(`Panel group with Id ${panelGroupId} not found`);
83
- }
84
- set((state)=>{
85
- state.deletePanelGroupDialog = {
86
- panelGroupId,
87
- panelGroupName: panelGroup.title
88
- };
89
- });
90
- },
91
- closeDeletePanelGroupDialog: ()=>set((state)=>{
92
- state.deletePanelGroupDialog = undefined;
93
- })
80
+ }
94
81
  });
95
82
 
96
83
  //# sourceMappingURL=panel-group-editor-slice.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupDefinition, PanelGroupId } from './panel-group-slice';\n\nexport interface PanelGroupEditor {\n mode: 'Add' | 'Edit';\n initialValues: PanelGroupEditorValues;\n applyChanges: (next: PanelGroupEditorValues) => void;\n close: () => void;\n}\n\nexport interface PanelGroupEditorValues {\n title: string;\n isCollapsed: boolean;\n}\n\nexport interface DeletePanelGroupDialog {\n panelGroupId: PanelGroupId;\n panelGroupName?: string;\n}\n\n/**\n * Slice that handles the visual editor state and actions for Panel Groups (i.e. add, edit, delete).\n */\nexport interface PanelGroupEditorSlice {\n /**\n * State that's present when the panel group editor is open.\n */\n panelGroupEditor?: PanelGroupEditor;\n\n /**\n * Opens the panel group editor to add a new panel group.\n */\n openAddPanelGroup: () => void;\n\n /**\n * Opens the panel group editor to edit an existing panel group.\n */\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n\n deletePanelGroupDialog?: DeletePanelGroupDialog;\n openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;\n closeDeletePanelGroupDialog: () => void;\n}\n\nexport const createPanelGroupEditorSlice: StateCreator<\n PanelGroupEditorSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelGroupEditorSlice\n> = (set, get) => ({\n panelGroupEditor: undefined,\n\n openAddPanelGroup: () => {\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Add',\n initialValues: {\n title: '',\n isCollapsed: false,\n },\n applyChanges(next) {\n const newGroup: PanelGroupDefinition = {\n id: get().createPanelGroupId(),\n items: [],\n ...next,\n };\n set((draft) => {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupIdOrder.unshift(newGroup.id);\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openEditPanelGroup: (panelGroupId) => {\n const existingGroup = get().panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Edit',\n initialValues: {\n title: existingGroup.title ?? '',\n isCollapsed: existingGroup.isCollapsed,\n },\n applyChanges(next) {\n set((draft) => {\n const group = draft.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n group.title = next.title;\n group.isCollapsed = next.isCollapsed;\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openDeletePanelGroupDialog: (panelGroupId) => {\n const panelGroup = get().panelGroups[panelGroupId];\n if (panelGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} not found`);\n }\n set((state) => {\n state.deletePanelGroupDialog = { panelGroupId, panelGroupName: panelGroup.title };\n });\n },\n closeDeletePanelGroupDialog: () =>\n set((state) => {\n state.deletePanelGroupDialog = undefined;\n }),\n});\n"],"names":["createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","id","createPanelGroupId","items","draft","panelGroups","panelGroupIdOrder","unshift","close","openEditPanelGroup","panelGroupId","existingGroup","Error","group","openDeletePanelGroupDialog","panelGroup","state","deletePanelGroupDialog","panelGroupName","closeDeletePanelGroupDialog"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AA+CjC,OAAO,MAAMA,2BAA2B,GAKpC,CAACC,GAAG,EAAEC,GAAG,GAAM,CAAA;QACjBC,gBAAgB,EAAEC,SAAS;QAE3BC,iBAAiB,EAAE,IAAM;YACvB,0BAA0B;YAC1B,MAAMC,MAAM,GAAqB;gBAC/BC,IAAI,EAAE,KAAK;gBACXC,aAAa,EAAE;oBACbC,KAAK,EAAE,EAAE;oBACTC,WAAW,EAAE,KAAK;iBACnB;gBACD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,CAACC,sBAAsB,GAAG1B,SAAS,CAAC;YAC3C,CAAC,CAAC;KACL,CAAA,AAAC,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-editor-slice.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupDefinition, PanelGroupId } from './panel-group-slice';\n\nexport interface PanelGroupEditor {\n mode: 'Add' | 'Edit';\n initialValues: PanelGroupEditorValues;\n applyChanges: (next: PanelGroupEditorValues) => void;\n close: () => void;\n}\n\nexport interface PanelGroupEditorValues {\n title: string;\n isCollapsed: boolean;\n}\n\n/**\n * Slice that handles the visual editor state and related actions for adding or editing Panel Groups.\n */\nexport interface PanelGroupEditorSlice {\n /**\n * State that's present when the panel group editor is open.\n */\n panelGroupEditor?: PanelGroupEditor;\n\n /**\n * Opens the panel group editor to add a new panel group.\n */\n openAddPanelGroup: () => void;\n\n /**\n * Opens the panel group editor to edit an existing panel group.\n */\n openEditPanelGroup: (panelGroupId: PanelGroupId) => void;\n}\n\nexport const createPanelGroupEditorSlice: StateCreator<\n // Actions in here need to modify Panel Group state\n PanelGroupEditorSlice & PanelGroupSlice,\n Middleware,\n [],\n PanelGroupEditorSlice\n> = (set, get) => ({\n panelGroupEditor: undefined,\n\n openAddPanelGroup: () => {\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Add',\n initialValues: {\n title: '',\n isCollapsed: false,\n },\n applyChanges(next) {\n const newGroup: PanelGroupDefinition = {\n id: generateId(),\n itemLayouts: [],\n itemPanelKeys: {},\n ...next,\n };\n set((draft) => {\n draft.panelGroups[newGroup.id] = newGroup;\n draft.panelGroupOrder.unshift(newGroup.id);\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n\n openEditPanelGroup: (panelGroupId) => {\n const existingGroup = get().panelGroups[panelGroupId];\n if (existingGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n\n // Create the editor state\n const editor: PanelGroupEditor = {\n mode: 'Edit',\n initialValues: {\n title: existingGroup.title ?? '',\n isCollapsed: existingGroup.isCollapsed,\n },\n applyChanges(next) {\n set((draft) => {\n const group = draft.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} does not exist`);\n }\n group.title = next.title;\n group.isCollapsed = next.isCollapsed;\n });\n },\n close() {\n set((draft) => {\n draft.panelGroupEditor = undefined;\n });\n },\n };\n\n // Open the editor\n set((draft) => {\n draft.panelGroupEditor = editor;\n });\n },\n});\n"],"names":["generateId","createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","id","itemLayouts","itemPanelKeys","draft","panelGroups","panelGroupOrder","unshift","close","openEditPanelGroup","panelGroupId","existingGroup","Error","group"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,UAAU,QAAoB,UAAU,CAAC;AAmClD,OAAO,MAAMC,2BAA2B,GAMpC,CAACC,GAAG,EAAEC,GAAG,GAAM,CAAA;QACjBC,gBAAgB,EAAEC,SAAS;QAE3BC,iBAAiB,EAAE,IAAM;YACvB,0BAA0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,MAAmB,GAAnBA,aAAa,CAACf,KAAK,cAAnBe,MAAmB,cAAnBA,MAAmB,GAAI,EAAE;oBAChCd,WAAW,EAAEc,aAAa,CAACd,WAAW;iBACvC;gBACDC,YAAY,EAACC,IAAI,EAAE;oBACjBX,GAAG,CAAC,CAACgB,KAAK,GAAK;wBACb,MAAMS,KAAK,GAAGT,KAAK,CAACC,WAAW,CAACK,YAAY,CAAC,AAAC;wBAC9C,IAAIG,KAAK,KAAKtB,SAAS,EAAE;4BACvB,MAAM,IAAIqB,KAAK,CAAC,CAAC,oBAAoB,EAAEF,YAAY,CAAC,eAAe,CAAC,CAAC,CAAC;wBACxE,CAAC;wBACDG,KAAK,CAACjB,KAAK,GAAGG,IAAI,CAACH,KAAK,CAAC;wBACzBiB,KAAK,CAAChB,WAAW,GAAGE,IAAI,CAACF,WAAW,CAAC;oBACvC,CAAC,CAAC,CAAC;gBACL,CAAC;gBACDW,KAAK,IAAG;oBACNpB,GAAG,CAAC,CAACgB,KAAK,GAAK;wBACbA,KAAK,CAACd,gBAAgB,GAAGC,SAAS,CAAC;oBACrC,CAAC,CAAC,CAAC;gBACL,CAAC;aACF,AAAC;YAEF,kBAAkB;YAClBH,GAAG,CAAC,CAACgB,KAAK,GAAK;gBACbA,KAAK,CAACd,gBAAgB,GAAGG,MAAM,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAA,AAAC,CAAC"}
@@ -1,7 +1,7 @@
1
- import { GridItemDefinition, LayoutDefinition } from '@perses-dev/core';
1
+ import { LayoutDefinition } from '@perses-dev/core';
2
+ import { Layout } from 'react-grid-layout';
2
3
  import { StateCreator } from 'zustand';
3
4
  import { Middleware } from './common';
4
- import { PanelEditorSlice } from './panel-editor-slice';
5
5
  /**
6
6
  * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.
7
7
  */
@@ -13,68 +13,38 @@ export interface PanelGroupSlice {
13
13
  /**
14
14
  * An array of panel group IDs, representing their order in the dashboard.
15
15
  */
16
- panelGroupIdOrder: PanelGroupId[];
17
- /**
18
- * previous state
19
- */
20
- previousPanelGroupStates: {
21
- panelGroups: PanelGroupSlice['panelGroups'];
22
- panelGroupIdOrder: PanelGroupSlice['panelGroupIdOrder'];
23
- };
24
- createPanelGroupId: () => PanelGroupId;
25
- /**
26
- * Given a LayoutItem location, returns the panel's unique key at that location.
27
- */
28
- getPanelKey: (layoutItem: PanelGroupItemId) => string;
29
- /**
30
- * Add a panel with the specified key to an existing group.
31
- */
32
- addPanelToGroup: (panelKey: string, panelGroupId: PanelGroupId) => void;
33
- /**
34
- * Move an existing Panel to a new panel group.
35
- */
36
- movePanelToGroup: (layoutItem: PanelGroupItemId, newPanelGroupId: PanelGroupId) => void;
16
+ panelGroupOrder: PanelGroupId[];
37
17
  /**
38
18
  * Rearrange the order of panel groups by swapping the positions
39
19
  */
40
20
  swapPanelGroups: (xIndex: number, yIndex: number) => void;
41
21
  /**
42
- * Delete panel group and all the panels within the group
22
+ * Update the item layouts for a panel group when, for example, a panel is moved or resized.
43
23
  */
44
- deletePanelGroup: (panelGroupId: PanelGroupId) => void;
45
- /**
46
- * Delete panel in panel group
47
- */
48
- deletePanelInPanelGroup: (layoutItem: PanelGroupItemId) => void;
49
- /**
50
- * Map panel to panel groups
51
- */
52
- mapPanelToPanelGroups: () => Record<string, PanelGroupId[]>;
53
- /**
54
- * save
55
- */
56
- savePanelGroups: () => void;
57
- /**
58
- * reset to previous panel group states
59
- */
60
- resetPanelGroups: () => void;
24
+ updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;
61
25
  }
62
26
  export declare type PanelGroupId = number;
63
27
  export interface PanelGroupDefinition {
64
28
  id: PanelGroupId;
65
- items: GridItemDefinition[];
66
29
  isCollapsed: boolean;
67
30
  title?: string;
31
+ itemLayouts: PanelGroupItemLayout[];
32
+ itemPanelKeys: Record<PanelGroupItemLayoutId, string>;
33
+ }
34
+ export interface PanelGroupItemLayout extends Layout {
35
+ i: PanelGroupItemLayoutId;
68
36
  }
37
+ export declare type PanelGroupItemLayoutId = string;
69
38
  /**
70
39
  * Uniquely identifies an item in a PanelGroup.
71
40
  */
72
41
  export interface PanelGroupItemId {
73
42
  panelGroupId: PanelGroupId;
74
- itemIndex: number;
43
+ panelGroupItemLayoutId: PanelGroupItemLayoutId;
75
44
  }
76
45
  /**
77
46
  * Curried function for creating a PanelGroupSlice.
78
47
  */
79
- export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice & PanelEditorSlice, Middleware, [], PanelGroupSlice>;
48
+ export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice>;
49
+ export declare function convertLayoutsToPanelGroups(layouts: LayoutDefinition[]): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'>;
80
50
  //# sourceMappingURL=panel-group-slice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAsC,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC5G,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAExD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,iBAAiB,EAAE,YAAY,EAAE,CAAC;IAElC;;OAEG;IACH,wBAAwB,EAAE;QACxB,WAAW,EAAE,eAAe,CAAC,aAAa,CAAC,CAAC;QAC5C,iBAAiB,EAAE,eAAe,CAAC,mBAAmB,CAAC,CAAC;KACzD,CAAC;IAGF,kBAAkB,EAA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