@perses-dev/dashboards 0.14.0 → 0.16.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 (144) hide show
  1. package/dist/cjs/components/DashboardToolbar/DashboardToolbar.js +9 -3
  2. package/dist/cjs/components/DownloadButton/DownloadButton.js +109 -0
  3. package/dist/cjs/{utils → components/DownloadButton}/index.js +1 -1
  4. package/dist/cjs/{css/styles.js → components/GridLayout/GridContainer.js} +66 -39
  5. package/dist/cjs/components/GridLayout/GridLayout.js +51 -64
  6. package/dist/cjs/components/GridLayout/GridTitle.js +11 -14
  7. package/dist/cjs/components/Panel/Panel.js +4 -2
  8. package/dist/cjs/components/Panel/PanelHeader.js +52 -48
  9. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +23 -0
  10. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +15 -54
  11. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +27 -11
  12. package/dist/cjs/components/Variables/Variable.js +16 -4
  13. package/dist/cjs/components/Variables/VariableEditor.js +21 -1
  14. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +63 -7
  15. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +3 -3
  16. package/dist/cjs/components/Variables/VariableList.js +81 -17
  17. package/dist/cjs/components/index.js +1 -0
  18. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +2 -1
  19. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +68 -39
  20. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +40 -15
  21. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +5 -9
  22. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +16 -1
  23. package/dist/cjs/context/{TimeRangeProvider.js → TimeRangeProvider/TimeRangeProvider.js} +4 -4
  24. package/dist/cjs/{utils/component-ids.js → context/TimeRangeProvider/index.js} +12 -14
  25. package/dist/cjs/{utils/time-range-params.js → context/TimeRangeProvider/query-params.js} +11 -5
  26. package/dist/cjs/index.js +0 -1
  27. package/dist/cjs/test/testDashboard.js +1 -1
  28. package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -1
  29. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +6 -7
  30. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +16 -22
  31. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +1 -0
  32. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  33. package/dist/components/DashboardToolbar/DashboardToolbar.js +9 -3
  34. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  35. package/dist/components/DownloadButton/DownloadButton.d.ts +3 -0
  36. package/dist/components/DownloadButton/DownloadButton.d.ts.map +1 -0
  37. package/dist/components/DownloadButton/DownloadButton.js +60 -0
  38. package/dist/components/DownloadButton/DownloadButton.js.map +1 -0
  39. package/dist/components/DownloadButton/index.d.ts +2 -0
  40. package/dist/components/DownloadButton/index.d.ts.map +1 -0
  41. package/dist/{utils → components/DownloadButton}/index.js +1 -1
  42. package/dist/components/DownloadButton/index.js.map +1 -0
  43. package/dist/components/GridLayout/GridContainer.d.ts +6 -0
  44. package/dist/components/GridLayout/GridContainer.d.ts.map +1 -0
  45. package/dist/{css/styles.js → components/GridLayout/GridContainer.js} +65 -38
  46. package/dist/components/GridLayout/GridContainer.js.map +1 -0
  47. package/dist/components/GridLayout/GridLayout.d.ts +1 -2
  48. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  49. package/dist/components/GridLayout/GridLayout.js +53 -66
  50. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  51. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  52. package/dist/components/GridLayout/GridTitle.js +12 -15
  53. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  54. package/dist/components/Panel/Panel.d.ts.map +1 -1
  55. package/dist/components/Panel/Panel.js +4 -2
  56. package/dist/components/Panel/Panel.js.map +1 -1
  57. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  58. package/dist/components/Panel/PanelHeader.js +52 -48
  59. package/dist/components/Panel/PanelHeader.js.map +1 -1
  60. package/dist/components/PanelDrawer/PanelDrawer.test.js +23 -0
  61. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  62. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  63. package/dist/components/TimeRangeControls/TimeRangeControls.js +19 -58
  64. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  65. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +28 -12
  66. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  67. package/dist/components/Variables/Variable.js +16 -4
  68. package/dist/components/Variables/Variable.js.map +1 -1
  69. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  70. package/dist/components/Variables/VariableEditor.js +23 -3
  71. package/dist/components/Variables/VariableEditor.js.map +1 -1
  72. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
  73. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +25 -3
  74. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
  75. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +1 -1
  76. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -1
  77. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +3 -3
  78. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -1
  79. package/dist/components/Variables/VariableList.d.ts +5 -1
  80. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  81. package/dist/components/Variables/VariableList.js +43 -18
  82. package/dist/components/Variables/VariableList.js.map +1 -1
  83. package/dist/components/index.d.ts +1 -0
  84. package/dist/components/index.d.ts.map +1 -1
  85. package/dist/components/index.js +1 -0
  86. package/dist/components/index.js.map +1 -1
  87. package/dist/context/DashboardProvider/DashboardProvider.js +2 -1
  88. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  89. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -1
  90. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  91. package/dist/context/DashboardProvider/dashboard-provider-api.js +70 -41
  92. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  93. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  94. package/dist/context/DashboardProvider/panel-editor-slice.js +40 -15
  95. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  96. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
  97. package/dist/context/DashboardProvider/panel-group-editor-slice.js +5 -9
  98. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  99. package/dist/context/DashboardProvider/panel-group-slice.d.ts +9 -0
  100. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  101. package/dist/context/DashboardProvider/panel-group-slice.js +17 -0
  102. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  103. package/dist/context/{TimeRangeProvider.d.ts → TimeRangeProvider/TimeRangeProvider.d.ts} +2 -2
  104. package/dist/context/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -0
  105. package/dist/context/{TimeRangeProvider.js → TimeRangeProvider/TimeRangeProvider.js} +4 -4
  106. package/dist/context/TimeRangeProvider/TimeRangeProvider.js.map +1 -0
  107. package/dist/context/TimeRangeProvider/index.d.ts +3 -0
  108. package/dist/context/TimeRangeProvider/index.d.ts.map +1 -0
  109. package/dist/{utils/component-ids.js → context/TimeRangeProvider/index.js} +3 -14
  110. package/dist/context/TimeRangeProvider/index.js.map +1 -0
  111. package/dist/{utils/time-range-params.d.ts → context/TimeRangeProvider/query-params.d.ts} +3 -3
  112. package/dist/context/TimeRangeProvider/query-params.d.ts.map +1 -0
  113. package/dist/{utils/time-range-params.js → context/TimeRangeProvider/query-params.js} +13 -7
  114. package/dist/context/TimeRangeProvider/query-params.js.map +1 -0
  115. package/dist/index.d.ts +0 -1
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.js +0 -1
  118. package/dist/index.js.map +1 -1
  119. package/dist/test/testDashboard.js +1 -1
  120. package/dist/test/testDashboard.js.map +1 -1
  121. package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -0
  122. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  123. package/dist/views/ViewDashboard/DashboardApp.js +2 -1
  124. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  125. package/dist/views/ViewDashboard/ViewDashboard.d.ts +1 -0
  126. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  127. package/dist/views/ViewDashboard/ViewDashboard.js +6 -7
  128. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  129. package/dist/views/ViewDashboard/tests/panelGroups.test.js +16 -22
  130. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  131. package/package.json +4 -4
  132. package/dist/context/TimeRangeProvider.d.ts.map +0 -1
  133. package/dist/context/TimeRangeProvider.js.map +0 -1
  134. package/dist/css/styles.d.ts +0 -172
  135. package/dist/css/styles.d.ts.map +0 -1
  136. package/dist/css/styles.js.map +0 -1
  137. package/dist/utils/component-ids.d.ts +0 -8
  138. package/dist/utils/component-ids.d.ts.map +0 -1
  139. package/dist/utils/component-ids.js.map +0 -1
  140. package/dist/utils/index.d.ts +0 -2
  141. package/dist/utils/index.d.ts.map +0 -1
  142. package/dist/utils/index.js.map +0 -1
  143. package/dist/utils/time-range-params.d.ts.map +0 -1
  144. package/dist/utils/time-range-params.js.map +0 -1
