@perses-dev/dashboards 0.10.0 → 0.11.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 (193) hide show
  1. package/dist/cjs/components/Dashboard.js +4 -5
  2. package/dist/cjs/components/DashboardToolbar.js +11 -5
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +3 -11
  4. package/dist/cjs/components/GridLayout/GridLayout.js +8 -6
  5. package/dist/cjs/components/GridLayout/GridTitle.js +9 -11
  6. package/dist/cjs/components/Panel/DeletePanelDialog.js +12 -8
  7. package/dist/cjs/components/Panel/Panel.js +4 -13
  8. package/dist/cjs/components/Panel/Panel.test.js +4 -3
  9. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +1 -1
  10. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +3 -3
  11. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +21 -15
  12. package/dist/cjs/components/PanelDrawer/PanelPreview.js +9 -3
  13. package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +13 -11
  14. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +70 -111
  15. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +22 -16
  16. package/dist/cjs/components/PanelGroupDialog/PanelGroupEditorForm.js +92 -0
  17. package/dist/cjs/components/PanelGroupDialog/index.js +29 -0
  18. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +8 -11
  19. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +20 -13
  20. package/dist/cjs/components/Variables/Variable.js +1 -0
  21. package/dist/cjs/components/Variables/VariableEditor.js +33 -0
  22. package/dist/cjs/components/Variables/VariableList.js +0 -1
  23. package/dist/cjs/components/index.js +1 -0
  24. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +20 -8
  25. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +122 -29
  26. package/dist/cjs/context/DashboardProvider/{panel-editing-slice.js → panel-editor-slice.js} +32 -13
  27. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +102 -0
  28. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +187 -17
  29. package/dist/cjs/context/TimeRangeProvider.js +20 -44
  30. package/dist/cjs/context/index.js +1 -1
  31. package/dist/cjs/context/useDashboardSpec.js +61 -0
  32. package/dist/cjs/index.js +1 -0
  33. package/dist/cjs/test/render.js +25 -5
  34. package/dist/cjs/test/setup-tests.js +4 -1
  35. package/dist/cjs/test/testDashboard.js +11 -10
  36. package/dist/cjs/utils/index.js +28 -0
  37. package/dist/cjs/utils/time-range-params.js +145 -0
  38. package/dist/cjs/views/ViewDashboard/DashboardApp.js +2 -4
  39. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +5 -22
  40. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +42 -93
  41. package/dist/components/Dashboard.js +5 -6
  42. package/dist/components/Dashboard.js.map +1 -1
  43. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  44. package/dist/components/DashboardToolbar.js +13 -7
  45. package/dist/components/DashboardToolbar.js.map +1 -1
  46. package/dist/components/GridLayout/GridItemContent.d.ts +2 -4
  47. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  48. package/dist/components/GridLayout/GridItemContent.js +4 -12
  49. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  50. package/dist/components/GridLayout/GridLayout.d.ts +2 -3
  51. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  52. package/dist/components/GridLayout/GridLayout.js +9 -7
  53. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  54. package/dist/components/GridLayout/GridTitle.d.ts +2 -1
  55. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  56. package/dist/components/GridLayout/GridTitle.js +10 -12
  57. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  58. package/dist/components/Panel/DeletePanelDialog.d.ts +1 -1
  59. package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -1
  60. package/dist/components/Panel/DeletePanelDialog.js +13 -9
  61. package/dist/components/Panel/DeletePanelDialog.js.map +1 -1
  62. package/dist/components/Panel/Panel.d.ts +2 -2
  63. package/dist/components/Panel/Panel.d.ts.map +1 -1
  64. package/dist/components/Panel/Panel.js +5 -14
  65. package/dist/components/Panel/Panel.js.map +1 -1
  66. package/dist/components/Panel/Panel.test.d.ts +1 -1
  67. package/dist/components/Panel/Panel.test.d.ts.map +1 -1
  68. package/dist/components/Panel/Panel.test.js +4 -3
  69. package/dist/components/Panel/Panel.test.js.map +1 -1
  70. package/dist/components/PanelDrawer/PanelDrawer.js +2 -2
  71. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  72. package/dist/components/PanelDrawer/PanelDrawer.test.js +3 -3
  73. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  74. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +1 -1
  75. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  76. package/dist/components/PanelDrawer/PanelEditorForm.js +22 -16
  77. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  78. package/dist/components/PanelDrawer/PanelPreview.d.ts +2 -2
  79. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
  80. package/dist/components/PanelDrawer/PanelPreview.js +9 -3
  81. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  82. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +1 -2
  83. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -1
  84. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +13 -11
  85. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -1
  86. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts +4 -2
  87. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  88. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +73 -112
  89. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  90. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +21 -15
  91. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
  92. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +12 -0
  93. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -0
  94. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +82 -0
  95. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -0
  96. package/dist/components/PanelGroupDialog/index.d.ts +3 -0
  97. package/dist/components/PanelGroupDialog/index.d.ts.map +1 -0
  98. package/dist/components/PanelGroupDialog/index.js +16 -0
  99. package/dist/components/PanelGroupDialog/index.js.map +1 -0
  100. package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
  101. package/dist/components/TimeRangeControls/TimeRangeControls.js +11 -14
  102. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  103. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +21 -14
  104. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  105. package/dist/components/Variables/Variable.js +1 -0
  106. package/dist/components/Variables/Variable.js.map +1 -1
  107. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  108. package/dist/components/Variables/VariableEditor.js +33 -0
  109. package/dist/components/Variables/VariableEditor.js.map +1 -1
  110. package/dist/components/Variables/VariableList.js +0 -1
  111. package/dist/components/Variables/VariableList.js.map +1 -1
  112. package/dist/components/index.d.ts +1 -0
  113. package/dist/components/index.d.ts.map +1 -1
  114. package/dist/components/index.js +1 -0
  115. package/dist/components/index.js.map +1 -1
  116. package/dist/context/DashboardProvider/DashboardProvider.d.ts +7 -5
  117. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  118. package/dist/context/DashboardProvider/DashboardProvider.js +19 -7
  119. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  120. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +64 -22
  121. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  122. package/dist/context/DashboardProvider/dashboard-provider-api.js +133 -26
  123. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  124. package/dist/context/DashboardProvider/index.d.ts +2 -0
  125. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  126. package/dist/context/DashboardProvider/index.js.map +1 -1
  127. package/dist/context/DashboardProvider/{panel-editing-slice.d.ts → panel-editor-slice.d.ts} +28 -13
  128. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -0
  129. package/dist/context/DashboardProvider/{panel-editing-slice.js → panel-editor-slice.js} +33 -14
  130. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -0
  131. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +40 -0
  132. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -0
  133. package/dist/context/DashboardProvider/panel-group-editor-slice.js +96 -0
  134. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -0
  135. package/dist/context/DashboardProvider/panel-group-slice.d.ts +75 -10
  136. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  137. package/dist/context/DashboardProvider/panel-group-slice.js +189 -17
  138. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  139. package/dist/context/TimeRangeProvider.d.ts +9 -2
  140. package/dist/context/TimeRangeProvider.d.ts.map +1 -1
  141. package/dist/context/TimeRangeProvider.js +15 -43
  142. package/dist/context/TimeRangeProvider.js.map +1 -1
  143. package/dist/context/index.d.ts +1 -1
  144. package/dist/context/index.d.ts.map +1 -1
  145. package/dist/context/index.js +1 -1
  146. package/dist/context/index.js.map +1 -1
  147. package/dist/context/useDashboardSpec.d.ts +3 -0
  148. package/dist/context/useDashboardSpec.d.ts.map +1 -0
  149. package/dist/context/useDashboardSpec.js +55 -0
  150. package/dist/context/useDashboardSpec.js.map +1 -0
  151. package/dist/index.d.ts +1 -0
  152. package/dist/index.d.ts.map +1 -1
  153. package/dist/index.js +1 -0
  154. package/dist/index.js.map +1 -1
  155. package/dist/test/render.d.ts +2 -1
  156. package/dist/test/render.d.ts.map +1 -1
  157. package/dist/test/render.js +25 -5
  158. package/dist/test/render.js.map +1 -1
  159. package/dist/test/setup-tests.d.ts.map +1 -1
  160. package/dist/test/setup-tests.js +4 -0
  161. package/dist/test/setup-tests.js.map +1 -1
  162. package/dist/test/testDashboard.d.ts.map +1 -1
  163. package/dist/test/testDashboard.js +11 -10
  164. package/dist/test/testDashboard.js.map +1 -1
  165. package/dist/utils/index.d.ts +2 -0
  166. package/dist/utils/index.d.ts.map +1 -0
  167. package/dist/utils/index.js +15 -0
  168. package/dist/utils/index.js.map +1 -0
  169. package/dist/utils/time-range-params.d.ts +25 -0
  170. package/dist/utils/time-range-params.d.ts.map +1 -0
  171. package/dist/utils/time-range-params.js +137 -0
  172. package/dist/utils/time-range-params.js.map +1 -0
  173. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  174. package/dist/views/ViewDashboard/DashboardApp.js +1 -3
  175. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  176. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  177. package/dist/views/ViewDashboard/ViewDashboard.js +5 -22
  178. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  179. package/dist/views/ViewDashboard/tests/panelGroups.test.js +45 -96
  180. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  181. package/package.json +5 -4
  182. package/dist/cjs/context/DashboardProvider/layout-slice.js +0 -200
  183. package/dist/cjs/context/QueryStringProvider.js +0 -89
  184. package/dist/context/DashboardProvider/layout-slice.d.ts +0 -57
  185. package/dist/context/DashboardProvider/layout-slice.d.ts.map +0 -1
  186. package/dist/context/DashboardProvider/layout-slice.js +0 -196
  187. package/dist/context/DashboardProvider/layout-slice.js.map +0 -1
  188. package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +0 -1
  189. package/dist/context/DashboardProvider/panel-editing-slice.js.map +0 -1
  190. package/dist/context/QueryStringProvider.d.ts +0 -13
  191. package/dist/context/QueryStringProvider.d.ts.map +0 -1
  192. package/dist/context/QueryStringProvider.js +0 -40
  193. package/dist/context/QueryStringProvider.js.map +0 -1