@@ -10,36 +10,42 @@
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 { useMemo } from 'react';
13
+ import { useCallback, useMemo } from 'react';
14
14
  import { useDashboardStore } from './DashboardProvider';
15
+ const selectEditMode = ({ isEditMode , setEditMode })=>({
16
+ isEditMode,
17
+ setEditMode
18
+ });
15
19
  export function useEditMode() {
16
- return useDashboardStore(({ isEditMode , setEditMode })=>({
17
- isEditMode,
18
- setEditMode
19
- }));
20
+ return useDashboardStore(selectEditMode);
20
21
  }
22
+ const selectDashboardActions = ({ setDashboard , openAddPanelGroup , openAddPanel })=>({
23
+ setDashboard,
24
+ openAddPanelGroup,
25
+ openAddPanel
26
+ });
21
27
  /**
22
28
  * Returns actions that can be performed on the current dashboard.
23
29
  */ export function useDashboardActions() {
24
- const setDashboard = useDashboardStore((store)=>store.setDashboard);
25
- const openAddPanelGroup = useDashboardStore((store)=>store.openAddPanelGroup);
26
- const openAddPanel = useDashboardStore((store)=>store.openAddPanel);
30
+ const { setDashboard , openAddPanelGroup , openAddPanel } = useDashboardStore(selectDashboardActions);
27
31
  return {
28
32
  setDashboard,
29
- openAddPanelGroup,
30
- openAddPanel: ()=>openAddPanel(undefined)
33
+ openAddPanelGroup: ()=>openAddPanelGroup(),
34
+ openAddPanel: ()=>openAddPanel()
31
35
  };
32
36
  }
37
+ const selectPanelGroupOrder = (state)=>state.panelGroupOrder;
33
38
  /**
34
39
  * Returns an array of PanelGroupIds in the order they appear in the dashboard.
35
40
  */ export function usePanelGroupIds() {
36
- return useDashboardStore((store)=>store.panelGroupOrder);
41
+ return useDashboardStore(selectPanelGroupOrder);
37
42
  }