@@ -1,32 +1,74 @@
1
+ import { PanelGroupItemId, PanelGroupId } from './panel-group-slice';
1
2
  export declare function useEditMode(): {
2
3
  isEditMode: boolean;
3
4
  setEditMode: (isEditMode: boolean) => void;
4
5
  };
5
- export declare function useLayouts(): {
6
- layouts: import("./layout-slice").PanelGroupDefinition[];
7
- addPanelToGroup: (panelKey: string, groupIndex: number) => void;
8
- movePanelToGroup: (layoutItem: import("./layout-slice").LayoutItem, newGroupIndex: number) => void;
9
- updatePanelGroup: (layout: Omit<import("./layout-slice").PanelGroupDefinition, "id">, groupIndex?: number | undefined) => void;
10
- swapPanelGroups: (xIndex: number, yIndex: number) => void;
11
- deletePanelGroup: (groupIndex: number) => void;
6
+ /**
7
+ * Returns actions that can be performed on the current dashboard.
8
+ */
9
+ export declare function useDashboardActions(): {
10
+ save: () => void;
11
+ reset: () => void;
12
+ openAddPanelGroup: () => void;
13
+ openAddPanel: () => void;
12
14
  };
13
- export declare function usePanelGroupDialog(): {
14
- panelGroupDialog: import("./panel-group-slice").PanelGroupDialog | undefined;
15
- openPanelGroupDialog: (groupIndex?: number | undefined) => void;
16
- closePanelGroupDialog: () => void;
17
- deletePanelGroupDialog: import("./panel-group-slice").PanelGroupDialog | undefined;
18
- openDeletePanelGroupDialog: (groupIndex: number) => void;
15
+ /**
16
+ * Returns an array of PanelGroupIds in the order they appear in the dashboard.
17
+ */
18
+ export declare function usePanelGroupIds(): number[];
19
+ /**
20
+ * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.
21
+ */
22
+ export declare function useListPanelGroups(): import("./panel-group-slice").PanelGroupDefinition[];
23
+ /**
24
+ * Gets a specific panel group by its id. Throws if the panel group does not exist.
25
+ */
26
+ export declare function usePanelGroup(panelGroupId: PanelGroupId): import("./panel-group-slice").PanelGroupDefinition;
27
+ /**
28
+ * Returns actions that can be performed on the given panel group.
29
+ */
30
+ export declare function usePanelGroupActions(panelGroupId: PanelGroupId): {
31
+ openEditPanelGroup: () => void;
32
+ deletePanelGroup: () => void;
33
+ openAddPanel: () => void;
34
+ moveUp: (() => void) | undefined;
35
+ moveDown: (() => void) | undefined;
36
+ };
37
+ /**
38
+ * Gets the Panel Group editor state.
39
+ */
40
+ export declare function usePanelGroupEditor(): import("./panel-group-editor-slice").PanelGroupEditor | undefined;
41
+ /**
42
+ * Gets the Delete Panel Group dialog state.
43
+ */
44
+ export declare function useDeletePanelGroupDialog(): {
45
+ deletePanelGroupDialog: import("./panel-group-editor-slice").DeletePanelGroupDialog | undefined;
46
+ openDeletePanelGroupDialog: (panelGroupId: number) => void;
19
47
  closeDeletePanelGroupDialog: () => void;
48
+ deletePanelGroup: (panelGroupId: number) => void;
49
+ };
50
+ /**
51
+ * Gets an individual panel in the store. Throws if the panel can't be found.
52
+ */
53
+ export declare function usePanel(panelGroupItemId: PanelGroupItemId): import("@perses-dev/core").PanelDefinition<import("@perses-dev/core").UnknownSpec>;
54
+ /**
55
+ * Returns actions that can be performed on the given Panel.
56
+ */
57
+ export declare function usePanelActions(panelGroupItemId: PanelGroupItemId): {
58
+ openEditPanel: () => void;
59
+ openDeletePanelDialog: () => void;
20
60
  };
21
- export declare function usePanels(): {
22
- panels: Record<string, import("@perses-dev/core").PanelDefinition<import("@perses-dev/core").UnknownSpec>>;
23
- panelEditor: import("./panel-editing-slice").PanelEditorState | undefined;
24
- addPanel: (initialGroup: number) => void;
25
- editPanel: (item: import("./layout-slice").LayoutItem) => void;
26
- deletePanels: (panels: import("./layout-slice").LayoutItem[]) => void;
27
- deletePanelDialog: import("./panel-editing-slice").DeletePanelDialog | undefined;
28
- openDeletePanelDialog: (item: import("./layout-slice").LayoutItem) => void;
61
+ /**
62
+ * Gets the state for the Panel Editor.
63
+ */
64
+ export declare function usePanelEditor(): import("./panel-editor-slice").PanelEditorState | undefined;
65
+ /**
66
+ * Gets the state for the Delete Panel dialog.
67
+ */
68
+ export declare function useDeletePanelDialog(): {
69
+ deletePanelDialog: import("./panel-editor-slice").DeletePanelDialog | undefined;
70
+ deletePanels: (panels: PanelGroupItemId[]) => void;
29
71
  closeDeletePanelDialog: () => void;
30
72
  };
31
- export declare function useDefaultTimeRange(): import("@perses-dev/core").DurationString;
73
+ export declare function useDefaultTimeRange(): import("@perses-dev/core").RelativeTimeRange;
32
74
  //# sourceMappingURL=dashboard-provider-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dashboard-provider-api.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"names":[],"mappings":"AAeA,wBAAgB,WAAW;;;EAE1B;AAED,wBAAgB,UAAU;;;;;;;EAWzB;AAED,wBAAgB,mBAAmB;;;;;;;EAkBlC;AAED,wBAAgB,SAAS;;;;;;;;;EAsBxB;AAED,wBAAgB,mBAAmB,8CAElC"}
1
+ {"version":3,"file":"dashboard-provider-api.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAErE,wBAAgB,WAAW;;;EAE1B;AAED;;GAEG;AACH,wBAAgB,mBAAmB;;;;;EAYlC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,aAE/B;AAED;;GAEG;AACH,wBAAgB,kBAAkB,yDAYjC;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,YAAY,EAAE,YAAY,sDAMvD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,YAAY;;;;;;EAa9D;AAuBD;;GAEG;AACH,wBAAgB,mBAAmB,sEAElC;AAED;;GAEG;AACH,wBAAgB,yBAAyB;;;;;EASxC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,sFAc1D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,gBAAgB,EAAE,gBAAgB;;;EAOjE;AAED;;GAEG;AACH,wBAAgB,cAAc,gEAE7B;AAED;;GAEG;AACH,wBAAgB,oBAAoB;;;;EAWnC;AAED,wBAAgB,mBAAmB,iDAElC"}
@@ -10,6 +10,8 @@
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 { getPanelKeyFromRef } from '@perses-dev/core';
14
+ import { useMemo } from 'react';
13
15
  import { useDashboardStore } from './DashboardProvider';
14
16
  export function useEditMode() {
15
17
  return useDashboardStore(({ isEditMode , setEditMode })=>({
@@ -17,37 +19,142 @@ export function useEditMode() {
17
19
  setEditMode
18
20
  }));
19
21
  }
20
- export function useLayouts() {
21
- return useDashboardStore(({ layouts , addPanelToGroup , movePanelToGroup , updatePanelGroup , swapPanelGroups , deletePanelGroup })=>({
22
- layouts,
23
- addPanelToGroup,
24
- movePanelToGroup,
25
- updatePanelGroup,
26
- swapPanelGroups,
27
- deletePanelGroup
28
- }));
22
+ /**
23
+ * Returns actions that can be performed on the current dashboard.
24
+ */ export function useDashboardActions() {
25
+ const save = useDashboardStore((store)=>store.save);
26
+ const reset = useDashboardStore((store)=>store.reset);
27
+ const openAddPanelGroup = useDashboardStore((store)=>store.openAddPanelGroup);
28
+ const openAddPanel = useDashboardStore((store)=>store.openAddPanel);
29
+ return {
30
+ save,
31
+ reset,
32
+ openAddPanelGroup,
33
+ openAddPanel: ()=>openAddPanel(undefined)
34
+ };
35
+ }
36
+ /**
37
+ * Returns an array of PanelGroupIds in the order they appear in the dashboard.
38
+ */ export function usePanelGroupIds() {
39
+ return useDashboardStore((store)=>store.panelGroupIdOrder);
40
+ }
41
+ /**
42
+ * Returns an array of PanelGroupDefinitions in the order they appear in the dashboard.
43
+ */ export function useListPanelGroups() {
44
+ const panelGroupIds = usePanelGroupIds();
45
+ const panelGroups = useDashboardStore((store)=>store.panelGroups);
46
+ return useMemo(()=>{
47
+ return panelGroupIds.map((id)=>{
48
+ const group = panelGroups[id];
49
+ if (group === undefined) {
50
+ throw new Error(`Invalid panel group Id found ${id}`);
51
+ }
52
+ return group;
53
+ });
54
+ }, [
55
+ panelGroupIds,
56
+ panelGroups
57
+ ]);
58
+ }
59
+ /**
60
+ * Gets a specific panel group by its id. Throws if the panel group does not exist.
61
+ */ export function usePanelGroup(panelGroupId) {
62
+ const panelGroup = useDashboardStore((store)=>store.panelGroups[panelGroupId]);
63
+ if (panelGroup === undefined) {
64
+ throw new Error(`Panel group with Id ${panelGroupId} was not found`);
65
+ }
66
+ return panelGroup;
67
+ }
68
+ /**
69
+ * Returns actions that can be performed on the given panel group.
70
+ */ export function usePanelGroupActions(panelGroupId) {
71
+ const { moveUp , moveDown } = useMovePanelGroup(panelGroupId);
72
+ const openEditPanelGroup = useDashboardStore((store)=>store.openEditPanelGroup);
73
+ const deletePanelGroup = useDashboardStore((store)=>store.openDeletePanelGroupDialog);
74
+ const openAddPanel = useDashboardStore((store)=>store.openAddPanel);
75
+ return {
76
+ openEditPanelGroup: ()=>openEditPanelGroup(panelGroupId),
77
+ deletePanelGroup: ()=>deletePanelGroup(panelGroupId),
78
+ openAddPanel: ()=>openAddPanel(panelGroupId),
79
+ moveUp,
80
+ moveDown
81
+ };
82
+ }
83
+ /**
84
+ * Returns functions for moving a panel group up or down. A function will be undefined if the panel group can't be
85
+ * moved in that direction.
86
+ */ function useMovePanelGroup(panelGroupId) {
87
+ const currentIndex = useDashboardStore((store)=>store.panelGroupIdOrder.findIndex((id)=>id === panelGroupId));
88
+ const panelGroupsLength = useDashboardStore((store)=>store.panelGroupIdOrder.length);
89
+ const swapPanelGroups = useDashboardStore((store)=>store.swapPanelGroups);
90
+ if (currentIndex < 0) {
91
+ throw new Error(`Could not find panel group with Id ${panelGroupId} in order array`);
92
+ }
93
+ const moveUp = ()=>swapPanelGroups(currentIndex, currentIndex - 1);
94
+ const moveDown = ()=>swapPanelGroups(currentIndex, currentIndex + 1);
95
+ return {
96
+ moveUp: currentIndex > 0 ? moveUp : undefined,
97
+ moveDown: currentIndex < panelGroupsLength - 1 ? moveDown : undefined
98
+ };
29
99
  }
30
- export function usePanelGroupDialog() {
31
- return useDashboardStore(({ panelGroupDialog , openPanelGroupDialog , closePanelGroupDialog , deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , })=>({
32
- panelGroupDialog,
33
- openPanelGroupDialog,
34
- closePanelGroupDialog,
100
+ /**
101
+ * Gets the Panel Group editor state.
102
+ */ export function usePanelGroupEditor() {
103
+ return useDashboardStore((store)=>store.panelGroupEditor);
104
+ }
105
+ /**
106
+ * Gets the Delete Panel Group dialog state.
107
+ */ export function useDeletePanelGroupDialog() {
108
+ return useDashboardStore(({ deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , deletePanelGroup })=>({
35
109
  deletePanelGroupDialog,
36
110
  openDeletePanelGroupDialog,
37
- closeDeletePanelGroupDialog
111
+ closeDeletePanelGroupDialog,
112
+ deletePanelGroup
38
113
  }));
39
114
  }
40
- export function usePanels() {
41
- return useDashboardStore(({ panels , panelEditor , addPanel , editPanel , deletePanelDialog , deletePanels , openDeletePanelDialog , closeDeletePanelDialog , })=>({
42
- panels,
43
- panelEditor,
44
- addPanel,
45
- editPanel,
46
- deletePanels,
47
- deletePanelDialog,
48
- openDeletePanelDialog,
49
- closeDeletePanelDialog
50
- }));
115
+ /**
116
+ * Gets an individual panel in the store. Throws if the panel can't be found.
117
+ */ export function usePanel(panelGroupItemId) {
118
+ const { panelGroupId , itemIndex } = panelGroupItemId;
119
+ const panel = useDashboardStore((store)=>{
120
+ var ref, ref1;
121
+ const panelRef = (ref1 = (ref = store.panelGroups[panelGroupId]) === null || ref === void 0 ? void 0 : ref.items[itemIndex]) === null || ref1 === void 0 ? void 0 : ref1.content;
122
+ if (panelRef === undefined) return;
123
+ const panelKey = getPanelKeyFromRef(panelRef);
124
+ return store.panels[panelKey];
125
+ });
126
+ if (panel === undefined) {
127
+ throw new Error(`Could not find panel for Id ${panelGroupItemId}`);
128
+ }
129
+ return panel;
130
+ }
131
+ /**
132
+ * Returns actions that can be performed on the given Panel.
133
+ */ export function usePanelActions(panelGroupItemId) {
134
+ const openEditPanel = useDashboardStore((store)=>store.openEditPanel);
135
+ const openDeletePanelDialog = useDashboardStore((store)=>store.openDeletePanelDialog);
136
+ return {
137
+ openEditPanel: ()=>openEditPanel(panelGroupItemId),
138
+ openDeletePanelDialog: ()=>openDeletePanelDialog(panelGroupItemId)
139
+ };
140
+ }
141
+ /**
142
+ * Gets the state for the Panel Editor.
143
+ */ export function usePanelEditor() {
144
+ return useDashboardStore((store)=>store.panelEditor);
145
+ }
146
+ /**
147
+ * Gets the state for the Delete Panel dialog.
148
+ */ export function useDeletePanelDialog() {
149
+ const deletePanelDialog = useDashboardStore((store)=>store.deletePanelDialog);
150
+ // TODO: Refactor similar to other dialogs/editors so these are on the editor state itself
151
+ const deletePanels = useDashboardStore((store)=>store.deletePanels);
152
+ const closeDeletePanelDialog = useDashboardStore((store)=>store.closeDeletePanelDialog);
153
+ return {
154
+ deletePanelDialog,
155
+ deletePanels,
156
+ closeDeletePanelDialog
157
+ };
51
158
  }
52
159
  export function useDefaultTimeRange() {
53
160
  return useDashboardStore((state)=>state.defaultTimeRange);
@@ -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 { useDashboardStore } from './DashboardProvider';\n\nexport function useEditMode() {\n return useDashboardStore(({ isEditMode, setEditMode }) => ({ isEditMode, setEditMode }));\n}\n\nexport function useLayouts() {\n return useDashboardStore(\n ({ layouts, addPanelToGroup, movePanelToGroup, updatePanelGroup, swapPanelGroups, deletePanelGroup }) => ({\n layouts,\n addPanelToGroup,\n movePanelToGroup,\n updatePanelGroup,\n swapPanelGroups,\n deletePanelGroup,\n })\n );\n}\n\nexport function usePanelGroupDialog() {\n return useDashboardStore(\n ({\n panelGroupDialog,\n openPanelGroupDialog,\n closePanelGroupDialog,\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n }) => ({\n panelGroupDialog,\n openPanelGroupDialog,\n closePanelGroupDialog,\n deletePanelGroupDialog,\n openDeletePanelGroupDialog,\n closeDeletePanelGroupDialog,\n })\n );\n}\n\nexport function usePanels() {\n return useDashboardStore(\n ({\n panels,\n panelEditor,\n addPanel,\n editPanel,\n deletePanelDialog,\n deletePanels,\n openDeletePanelDialog,\n closeDeletePanelDialog,\n }) => ({\n panels,\n panelEditor,\n addPanel,\n editPanel,\n deletePanels,\n deletePanelDialog,\n openDeletePanelDialog,\n closeDeletePanelDialog,\n })\n );\n}\n\nexport function useDefaultTimeRange() {\n return useDashboardStore((state) => state.defaultTimeRange);\n}\n"],"names":["useDashboardStore","useEditMode","isEditMode","setEditMode","useLayouts","layouts","addPanelToGroup","movePanelToGroup","updatePanelGroup","swapPanelGroups","deletePanelGroup","usePanelGroupDialog","panelGroupDialog","openPanelGroupDialog","closePanelGroupDialog","deletePanelGroupDialog","openDeletePanelGroupDialog","closeDeletePanelGroupDialog","usePanels","panels","panelEditor","addPanel","editPanel","deletePanelDialog","deletePanels","openDeletePanelDialog","closeDeletePanelDialog","useDefaultTimeRange","state","defaultTimeRange"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE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A,IACvB,GAAM,CAAA;YACLP,MAAM;YACNC,WAAW;YACXC,QAAQ;YACRC,SAAS;YACTE,YAAY;YACZD,iBAAiB;YACjBE,qBAAqB;YACrBC,sBAAsB;SACvB,CAAA,AAAC,CACH,CAAC;AACJ,CAAC;AAED,OAAO,SAASC,mBAAmB,GAAG;IACpC,OAAO3B,iBAAiB,CAAC,CAAC4B,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 { getPanelKeyFromRef } from '@perses-dev/core';\nimport { useMemo } from 'react';\nimport { useDashboardStore } from './DashboardProvider';\nimport { PanelGroupItemId, PanelGroupId } 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 save = useDashboardStore((store) => store.save);\n const reset = useDashboardStore((store) => store.reset);\n const openAddPanelGroup = useDashboardStore((store) => store.openAddPanelGroup);\n const openAddPanel = useDashboardStore((store) => store.openAddPanel);\n\n return {\n save,\n reset,\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.panelGroupIdOrder);\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\n return {\n openEditPanelGroup: () => openEditPanelGroup(panelGroupId),\n deletePanelGroup: () => deletePanelGroup(panelGroupId),\n openAddPanel: () => openAddPanel(panelGroupId),\n moveUp,\n moveDown,\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.panelGroupIdOrder.findIndex((id) => id === panelGroupId));\n const panelGroupsLength = useDashboardStore((store) => store.panelGroupIdOrder.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, itemIndex } = panelGroupItemId;\n\n const panel = useDashboardStore((store) => {\n const panelRef = store.panelGroups[panelGroupId]?.items[itemIndex]?.content;\n if (panelRef === undefined) return;\n const panelKey = getPanelKeyFromRef(panelRef);\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 deletePanels = useDashboardStore((store) => store.deletePanels);\n const closeDeletePanelDialog = useDashboardStore((store) => store.closeDeletePanelDialog);\n\n return {\n deletePanelDialog,\n deletePanels,\n closeDeletePanelDialog,\n };\n}\n\nexport function useDefaultTimeRange() {\n return useDashboardStore((state) => state.defaultTimeRange);\n}\n"],"names":["getPanelKeyFromRef","useMemo","useDashboardStore","useEditMode","isEditMode","setEditMode","useDashboardActions","save","store","reset","openAddPanelGroup","openAddPanel","undefined","usePanelGroupIds","panelGroupIdOrder","useListPanelGroups","panelGroupIds","panelGroups","map","id","group","Error","usePanelGroup","panelGroupId","panelGroup","usePanelGroupActions","moveUp","moveDown","useMovePanelGroup","openEditPanelGroup","deletePanelGroup","openDeletePanelGroupDialog","currentIndex","findIndex","panelGroupsLength","length","swapPanelGroups","usePanelGroupEditor","panelGroupEditor","useDeletePanelGroupDialog","deletePanelGroupDialog","closeDeletePanelGroupDialog","usePanel","panelGroupItemId","itemIndex","panel","panelRef","items","content","panelKey","panels","usePanelActions","openEditPanel","openDeletePanelDialog","usePanelEditor","panelEditor","useDeletePanelDialog","deletePanelDialog","deletePanels","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,kBAAkB,QAAQ,kBAAkB,CAAC;AACtD,SAASC,OAAO,QAAQ,OAAO,CAAC;AAChC,SAASC,iBAAiB,QAAQ,qBAAqB,CAAC;AAGxD,OAAO,SAASC,WAAW,GAAG;IAC5B,OAAOD,iBAAiB,CAAC,CAAC,EAAEE,UAAU,CAAA,EAAEC,WAAW,CAAA,EAAE,GAAM,CAAA;YAAED,UAAU;YAAEC,WAAW;SAAE,CAAA,AAAC,CAAC,CAAC;AAC3F,CAAC;AAED;;CAEC,GACD,OAAO,SAASC,mBAAmB,GAAG;IACpC,MAAMC,IAAI,GAAGL,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACD,IAAI,CAAC,A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C,CAACM,KAAK,GAAKA,KAAK,CAACiD,iBAAiB,CAAC,AAAC;IAChF,0FAA0F;IAC1F,MAAMC,YAAY,GAAGxD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACkD,YAAY,CAAC,AAAC;IACtE,MAAMC,sBAAsB,GAAGzD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACmD,sBAAsB,CAAC,AAAC;IAE1F,OAAO;QACLF,iBAAiB;QACjBC,YAAY;QACZC,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,3 +1,5 @@
1
1
  export * from './dashboard-provider-api';
2
2
  export * from './DashboardProvider';
3
+ export type { PanelGroupId, PanelGroupDefinition, PanelGroupItemId as LayoutItem } from './panel-group-slice';
4
+ export type { PanelGroupEditor, PanelGroupEditorValues } from './panel-group-editor-slice';
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/index.ts"],"names":[],"mappings":"AAaA,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/index.ts"],"names":[],"mappings":"AAaA,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC;AACpC,YAAY,EAAE,YAAY,EAAE,oBAAoB,EAAE,gBAAgB,IAAI,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC9G,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/index.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\nexport * from './dashboard-provider-api';\nexport * from './DashboardProvider';\n"],"names":[],"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,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/index.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\nexport * from './dashboard-provider-api';\nexport * from './DashboardProvider';\nexport type { PanelGroupId, PanelGroupDefinition, PanelGroupItemId as LayoutItem } from './panel-group-slice';\nexport type { PanelGroupEditor, PanelGroupEditorValues } from './panel-group-editor-slice';\n"],"names":[],"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,cAAc,0BAA0B,CAAC;AACzC,cAAc,qBAAqB,CAAC"}
@@ -1,39 +1,54 @@
1
1
  import { PanelDefinition, UnknownSpec } from '@perses-dev/core';
2
2
  import { StateCreator } from 'zustand';
3
3
  import { Middleware } from './common';
4
- import { LayoutSlice, LayoutItem } from './layout-slice';
4
+ import { PanelGroupSlice, PanelGroupItemId, PanelGroupId } from './panel-group-slice';
5
+ /**
6
+ * Slice that handles the visual editor state and actions for Panels (i.e. add, edit, delete).
7
+ */
5
8
  export interface PanelEditorSlice {
6
9
  panels: Record<string, PanelDefinition>;
7
- deletePanelDialog?: DeletePanelDialog;
10
+ previousPanels: Record<string, PanelDefinition>;
8
11
  /**
9
12
  * State for the panel editor when its open, otherwise undefined when it's closed.
10
13
  */
11
14
  panelEditor?: PanelEditorState;
12
15
  /**
13
- * Edit an existing panel by providing its layout coordinates.
16
+ * Opens the editor for editing an existing panel by providing its layout coordinates.
14
17
  */
15
- editPanel: (item: LayoutItem) => void;
18
+ openEditPanel: (item: PanelGroupItemId) => void;
16
19
  /**
17
- * Add a new Panel to a panel group.
20
+ * Opens the editor for adding a new Panel to a panel group.
18
21
  */
19
- addPanel: (initialGroup: number) => void;
22
+ openAddPanel: (panelGroupId?: PanelGroupId) => void;
20
23
  /**
21
24
  * Delete panels
22
25
  */
23
- deletePanels: (panels: LayoutItem[]) => void;
26
+ deletePanels: (panels: PanelGroupItemId[]) => void;
27
+ /**
28
+ * Reset panels to previous state
29
+ */
30
+ resetPanels: () => void;
31
+ /**
32
+ * Save panels
33
+ */
34
+ savePanels: () => void;
35
+ /**
36
+ * State for the delete panel dialog when it's open, otherwise undefined when it's closed.
37
+ */
38
+ deletePanelDialog?: DeletePanelDialog;
24
39
  /**
25
40
  * Open delete panel dialog
26
41
  */
27
- openDeletePanelDialog: (item: LayoutItem) => void;
42
+ openDeletePanelDialog: (item: PanelGroupItemId) => void;
28
43
  /**
29
44
  * Close delete panel dialog
30
45
  */
31
46
  closeDeletePanelDialog: () => void;
32
47
  }
33
48
  export interface DeletePanelDialog {
34
- panelKey: string;
49
+ panelGroupItemId: PanelGroupItemId;
35
50
  panelName: string;
36
- layoutItem: LayoutItem;
51
+ panelGroupName: string;
37
52
  }
38
53
  export interface PanelEditorState {
39
54
  /**
@@ -59,12 +74,12 @@ export interface PanelEditorState {
59
74
  export interface PanelEditorValues {
60
75
  name: string;
61
76
  description: string;
62
- groupIndex: number;
77
+ groupId: PanelGroupId;
63
78
  kind: string;
64
79
  spec: UnknownSpec;
65
80
  }
66
81
  /**
67
82
  * Curried function for creating the PanelEditorSlice.
68
83
  */
69
- export declare function createPanelEditorSlice(panels: PanelEditorSlice['panels']): StateCreator<PanelEditorSlice & LayoutSlice, Middleware, [], PanelEditorSlice>;
70
- //# sourceMappingURL=panel-editing-slice.d.ts.map
84
+ export declare function createPanelEditorSlice(panels: PanelEditorSlice['panels']): StateCreator<PanelEditorSlice & PanelGroupSlice, Middleware, [], PanelEditorSlice>;
85
+ //# sourceMappingURL=panel-editor-slice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel-editor-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editor-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEtF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAE/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACxC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAEhD;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,aAAa,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,CAAC;IA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ialCharacters } from '../../utils/functions';
17
17
  // Return the state creator function for Zustand that uses the panels provided as intitial state
18
18
  return (set, get)=>{
19
19
  return {
20
+ previousPanels: panels,
20
21
  panels,
21
22
  panelEditor: undefined,
22
- editPanel (item) {
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) {
23
34
  const { panels , getPanelKey } = get();
24
35
  // Ask the layout store for the panel key at that location
25
36
  const panelKey = getPanelKey(item);
@@ -34,7 +45,7 @@ import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
34
45
  initialValues: {
35
46
  name: panelToEdit.spec.display.name,
36
47
  description: (_description = panelToEdit.spec.display.description) !== null && _description !== void 0 ? _description : '',
37
- groupIndex: item.groupIndex,
48
+ groupId: item.panelGroupId,
38
49
  kind: panelToEdit.spec.plugin.kind,
39
50
  spec: panelToEdit.spec.plugin.spec
40
51
  },
@@ -44,8 +55,8 @@ import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
44
55
  state.panels[panelKey] = panelDefinititon;
45
56
  });
46
57
  // Move the panel to another group if it changed
47
- if (next.groupIndex !== item.groupIndex) {
48
- get().movePanelToGroup(item, next.groupIndex);
58
+ if (next.groupId !== item.panelGroupId) {
59
+ get().movePanelToGroup(item, next.groupId);
49
60
  }
50
61
  },
51
62
  close: ()=>{
@@ -59,13 +70,21 @@ import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
59
70
  state.panelEditor = editorState;
60
71
  });
61
72
  },
62
- addPanel (initialGroup) {
73
+ openAddPanel (panelGroupId) {
74
+ // If a panel group isn't supplied, add to the first group
75
+ if (panelGroupId === undefined) {
76
+ const firstGroupId = get().panelGroupIdOrder[0];
77
+ if (firstGroupId === undefined) {
78
+ throw new Error('No panel groups to add a panel to');
79
+ }
80
+ panelGroupId = firstGroupId;
81
+ }
63
82
  const editorState = {
64
83
  mode: 'Add',
65
84
  initialValues: {
66
85
  name: '',
67
86
  description: '',
68
- groupIndex: initialGroup,
87
+ groupId: panelGroupId,
69
88
  // TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to
70
89
  // set a smarter default here?
71
90
  kind: '',
@@ -77,7 +96,7 @@ import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
77
96
  set((state)=>{
78
97
  state.panels[panelKey] = panelDef;
79
98
  });
80
- get().addPanelToGroup(panelKey, next.groupIndex);
99
+ get().addPanelToGroup(panelKey, next.groupId);
81
100
  },
82
101
  close: ()=>{
83
102
  set((state)=>{
@@ -112,15 +131,15 @@ import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
112
131
  });
113
132
  },
114
133
  openDeletePanelDialog (item) {
134
+ const { panels , getPanelKey , panelGroups } = get();
135
+ const panelKey = getPanelKey(item);
115
136
  set((state)=>{
116
- var ref;
117
- const { panels , getPanelKey } = get();
118
- const panelKey = getPanelKey(item);
119
- var _name;
137
+ var ref, ref1;
138
+ var _name, ref2;
120
139
  state.deletePanelDialog = {
121
- panelKey,
140
+ panelGroupItemId: item,
122
141
  panelName: (_name = (ref = panels[panelKey]) === null || ref === void 0 ? void 0 : ref.spec.display.name) !== null && _name !== void 0 ? _name : '',
123
- layoutItem: item
142
+ panelGroupName: (ref2 = (ref1 = panelGroups[item.panelGroupId]) === null || ref1 === void 0 ? void 0 : ref1.title) !== null && ref2 !== void 0 ? ref2 : ''
124
143
  };
125
144
  });
126
145
  },
@@ -149,4 +168,4 @@ function createPanelDefinitionFromEditorValues(editorValues) {
149
168
  };
150
169
  }
151
170
 
152
- //# sourceMappingURL=panel-editing-slice.js.map
171
+ //# sourceMappingURL=panel-editor-slice.js.map
@@ -0,0 +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,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;AAiG9E;;CAEC,GACD,OAAO,SAASC,sBAAsB,CACpCC,MAAkC,EACkD;IACpF,gGAAgG;IAChG,OAAO,CAACC,GAAG,EAAEC,GAAG;QAAM,OAAA;YACpBC,cAAc,EAAEH,MAAM;YACtBA,MAAM;YAENI,WAAW,EAAEC,SAAS;YAEtBC,UAAU,IAAG;gBACXL,GAAG,CAAC,CAACM,KAAK,GAAK;oBACbA,KAAK,CAACJ,cAAc,GAAGI,KAAK,CAACP,MAAM,CAAC;gBACtC,CAAC,CAAC,CAAC;YACL,CAAC;YAEDQ,WAAW,IAAG;gBACZP,GAAG,CAAC,CAACM,KAAK,GAAK;oBACbA,KAAK,CAACP,MAAM,GAAGO,KAAK,CAACJ,cAAc,CAAC;gBACtC,CAAC,CAAC,CAAC;YACL,CAAC;YAEDM,aAAa,EAACC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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"}
@@ -0,0 +1,40 @@
1
+ import { StateCreator } from 'zustand';
2
+ import { Middleware } from './common';
3
+ import { PanelGroupSlice, PanelGroupId } from './panel-group-slice';
4
+ export interface PanelGroupEditor {
5
+ mode: 'Add' | 'Edit';
6
+ initialValues: PanelGroupEditorValues;
7
+ applyChanges: (next: PanelGroupEditorValues) => void;
8
+ close: () => void;
9
+ }
10
+ export interface PanelGroupEditorValues {
11
+ title: string;
12
+ isCollapsed: boolean;
13
+ }
14
+ export interface DeletePanelGroupDialog {
15
+ panelGroupId: PanelGroupId;
16
+ panelGroupName?: string;
17
+ }
18
+ /**
19
+ * Slice that handles the visual editor state and actions for Panel Groups (i.e. add, edit, delete).
20
+ */
21
+ export interface PanelGroupEditorSlice {
22
+ /**
23
+ * State that's present when the panel group editor is open.
24
+ */
25
+ panelGroupEditor?: PanelGroupEditor;
26
+ /**
27
+ * Opens the panel group editor to add a new panel group.
28
+ */
29
+ openAddPanelGroup: () => void;
30
+ /**
31
+ * Opens the panel group editor to edit an existing panel group.
32
+ */
33
+ openEditPanelGroup: (panelGroupId: PanelGroupId) => void;
34
+ deletePanelGroupDialog?: DeletePanelGroupDialog;
35
+ openDeletePanelGroupDialog: (panelGroupId: PanelGroupId) => void;
36
+ closeDeletePanelGroupDialog: () => void;
37
+ }
38
+ export declare const createPanelGroupEditorSlice: StateCreator<PanelGroupEditorSlice & PanelGroupSlice, Middleware, [
39
+ ], PanelGroupEditorSlice>;
40
+ //# sourceMappingURL=panel-group-editor-slice.d.ts.map
@@ -0,0 +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"}