43
+ const selectPanelGroups = (state)=>state.panelGroups;
38
44
  /**
39
45
  * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.
40
46
  */ export function useListPanelGroups() {
41
47
  const panelGroupIds = usePanelGroupIds();
42
- const panelGroups = useDashboardStore((store)=>store.panelGroups);
48
+ const panelGroups = useDashboardStore(selectPanelGroups);
43
49
  return useMemo(()=>{
44
50
  return panelGroupIds.map((id)=>{
45
51
  const group = panelGroups[id];
@@ -56,20 +62,25 @@ export function useEditMode() {
56
62
  /**
57
63
  * Gets a specific panel group by its id. Throws if the panel group does not exist.
58
64
  */ export function usePanelGroup(panelGroupId) {
59
- const panelGroup = useDashboardStore((store)=>store.panelGroups[panelGroupId]);
65
+ const panelGroup = useDashboardStore(useCallback((state)=>state.panelGroups[panelGroupId], [
66
+ panelGroupId
67
+ ]));
60
68
  if (panelGroup === undefined) {
61
69
  throw new Error(`Panel group with Id ${panelGroupId} was not found`);
62
70
  }
63
71
  return panelGroup;
64
72
  }
73
+ const selectPanelGroupActions = ({ openEditPanelGroup , deletePanelGroup , openAddPanel , updatePanelGroupLayouts })=>({
74
+ openEditPanelGroup,
75
+ deletePanelGroup,
76
+ openAddPanel,
77
+ updatePanelGroupLayouts
78
+ });
65
79
  /**
66
80
  * Returns actions that can be performed on the given panel group.
67
81
  */ export function usePanelGroupActions(panelGroupId) {
68
82
  const { moveUp , moveDown } = useMovePanelGroup(panelGroupId);
69
- const openEditPanelGroup = useDashboardStore((store)=>store.openEditPanelGroup);
70
- const deletePanelGroup = useDashboardStore((store)=>store.openDeletePanelGroupDialog);
71
- const openAddPanel = useDashboardStore((store)=>store.openAddPanel);
72
- const updatePanelGroupLayouts = useDashboardStore((store)=>store.updatePanelGroupLayouts);
83
+ const { openEditPanelGroup , deletePanelGroup , openAddPanel , updatePanelGroupLayouts } = useDashboardStore(selectPanelGroupActions);
73
84
  return {
74
85
  openEditPanelGroup: ()=>openEditPanelGroup(panelGroupId),
75
86
  deletePanelGroup: ()=>deletePanelGroup(panelGroupId),
@@ -79,13 +90,17 @@ export function useEditMode() {
79
90
  updatePanelGroupLayouts: (itemLayouts)=>updatePanelGroupLayouts(panelGroupId, itemLayouts)
80
91
  };
81
92
  }
93
+ const selectSwapPanelGroups = (state)=>state.swapPanelGroups;
94
+ const selectPanelGroupsLength = (state)=>state.panelGroupOrder.length;
82
95
  /**
83
96
  * Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be
84
97
  * moved in that direction.
85
98
  */ function useMovePanelGroup(panelGroupId) {
86
- const currentIndex = useDashboardStore((store)=>store.panelGroupOrder.findIndex((id)=>id === panelGroupId));
87
- const panelGroupsLength = useDashboardStore((store)=>store.panelGroupOrder.length);
88
- const swapPanelGroups = useDashboardStore((store)=>store.swapPanelGroups);
99
+ const currentIndex = useDashboardStore(useCallback((store)=>store.panelGroupOrder.findIndex((id)=>id === panelGroupId), [
100
+ panelGroupId
101
+ ]));
102
+ const panelGroupsLength = useDashboardStore(selectPanelGroupsLength);
103
+ const swapPanelGroups = useDashboardStore(selectSwapPanelGroups);
89
104
  if (currentIndex < 0) {
90
105
  throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);
91
106
  }
@@ -96,66 +111,80 @@ export function useEditMode() {
96
111
  moveDown: currentIndex < panelGroupsLength - 1 ? moveDown : undefined
97
112
  };
98
113
  }
114
+ const selectPanelGroupEditor = (state)=>state.panelGroupEditor;
99
115
  /**
100
116
  * Gets the Panel Group editor state.
101
117
  */ export function usePanelGroupEditor() {
102
- return useDashboardStore((store)=>store.panelGroupEditor);
118
+ return useDashboardStore(selectPanelGroupEditor);
103
119
  }
120
+ const selectDeletePanelGroupDialog = ({ deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , deletePanelGroup })=>({
121
+ deletePanelGroupDialog,
122
+ openDeletePanelGroupDialog,
123
+ closeDeletePanelGroupDialog,
124
+ deletePanelGroup
125
+ });
104
126
  /**
105
127
  * Gets the Delete Panel Group dialog state.
106
128
  */ export function useDeletePanelGroupDialog() {
107
- return useDashboardStore(({ deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , deletePanelGroup })=>({
108
- deletePanelGroupDialog,
109
- openDeletePanelGroupDialog,
110
- closeDeletePanelGroupDialog,
111
- deletePanelGroup
112
- }));
129
+ const { deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , deletePanelGroup } = useDashboardStore(selectDeletePanelGroupDialog);
130
+ return {
131
+ deletePanelGroupDialog,
132
+ deletePanelGroup,
133
+ openDeletePanelGroupDialog,
134
+ closeDeletePanelGroupDialog: ()=>closeDeletePanelGroupDialog()
135
+ };
113
136
  }
114
137
  /**
115
138
  * Gets an individual panel in the store. Throws if the panel can't be found.
116
139
  */ export function usePanel(panelGroupItemId) {
117
140
  const { panelGroupId , panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;
118
- const panel = useDashboardStore((store)=>{
141
+ const panel = useDashboardStore(useCallback((store)=>{
119
142
  var ref;
120
143
  const panelKey = (ref = store.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.itemPanelKeys[panelGroupLayoutId];
121
144
  if (panelKey === undefined) return;
122
145
  return store.panels[panelKey];
123
- });
146
+ }, [
147
+ panelGroupId,
148
+ panelGroupLayoutId
149
+ ]));
124
150
  if (panel === undefined) {
125
151
  throw new Error(`Could not find panel for Id ${panelGroupItemId}`);
126
152
  }
127
153
  return panel;
128
154
  }
155
+ const selectPanelActions = ({ openEditPanel , openDeletePanelDialog })=>({
156
+ openEditPanel,
157
+ openDeletePanelDialog
158
+ });
129
159
  /**
130
160
  * Returns actions that can be performed on the given Panel.
131
161
  */ export function usePanelActions(panelGroupItemId) {
132
- const openEditPanel = useDashboardStore((store)=>store.openEditPanel);
133
- const openDeletePanelDialog = useDashboardStore((store)=>store.openDeletePanelDialog);
162
+ const { openEditPanel , openDeletePanelDialog } = useDashboardStore(selectPanelActions);
134
163
  return {
135
164
  openEditPanel: ()=>openEditPanel(panelGroupItemId),
136
165
  openDeletePanelDialog: ()=>openDeletePanelDialog(panelGroupItemId)
137
166
  };
138
167
  }
168
+ const selectPanelEditor = (state)=>state.panelEditor;
139
169
  /**
140
170
  * Gets the state for the Panel Editor.
141
171
  */ export function usePanelEditor() {
142
- return useDashboardStore((store)=>store.panelEditor);
172
+ return useDashboardStore(selectPanelEditor);
143
173
  }
174
+ const selectDeletePanelDialog = ({ deletePanelDialog , deletePanel , closeDeletePanelDialog })=>({
175
+ deletePanelDialog,
176
+ deletePanel,
177
+ closeDeletePanelDialog
178
+ });
144
179
  /**
145
180
  * Gets the state for the Delete Panel dialog.
146
181
  */ export function useDeletePanelDialog() {
147
- const deletePanelDialog = useDashboardStore((store)=>store.deletePanelDialog);
148
182
  // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself
149
- const deletePanel = useDashboardStore((store)=>store.deletePanel);
150
- const closeDeletePanelDialog = useDashboardStore((store)=>store.closeDeletePanelDialog);
151
- return {
152
- deletePanelDialog,
153
- deletePanel,
154
- closeDeletePanelDialog
155
- };
183
+ return useDashboardStore(selectDeletePanelDialog);
156
184
  }
185
+ const selectDefaultTimeRange = (state)=>state.defaultTimeRange;
157
186
  export function useDefaultTimeRange() {
158
- return useDashboardStore((state)=>state.defaultTimeRange);
187
+ return useDashboardStore(selectDefaultTimeRange);
159
188
  }
160
189
 
161
190
  //# sourceMappingURL=dashboard-provider-api.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/dashboard-provider-api.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 { useMemo } from 'react';\nimport { useDashboardStore } from './DashboardProvider';\nimport { PanelGroupItemId, PanelGroupId, PanelGroupItemLayout } from './panel-group-slice';\n\nexport function useEditMode() {\n return useDashboardStore(({ isEditMode, setEditMode }) => ({ isEditMode, setEditMode }));\n}\n\n/**\n * Returns actions that can be performed on the current dashboard.\n */\nexport function useDashboardActions() {\n const setDashboard = useDashboardStore((store) => store.setDashboard);\n const openAddPanelGroup = useDashboardStore((store) => store.openAddPanelGroup);\n const openAddPanel = useDashboardStore((store) => store.openAddPanel);\n\n return {\n setDashboard,\n openAddPanelGroup,\n openAddPanel: () => openAddPanel(undefined),\n };\n}\n\n/**\n * Returns an array of PanelGroupIds in the order they appear in the dashboard.\n */\nexport function usePanelGroupIds() {\n return useDashboardStore((store) => store.panelGroupOrder);\n}\n\n/**\n * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.\n */\nexport function useListPanelGroups() {\n const panelGroupIds = usePanelGroupIds();\n const panelGroups = useDashboardStore((store) => store.panelGroups);\n return useMemo(() => {\n return panelGroupIds.map((id) => {\n const group = panelGroups[id];\n if (group === undefined) {\n throw new Error(`Invalid panel group Id found ${id}`);\n }\n return group;\n });\n }, [panelGroupIds, panelGroups]);\n}\n\n/**\n * Gets a specific panel group by its id. Throws if the panel group does not exist.\n */\nexport function usePanelGroup(panelGroupId: PanelGroupId) {\n const panelGroup = useDashboardStore((store) => store.panelGroups[panelGroupId]);\n if (panelGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} was not found`);\n }\n return panelGroup;\n}\n\n/**\n * Returns actions that can be performed on the given panel group.\n */\nexport function usePanelGroupActions(panelGroupId: PanelGroupId) {\n const { moveUp, moveDown } = useMovePanelGroup(panelGroupId);\n const openEditPanelGroup = useDashboardStore((store) => store.openEditPanelGroup);\n const deletePanelGroup = useDashboardStore((store) => store.openDeletePanelGroupDialog);\n const openAddPanel = useDashboardStore((store) => store.openAddPanel);\n const updatePanelGroupLayouts = useDashboardStore((store) => store.updatePanelGroupLayouts);\n\n return {\n openEditPanelGroup: () => openEditPanelGroup(panelGroupId),\n deletePanelGroup: () => deletePanelGroup(panelGroupId),\n openAddPanel: () => openAddPanel(panelGroupId),\n moveUp,\n moveDown,\n updatePanelGroupLayouts: (itemLayouts: PanelGroupItemLayout[]) =>\n updatePanelGroupLayouts(panelGroupId, itemLayouts),\n };\n}\n\n/**\n * Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be\n * moved in that direction.\n */\nfunction useMovePanelGroup(panelGroupId: PanelGroupId) {\n const currentIndex = useDashboardStore((store) => store.panelGroupOrder.findIndex((id) => id === panelGroupId));\n const panelGroupsLength = useDashboardStore((store) => store.panelGroupOrder.length);\n const swapPanelGroups = useDashboardStore((store) => store.swapPanelGroups);\n\n if (currentIndex < 0) {\n throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);\n }\n\n const moveUp = () => swapPanelGroups(currentIndex, currentIndex - 1);\n const moveDown = () => swapPanelGroups(currentIndex, currentIndex + 1);\n return {\n moveUp: currentIndex > 0 ? moveUp : undefined,\n moveDown: currentIndex < panelGroupsLength - 1 ? moveDown : undefined,\n };\n}\n\n/**\n * Gets the Panel Group editor state.\n */\nexport function usePanelGroupEditor() {\n return useDashboardStore((store) => store.panelGroupEditor);\n}\n\n/**\n * Gets the Delete Panel Group dialog state.\n */\nexport function useDeletePanelGroupDialog() {\n return useDashboardStore(\n ({ deletePanelGroupDialog, openDeletePanelGroupDialog, closeDeletePanelGroupDialog, deletePanelGroup }) => ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n })\n );\n}\n\n/**\n * Gets an individual panel in the store. Throws if the panel can't be found.\n */\nexport function usePanel(panelGroupItemId: PanelGroupItemId) {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n\n const panel = useDashboardStore((store) => {\n const panelKey = store.panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) return;\n return store.panels[panelKey];\n });\n\n if (panel === undefined) {\n throw new Error(`Could not find panel for Id ${panelGroupItemId}`);\n }\n return panel;\n}\n\n/**\n * Returns actions that can be performed on the given Panel.\n */\nexport function usePanelActions(panelGroupItemId: PanelGroupItemId) {\n const openEditPanel = useDashboardStore((store) => store.openEditPanel);\n const openDeletePanelDialog = useDashboardStore((store) => store.openDeletePanelDialog);\n return {\n openEditPanel: () => openEditPanel(panelGroupItemId),\n openDeletePanelDialog: () => openDeletePanelDialog(panelGroupItemId),\n };\n}\n\n/**\n * Gets the state for the Panel Editor.\n */\nexport function usePanelEditor() {\n return useDashboardStore((store) => store.panelEditor);\n}\n\n/**\n * Gets the state for the Delete Panel dialog.\n */\nexport function useDeletePanelDialog() {\n const deletePanelDialog = useDashboardStore((store) => store.deletePanelDialog);\n // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself\n const deletePanel = useDashboardStore((store) => store.deletePanel);\n const closeDeletePanelDialog = useDashboardStore((store) => store.closeDeletePanelDialog);\n\n return {\n deletePanelDialog,\n deletePanel,\n closeDeletePanelDialog,\n };\n}\n\nexport function useDefaultTimeRange() {\n return useDashboardStore((state) => state.defaultTimeRange);\n}\n"],"names":["useMemo","useDashboardStore","useEditMode","isEditMode","setEditMode","useDashboardActions","setDashboard","store","openAddPanelGroup","openAddPanel","undefined","usePanelGroupIds","panelGroupOrder","useListPanelGroups","panelGroupIds","panelGroups","map","id","group","Error","usePanelGroup","panelGroupId","panelGroup","usePanelGroupActions","moveUp","moveDown","useMovePanelGroup","openEditPanelGroup","deletePanelGroup","openDeletePanelGroupDialog","updatePanelGroupLayouts","itemLayouts","currentIndex","findIndex","panelGroupsLength","length","swapPanelGroups","usePanelGroupEditor","panelGroupEditor","useDeletePanelGroupDialog","deletePanelGroupDialog","closeDeletePanelGroupDialog","usePanel","panelGroupItemId","panelGroupItemLayoutId","panelGroupLayoutId","panel","panelKey","itemPanelKeys","panels","usePanelActions","openEditPanel","openDeletePanelDialog","usePanelEditor","panelEditor","useDeletePanelDialog","deletePanelDialog","deletePanel","closeDeletePanelDialog","useDefaultTimeRange","state","defaultTimeRange"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,iBAAiB,QAAQ,qBAAqB,CAAC;AAGxD,OAAO,SAASC,WAAW,GAAG;IAC5B,OA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BAAgB,CAAC;KACrE,CAAC;AACJ,CAAC;AAED;;CAEC,GACD,OAAO,SAASU,cAAc,GAAG;IAC/B,OAAOpD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAAC+C,WAAW,CAAC,CAAC;AACzD,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,oBAAoB,GAAG;IACrC,MAAMC,iBAAiB,GAAGvD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACiD,iBAAiB,CAAC,AAAC;IAChF,0FAA0F;IAC1F,MAAMC,WAAW,GAAGxD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACkD,WAAW,CAAC,AAAC;IACpE,MAAMC,sBAAsB,GAAGzD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACmD,sBAAsB,CAAC,AAAC;IAE1F,OAAO;QACLF,iBAAiB;QACjBC,WAAW;QACXC,sBAAsB;KACvB,CAAC;AACJ,CAAC;AAED,OAAO,SAASC,mBAAmB,GAAG;IACpC,OAAO1D,iBAAiB,CAAC,CAAC2D,KAAK,GAAKA,KAAK,CAACC,gBAAgB,CAAC,CAAC;AAC9D,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/dashboard-provider-api.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 { useCallback, useMemo } from 'react';\nimport { DashboardStoreState, useDashboardStore } from './DashboardProvider';\nimport { PanelGroupItemId, PanelGroupId, PanelGroupItemLayout } from './panel-group-slice';\n\nconst selectEditMode = ({ isEditMode, setEditMode }: DashboardStoreState) => ({ isEditMode, setEditMode });\nexport function useEditMode() {\n return useDashboardStore(selectEditMode);\n}\n\nconst selectDashboardActions = ({ setDashboard, openAddPanelGroup, openAddPanel }: DashboardStoreState) => ({\n setDashboard,\n openAddPanelGroup,\n openAddPanel,\n});\n/**\n * Returns actions that can be performed on the current dashboard.\n */\nexport function useDashboardActions() {\n const { setDashboard, openAddPanelGroup, openAddPanel } = useDashboardStore(selectDashboardActions);\n return {\n setDashboard,\n openAddPanelGroup: () => openAddPanelGroup(),\n openAddPanel: () => openAddPanel(),\n };\n}\n\nconst selectPanelGroupOrder = (state: DashboardStoreState) => state.panelGroupOrder;\n/**\n * Returns an array of PanelGroupIds in the order they appear in the dashboard.\n */\nexport function usePanelGroupIds() {\n return useDashboardStore(selectPanelGroupOrder);\n}\n\nconst selectPanelGroups = (state: DashboardStoreState) => state.panelGroups;\n/**\n * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.\n */\nexport function useListPanelGroups() {\n const panelGroupIds = usePanelGroupIds();\n const panelGroups = useDashboardStore(selectPanelGroups);\n return useMemo(() => {\n return panelGroupIds.map((id) => {\n const group = panelGroups[id];\n if (group === undefined) {\n throw new Error(`Invalid panel group Id found ${id}`);\n }\n return group;\n });\n }, [panelGroupIds, panelGroups]);\n}\n\n/**\n * Gets a specific panel group by its id. Throws if the panel group does not exist.\n */\nexport function usePanelGroup(panelGroupId: PanelGroupId) {\n const panelGroup = useDashboardStore(useCallback((state) => state.panelGroups[panelGroupId], [panelGroupId]));\n if (panelGroup === undefined) {\n throw new Error(`Panel group with Id ${panelGroupId} was not found`);\n }\n return panelGroup;\n}\n\nconst selectPanelGroupActions = ({\n openEditPanelGroup,\n deletePanelGroup,\n openAddPanel,\n updatePanelGroupLayouts,\n}: DashboardStoreState) => ({\n openEditPanelGroup,\n deletePanelGroup,\n openAddPanel,\n updatePanelGroupLayouts,\n});\n/**\n * Returns actions that can be performed on the given panel group.\n */\nexport function usePanelGroupActions(panelGroupId: PanelGroupId) {\n const { moveUp, moveDown } = useMovePanelGroup(panelGroupId);\n const { openEditPanelGroup, deletePanelGroup, openAddPanel, updatePanelGroupLayouts } =\n useDashboardStore(selectPanelGroupActions);\n\n return {\n openEditPanelGroup: () => openEditPanelGroup(panelGroupId),\n deletePanelGroup: () => deletePanelGroup(panelGroupId),\n openAddPanel: () => openAddPanel(panelGroupId),\n moveUp,\n moveDown,\n updatePanelGroupLayouts: (itemLayouts: PanelGroupItemLayout[]) =>\n updatePanelGroupLayouts(panelGroupId, itemLayouts),\n };\n}\n\nconst selectSwapPanelGroups = (state: DashboardStoreState) => state.swapPanelGroups;\nconst selectPanelGroupsLength = (state: DashboardStoreState) => state.panelGroupOrder.length;\n/**\n * Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be\n * moved in that direction.\n */\nfunction useMovePanelGroup(panelGroupId: PanelGroupId) {\n const currentIndex = useDashboardStore(\n useCallback((store) => store.panelGroupOrder.findIndex((id) => id === panelGroupId), [panelGroupId])\n );\n const panelGroupsLength = useDashboardStore(selectPanelGroupsLength);\n const swapPanelGroups = useDashboardStore(selectSwapPanelGroups);\n\n if (currentIndex < 0) {\n throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);\n }\n\n const moveUp = () => swapPanelGroups(currentIndex, currentIndex - 1);\n const moveDown = () => swapPanelGroups(currentIndex, currentIndex + 1);\n return {\n moveUp: currentIndex > 0 ? moveUp : undefined,\n moveDown: currentIndex < panelGroupsLength - 1 ? moveDown : undefined,\n };\n}\n\nconst selectPanelGroupEditor = (state: DashboardStoreState) => state.panelGroupEditor;\n/**\n * Gets the Panel Group editor state.\n */\nexport function usePanelGroupEditor() {\n return useDashboardStore(selectPanelGroupEditor);\n}\n\nconst selectDeletePanelGroupDialog = ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n}: DashboardStoreState) => ({\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n deletePanelGroup,\n});\n/**\n * Gets the Delete Panel Group dialog state.\n */\nexport function useDeletePanelGroupDialog() {\n const { deletePanelGroupDialog, openDeletePanelGroupDialog, closeDeletePanelGroupDialog, deletePanelGroup } =\n useDashboardStore(selectDeletePanelGroupDialog);\n return {\n deletePanelGroupDialog,\n deletePanelGroup,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog: () => closeDeletePanelGroupDialog(),\n };\n}\n\n/**\n * Gets an individual panel in the store. Throws if the panel can't be found.\n */\nexport function usePanel(panelGroupItemId: PanelGroupItemId) {\n const { panelGroupId, panelGroupItemLayoutId: panelGroupLayoutId } = panelGroupItemId;\n const panel = useDashboardStore(\n useCallback(\n (store) => {\n const panelKey = store.panelGroups[panelGroupId]?.itemPanelKeys[panelGroupLayoutId];\n if (panelKey === undefined) return;\n return store.panels[panelKey];\n },\n [panelGroupId, panelGroupLayoutId]\n )\n );\n\n if (panel === undefined) {\n throw new Error(`Could not find panel for Id ${panelGroupItemId}`);\n }\n return panel;\n}\n\nconst selectPanelActions = ({ openEditPanel, openDeletePanelDialog }: DashboardStoreState) => ({\n openEditPanel,\n openDeletePanelDialog,\n});\n/**\n * Returns actions that can be performed on the given Panel.\n */\nexport function usePanelActions(panelGroupItemId: PanelGroupItemId) {\n const { openEditPanel, openDeletePanelDialog } = useDashboardStore(selectPanelActions);\n return {\n openEditPanel: () => openEditPanel(panelGroupItemId),\n openDeletePanelDialog: () => openDeletePanelDialog(panelGroupItemId),\n };\n}\n\nconst selectPanelEditor = (state: DashboardStoreState) => state.panelEditor;\n/**\n * Gets the state for the Panel Editor.\n */\nexport function usePanelEditor() {\n return useDashboardStore(selectPanelEditor);\n}\n\nconst selectDeletePanelDialog = ({ deletePanelDialog, deletePanel, closeDeletePanelDialog }: DashboardStoreState) => ({\n deletePanelDialog,\n deletePanel,\n closeDeletePanelDialog,\n});\n\n/**\n * Gets the state for the Delete Panel dialog.\n */\nexport function useDeletePanelDialog() {\n // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself\n return useDashboardStore(selectDeletePanelDialog);\n}\n\nconst selectDefaultTimeRange = (state: DashboardStoreState) => state.defaultTimeRange;\nexport function useDefaultTimeRange() {\n return useDashboardStore(selectDefaultTimeRange);\n}\n"],"names":["useCallback","useMemo","useDashboardStore","selectEditMode","isEditMode","setEditMode","useEditMode","selectDashboardActions","setDashboard","openAddPanelGroup","openAddPanel","useDashboardActions","selectPanelGroupOrder","state","panelGroupOrder","usePanelGroupIds","selectPanelGroups","panelGroups","useListPanelGroups","panelGroupIds","map","id","group","undefined","Error","usePanelGroup","panelGroupId","panelGroup","selectPanelGroupActions","openEditPanelGroup","deletePanelGroup","updatePanelGroupLayouts","usePanelGroupActions","moveUp","moveDown","useMovePanelGroup","itemLayouts","selectSwapPanelGroups","swapPanelGroups","selectPanelGroupsLength","length","currentIndex","store","findIndex","panelGroupsLength","selectPanelGroupEditor","panelGroupEditor","usePanelGroupEditor","selectDeletePanelGroupDialog","deletePanelGroupDialog","openDeletePanelGroupDialog","closeDeletePanelGroupDialog","useDeletePanelGroupDialog","usePanel","panelGroupItemId","panelGroupItemLayoutId","panelGroupLayoutId","panel","panelKey","itemPanelKeys","panels","selectPanelActions","openEditPanel","openDeletePanelDialog","usePanelActions","selectPanelEditor","panelEditor","usePanelEditor","selectDeletePanelDialog","deletePanelDialog","deletePanel","closeDeletePanelDialog","useDeletePanelDialog","selectDefaultTimeRange","defaultTimeRange","useDefaultTimeRange"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,WAAW,EAAEC,OAAO,QAAQ,OAAO,CAAC;AAC7C,SAA8BC,iBAAiB,QAAQ,qBAAqB,CAAC;AAG7E,MAAMC,cAAc,GAAG,CAAC,EAAEC,UAAU,CAAA,EAAEC,WAAW,C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B,CAAC,CAAC;AACpD,CAAC;AAED,MAAMK,sBAAsB,GAAG,CAAC5D,KAA0B,GAAKA,KAAK,CAAC6D,gBAAgB,AAAC;AACtF,OAAO,SAASC,mBAAmB,GAAG;IACpC,OAAOzE,iBAAiB,CAACuE,sBAAsB,CAAC,CAAC;AACnD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"panel-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAmB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,YAAY,EAGb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,aAAa,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE5D;;OAEG;IACH,YAAY,EAAE,CAAC,YAAY,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,CA+IA"}
1
+ {"version":3,"file":"panel-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editor-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAmB,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,YAAY,EAKb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,aAAa,EAAE,CAAC,gBAAgB,EAAE,gBAAgB,KAAK,IAAI,CAAC;IAE5D;;OAEG;IACH,YAAY,EAAE,CAAC,YAAY,CAAC,EAAE,YAAY,KAAK,IAAI,CAAC;CACrD;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,YAAY,CAAC;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,IAAI,YAAY,CAEpD,gBAAgB,GAAG,UAAU,GAAG,eAAe,EAC/C,UAAU,EACV;CAAE,EACF,gBAAgB,CACjB,CAyJA"}
@@ -12,6 +12,7 @@
12
12
  // limitations under the License.
13
13
  import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
14
14
  import { generateId } from './common';
15
+ import { addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';
15
16
  /**
16
17
  * Curried function for creating the PanelEditorSlice.
17
18
  */ export function createPanelEditorSlice() {
@@ -45,14 +46,14 @@ import { generateId } from './common';
45
46
  },
46
47
  applyChanges: (next)=>{
47
48
  const panelDefinititon = createPanelDefinitionFromEditorValues(next);
48
- set((draft)=>{
49
- draft.panels[panelKey] = panelDefinititon;
49
+ set((state)=>{
50
+ state.panels[panelKey] = panelDefinititon;
50
51
  // If the panel didn't change groups, nothing else to do
51
52
  if (next.groupId === panelGroupId) {
52
53
  return;
53
54
  }
54
55
  // Move panel to the new group
55
- const existingGroup = draft.panelGroups[panelGroupId];
56
+ const existingGroup = state.panelGroups[panelGroupId];
56
57
  if (existingGroup === undefined) {
57
58
  throw new Error(`Missing panel group ${panelGroupId}`);
58
59
  }
@@ -66,7 +67,7 @@ import { generateId } from './common';
66
67
  existingGroup.itemLayouts.splice(existingLayoutIdx, 1);
67
68
  delete existingGroup.itemPanelKeys[panelGroupLayoutId];
68
69
  // Add item to the end of the new group
69
- const newGroup = draft.panelGroups[next.groupId];
70
+ const newGroup = state.panelGroups[next.groupId];
70
71
  if (newGroup === undefined) {
71
72
  throw new Error(`Could not find new group ${next.groupId}`);
72
73
  }
@@ -92,13 +93,13 @@ import { generateId } from './common';
92
93
  });
93
94
  },
94
95
  openAddPanel (panelGroupId) {
95
- // If a panel group isn't supplied, add to the first group
96
+ // If a panel group isn't supplied, add to the first group or create a group if there aren't any
97
+ let newGroup = undefined;
98
+ panelGroupId !== null && panelGroupId !== void 0 ? panelGroupId : panelGroupId = get().panelGroupOrder[0];
96
99
  if (panelGroupId === undefined) {
97
- const firstGroupId = get().panelGroupOrder[0];
98
- if (firstGroupId === undefined) {
99
- throw new Error('No panel groups to add a panel to');
100
- }
101
- panelGroupId = firstGroupId;
100
+ newGroup = createEmptyPanelGroup();
101
+ newGroup.title = 'Panel Group';
102
+ panelGroupId = newGroup.id;
102
103
  }
103
104
  const editorState = {
104
105
  mode: 'Add',
@@ -113,12 +114,17 @@ import { generateId } from './common';
113
114
  },
114
115
  applyChanges: (next)=>{
115
116
  const panelDef = createPanelDefinitionFromEditorValues(next);
116
- const panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);
117
- set((draft)=>{
117
+ const uniquePanelKeys = getUniquePanelKeys(get().panels);
118
+ let panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);
119
+ // append count if panel key already exists
120
+ if (uniquePanelKeys[panelKey]) {
121
+ panelKey += `-${uniquePanelKeys[panelKey]}`;
122
+ }
123
+ set((state)=>{
118
124
  // Add a panel
119
- draft.panels[panelKey] = panelDef;
125
+ state.panels[panelKey] = panelDef;
120
126
  // Also add a panel group item referencing the panel
121
- const group = draft.panelGroups[next.groupId];
127
+ const group = state.panelGroups[next.groupId];
122
128
  if (group === undefined) {
123
129
  throw new Error(`Missing panel group ${next.groupId}`);
124
130
  }
@@ -139,8 +145,12 @@ import { generateId } from './common';
139
145
  });
140
146
  }
141
147
  };
142
- // Open the editor with the new state
143
148
  set((state)=>{
149
+ // Add the new panel group if one was created for the panel
150
+ if (newGroup !== undefined) {
151
+ addPanelGroup(state, newGroup);
152
+ }
153
+ // Open the editor with the new state
144
154
  state.panelEditor = editorState;
145
155
  });
146
156
  }
@@ -174,5 +184,20 @@ function getYForNewRow(group) {
174
184
  }
175
185
  return newRowY;
176
186
  }
187
+ // Find all the unique panel keys
188
+ // ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name
189
+ function getUniquePanelKeys(panels) {
190
+ const uniquePanelKeys = {};
191
+ Object.keys(panels).forEach((panelKey)=>{
192
+ const key = panelKey.replace(/-([0-9]+)/, '');
193
+ const count = uniquePanelKeys[key];
194
+ if (count) {
195
+ uniquePanelKeys[key] = count + 1;
196
+ } else {
197
+ uniquePanelKeys[key] = 1;
198
+ }
199
+ });
200
+ return uniquePanelKeys;
201
+ }
177
202
 
178
203
  //# sourceMappingURL=panel-editor-slice.js.map
@@ -1 +1 @@
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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AAC;AACjB,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 addPanelGroup,\n createEmptyPanelGroup,\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((state) => {\n state.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 = state.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 = state.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 or create a group if there aren't any\n let newGroup: PanelGroupDefinition | undefined = undefined;\n panelGroupId ??= get().panelGroupOrder[0];\n if (panelGroupId === undefined) {\n newGroup = createEmptyPanelGroup();\n newGroup.title = 'Panel Group';\n panelGroupId = newGroup.id;\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 uniquePanelKeys = getUniquePanelKeys(get().panels);\n let panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);\n // append count if panel key already exists\n if (uniquePanelKeys[panelKey]) {\n panelKey += `-${uniquePanelKeys[panelKey]}`;\n }\n set((state) => {\n // Add a panel\n state.panels[panelKey] = panelDef;\n\n // Also add a panel group item referencing the panel\n const group = state.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 set((state) => {\n // Add the new panel group if one was created for the panel\n if (newGroup !== undefined) {\n addPanelGroup(state, newGroup);\n }\n\n // Open the editor with the new 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\n// Find all the unique panel keys\n// ex: cpu, cpu-1, cpu-2 count as the same panel key since these panels have the same name\nfunction getUniquePanelKeys(panels: Record<string, PanelDefinition>): Record<string, number> {\n const uniquePanelKeys: Record<string, number> = {};\n Object.keys(panels).forEach((panelKey) => {\n const key = panelKey.replace(/-([0-9]+)/, '');\n const count = uniquePanelKeys[key];\n if (count) {\n uniquePanelKeys[key] = count + 1;\n } else {\n uniquePanelKeys[key] = 1;\n }\n });\n return uniquePanelKeys;\n}\n"],"names":["removeWhiteSpacesAndSpecialCharacters","generateId","addPanelGroup","createEmptyPanelGroup","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","state","existingGroup","existingLayoutIdx","itemLayouts","findIndex","layout","i","existingLayout","existingPanelKey","splice","newGroup","push","x","y","getYForNewRow","w","h","close","openAddPanel","panelGroupOrder","title","id","panelDef","uniquePanelKeys","getUniquePanelKeys","group","toString","editorValues","newRowY","itemMaxY","Object","keys","forEach","key","replace","count"],"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;AAClD,SAMEC,aAAa,EACbC,qBAAqB,QAChB,qBAAqB,CAAC;AAwD7B;;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,cAAzBF,GAAyB,WAAe,GAAxCA,KAAAA,CAAwC,GAAxCA,GAAyB,CAAEM,aAAa,CAACF,kBAAkB,CAAC,AAAC;gBAC9E,IAAIC,QAAQ,KAAKR,SAAS,EAAE;oBAC1B,MAAM,IAAIU,KAAK,CAAC,CAAC,gCAAgC,EAAER,gBAAgB,CAAC,CAAC,CAAC,CAAC;gBACzE,CAAC;gBAED,yBAAyB;gBACzB,MAAMS,WAAW,GAAGP,MAAM,CAACI,QAAQ,CAAC,AAAC;gBACrC,IAAIG,WAAW,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TZ,eAAe,CAACU,GAAG,CAAC,GAAGE,KAAK,GAAG,CAAC,CAAC;QACnC,OAAO;YACLZ,eAAe,CAACU,GAAG,CAAC,GAAG,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC,CAAC,CAAC;IACH,OAAOV,eAAe,CAAC;AACzB,CAAC"}
@@ -1 +1 @@
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"}
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,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,YAAY,EAAwC,MAAM,qBAAqB,CAAC;AAE1G,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,CAoErB,CAAC"}
@@ -10,7 +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
+ import { addPanelGroup, createEmptyPanelGroup } from './panel-group-slice';
14
14
  export const createPanelGroupEditorSlice = (set, get)=>({
15
15
  panelGroupEditor: undefined,
16
16
  openAddPanelGroup: ()=>{
@@ -22,15 +22,11 @@ export const createPanelGroupEditorSlice = (set, get)=>({
22
22
  isCollapsed: false
23
23
  },
24
24
  applyChanges (next) {
25
- const newGroup = {
26
- id: generateId(),
27
- itemLayouts: [],
28
- itemPanelKeys: {},
29
- ...next
30
- };
25
+ const newGroup = createEmptyPanelGroup();
26
+ newGroup.title = next.title;
27
+ newGroup.isCollapsed = next.isCollapsed;
31
28
  set((draft)=>{
32
- draft.panelGroups[newGroup.id] = newGroup;
33
- draft.panelGroupOrder.unshift(newGroup.id);
29
+ addPanelGroup(draft, newGroup);
34
30
  });
35
31
  },
36
32
  close () {
@@ -1 +1 @@
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,2BA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YAJ9B,0BAA0B;YAC1B,MAAMlB,MAAM,GAAqB;gBAC/BC,IAAI,EAAE,MAAM;gBACZC,aAAa,EAAE;oBACbC,KAAK,EAAEe,CAAAA,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
+ {"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 { Middleware } from './common';\nimport { PanelGroupSlice, PanelGroupId, addPanelGroup, createEmptyPanelGroup } 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 = createEmptyPanelGroup();\n newGroup.title = next.title;\n newGroup.isCollapsed = next.isCollapsed;\n set((draft) => {\n addPanelGroup(draft, newGroup);\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":["addPanelGroup","createEmptyPanelGroup","createPanelGroupEditorSlice","set","get","panelGroupEditor","undefined","openAddPanelGroup","editor","mode","initialValues","title","isCollapsed","applyChanges","next","newGroup","draft","close","openEditPanelGroup","panelGroupId","existingGroup","panelGroups","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;AAIjC,SAAwCA,aAAa,EAAEC,qBAAqB,QAAQ,qBAAqB,CAAC;AAkC1G,OAAO,MAAMC,2BAA2B,GAMpC,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;gBACDC,YAAY,EAACC,IAAI,EAAE;oBACjB,MAAMC,QAAQ,GAAGd,qBAAqB,EAAE,AAAC;oBACzCc,QAAQ,CAACJ,KAAK,GAAGG,IAAI,CAACH,KAAK,CAAC;oBAC5BI,QAAQ,CAACH,WAAW,GAAGE,IAAI,CAACF,WAAW,CAAC;oBACxCT,GAA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GAAGG,IAAI,CAACH,KAAK,CAAC;wBACzBY,KAAK,CAACX,WAAW,GAAGE,IAAI,CAACF,WAAW,CAAC;oBACvC,CAAC,CAAC,CAAC;gBACL,CAAC;gBACDK,KAAK,IAAG;oBACNd,GAAG,CAAC,CAACa,KAAK,GAAK;wBACbA,KAAK,CAACX,gBAAgB,GAAGC,SAAS,CAAC;oBACrC,CAAC,CAAC,CAAC;gBACL,CAAC;aACF,AAAC;YAEF,kBAAkB;YAClBH,GAAG,CAAC,CAACa,KAAK,GAAK;gBACbA,KAAK,CAACX,gBAAgB,GAAGG,MAAM,CAAC;YAClC,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAA,AAAC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { LayoutDefinition } from '@perses-dev/core';
2
+ import { WritableDraft } from 'immer/dist/internal';
2
3
  import { Layout } from 'react-grid-layout';
3
4
  import { StateCreator } from 'zustand';
4
5
  import { Middleware } from './common';
@@ -47,4 +48,12 @@ export interface PanelGroupItemId {
47
48
  */
48
49
  export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice>;
49
50
  export declare function convertLayoutsToPanelGroups(layouts: LayoutDefinition[]): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'>;
51
+ /**
52
+ * Private helper function for creating an empty panel group.
53
+ */
54
+ export declare function createEmptyPanelGroup(): PanelGroupDefinition;
55
+ /**
56
+ * Private helper function that modifies panel group state to add a new panel
57
+ */
58
+ export declare function addPanelGroup(draft: WritableDraft<PanelGroupSlice>, newGroup: PanelGroupDefinition): void;
50
59
  //# 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.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,MAAM,E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,GAAG,iBAAiB,CAAC,CAoC1D"}
1
+ {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAc,UAAU,EAAE,MAAM,UAAU,CAAC;AAElD;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC,YAAY,EAAE,oBAAoB,CAAC,CAAC;IAExD;;OAEG;IACH,eAAe,EAAE,YAAY,EAAE,CAAC;IAEhC;;OAEG;IACH,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IAE1D;;OAEG;IACH,uBAAuB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,oBAAoB,CAAC,aAAa,CAAC,KAAK,IAAI,CAAC;CACjH;AAED,oBAAY,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,YAAY,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,oBAAoB,EAAE,CAAC;IACpC,aAAa,EAAE,MAAM,CAAC,sBAAsB,EAAE,MAAM,CAAC,CAAC;CACvD;AAED,MAAM,WAAW,oBAAqB,SAAQ,MAAM;IAClD,CAAC,EAAE,sBAAsB,CAAC;CAC3B;AAED,oBAAY,sBAAsB,GAAG,MAAM,CAAC;AAE5C;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAC;IAC3B,sBAAsB,EAAE,sBAAsB,CAAC;CAChD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,YAAY,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe,CAAC,CAkChE;AAED,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,gBAAgB,EAAE,GAC1B,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,iBAAiB,CAAC,CAoC1D;AAED;;GAEG;AACH,wBAAgB,qBAAqB,IAAI,oBAAoB,CAQ5D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,aAAa,CAAC,eAAe,CAAC,EAAE,QAAQ,EAAE,oBAAoB,QAGlG"}
@@ -84,5 +84,22 @@ export function convertLayoutsToPanelGroups(layouts) {
84
84
  panelGroupOrder: panelGroupIdOrder
85
85
  };
86
86
  }
87
+ /**
88
+ * Private helper function for creating an empty panel group.
89
+ */ export function createEmptyPanelGroup() {
90
+ return {
91
+ id: generateId(),
92
+ title: undefined,
93
+ isCollapsed: false,
94
+ itemLayouts: [],
95
+ itemPanelKeys: {}
96
+ };
97
+ }
98
+ /**
99
+ * Private helper function that modifies panel group state to add a new panel
100
+ */ export function addPanelGroup(draft, newGroup) {
101
+ draft.panelGroups[newGroup.id] = newGroup;
102
+ draft.panelGroupOrder.unshift(newGroup.id);
103
+ }
87
104
 
88
105
  //# sourceMappingURL=panel-group-slice.js.map