@perses-dev/dashboards 0.12.0 → 0.14.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 (208) hide show
  1. package/dist/cjs/components/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
  2. package/dist/cjs/components/Dashboard/index.js +28 -0
  3. package/dist/cjs/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +15 -34
  4. package/dist/cjs/components/DashboardToolbar/index.js +28 -0
  5. package/dist/cjs/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +2 -3
  6. package/dist/cjs/components/DeletePanelDialog/index.js +28 -0
  7. package/dist/cjs/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
  8. package/dist/cjs/components/DeletePanelGroupDialog/index.js +28 -0
  9. package/dist/cjs/components/GridLayout/GridItemContent.js +11 -1
  10. package/dist/cjs/components/Panel/Panel.js +30 -89
  11. package/dist/cjs/components/Panel/Panel.test.js +93 -47
  12. package/dist/cjs/components/Panel/PanelHeader.js +116 -0
  13. package/dist/cjs/components/Panel/index.js +0 -1
  14. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +1 -2
  15. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +9 -15
  16. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +7 -5
  17. package/dist/cjs/components/PanelDrawer/PanelPreview.js +13 -20
  18. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
  19. package/dist/cjs/components/PanelGroupDialog/index.js +0 -1
  20. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
  21. package/dist/cjs/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +67 -0
  22. package/dist/cjs/components/UnsavedChangesConfirmationDialog/index.js +28 -0
  23. package/dist/cjs/components/Variables/Variable.js +18 -11
  24. package/dist/cjs/components/index.js +4 -0
  25. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +24 -18
  26. package/dist/cjs/context/DashboardProvider/common.js +1 -1
  27. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +2 -4
  28. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +47 -52
  29. package/dist/cjs/context/DashboardProvider/panel-slice.js +2 -13
  30. package/dist/cjs/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
  31. package/dist/cjs/context/TemplateVariableProvider/index.js +28 -0
  32. package/dist/cjs/context/TemplateVariableProvider/query-params.js +79 -0
  33. package/dist/cjs/context/TemplateVariableProvider/query-params.test.js +82 -0
  34. package/dist/cjs/context/index.js +1 -1
  35. package/dist/cjs/context/{useDashboardSpec.js → useDashboard.js} +20 -16
  36. package/dist/cjs/test/plugin-registry.js +14 -54
  37. package/dist/cjs/test/render.js +6 -2
  38. package/dist/cjs/utils/component-ids.js +31 -0
  39. package/dist/cjs/views/ViewDashboard/DashboardApp.js +42 -11
  40. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +4 -3
  41. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +1 -1
  42. package/dist/components/{Dashboard.d.ts → Dashboard/Dashboard.d.ts} +0 -0
  43. package/dist/components/Dashboard/Dashboard.d.ts.map +1 -0
  44. package/dist/components/{Dashboard.js → Dashboard/Dashboard.js} +2 -2
  45. package/dist/components/Dashboard/Dashboard.js.map +1 -0
  46. package/dist/components/Dashboard/index.d.ts +2 -0
  47. package/dist/components/Dashboard/index.d.ts.map +1 -0
  48. package/dist/components/Dashboard/index.js +15 -0
  49. package/dist/components/Dashboard/index.js.map +1 -0
  50. package/dist/components/{DashboardToolbar.d.ts → DashboardToolbar/DashboardToolbar.d.ts} +3 -0
  51. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -0
  52. package/dist/components/{DashboardToolbar.js → DashboardToolbar/DashboardToolbar.js} +11 -30
  53. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -0
  54. package/dist/components/DashboardToolbar/index.d.ts +2 -0
  55. package/dist/components/DashboardToolbar/index.d.ts.map +1 -0
  56. package/dist/components/DashboardToolbar/index.js +15 -0
  57. package/dist/components/DashboardToolbar/index.js.map +1 -0
  58. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts +3 -0
  59. package/dist/components/DeletePanelDialog/DeletePanelDialog.d.ts.map +1 -0
  60. package/dist/components/{Panel → DeletePanelDialog}/DeletePanelDialog.js +1 -2
  61. package/dist/components/DeletePanelDialog/DeletePanelDialog.js.map +1 -0
  62. package/dist/components/DeletePanelDialog/index.d.ts +2 -0
  63. package/dist/components/DeletePanelDialog/index.d.ts.map +1 -0
  64. package/dist/components/DeletePanelDialog/index.js +15 -0
  65. package/dist/components/DeletePanelDialog/index.js.map +1 -0
  66. package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.d.ts +0 -0
  67. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
  68. package/dist/components/{PanelGroupDialog → DeletePanelGroupDialog}/DeletePanelGroupDialog.js +0 -0
  69. package/dist/components/DeletePanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
  70. package/dist/components/DeletePanelGroupDialog/index.d.ts +2 -0
  71. package/dist/components/DeletePanelGroupDialog/index.d.ts.map +1 -0
  72. package/dist/components/DeletePanelGroupDialog/index.js +15 -0
  73. package/dist/components/DeletePanelGroupDialog/index.js.map +1 -0
  74. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  75. package/dist/components/GridLayout/GridItemContent.js +12 -2
  76. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  77. package/dist/components/Panel/Panel.d.ts +3 -3
  78. package/dist/components/Panel/Panel.d.ts.map +1 -1
  79. package/dist/components/Panel/Panel.js +32 -91
  80. package/dist/components/Panel/Panel.js.map +1 -1
  81. package/dist/components/Panel/Panel.test.js +95 -49
  82. package/dist/components/Panel/Panel.test.js.map +1 -1
  83. package/dist/components/Panel/PanelHeader.d.ts +16 -0
  84. package/dist/components/Panel/PanelHeader.d.ts.map +1 -0
  85. package/dist/components/Panel/PanelHeader.js +105 -0
  86. package/dist/components/Panel/PanelHeader.js.map +1 -0
  87. package/dist/components/Panel/index.d.ts +0 -1
  88. package/dist/components/Panel/index.d.ts.map +1 -1
  89. package/dist/components/Panel/index.js +0 -1
  90. package/dist/components/Panel/index.js.map +1 -1
  91. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  92. package/dist/components/PanelDrawer/PanelDrawer.js +1 -2
  93. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  94. package/dist/components/PanelDrawer/PanelDrawer.test.js +10 -16
  95. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  96. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  97. package/dist/components/PanelDrawer/PanelEditorForm.js +8 -6
  98. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  99. package/dist/components/PanelDrawer/PanelPreview.d.ts +2 -2
  100. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -1
  101. package/dist/components/PanelDrawer/PanelPreview.js +13 -20
  102. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -1
  103. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +1 -1
  104. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
  105. package/dist/components/PanelGroupDialog/index.d.ts +0 -1
  106. package/dist/components/PanelGroupDialog/index.d.ts.map +1 -1
  107. package/dist/components/PanelGroupDialog/index.js +0 -1
  108. package/dist/components/PanelGroupDialog/index.js.map +1 -1
  109. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +1 -1
  110. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -1
  111. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts +8 -0
  112. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.d.ts.map +1 -0
  113. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js +56 -0
  114. package/dist/components/UnsavedChangesConfirmationDialog/UnsavedChangesConfirmationDialog.js.map +1 -0
  115. package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts +2 -0
  116. package/dist/components/UnsavedChangesConfirmationDialog/index.d.ts.map +1 -0
  117. package/dist/components/UnsavedChangesConfirmationDialog/index.js +15 -0
  118. package/dist/components/UnsavedChangesConfirmationDialog/index.js.map +1 -0
  119. package/dist/components/Variables/Variable.d.ts.map +1 -1
  120. package/dist/components/Variables/Variable.js +19 -12
  121. package/dist/components/Variables/Variable.js.map +1 -1
  122. package/dist/components/index.d.ts +4 -0
  123. package/dist/components/index.d.ts.map +1 -1
  124. package/dist/components/index.js +4 -0
  125. package/dist/components/index.js.map +1 -1
  126. package/dist/context/DashboardProvider/DashboardProvider.d.ts +4 -4
  127. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  128. package/dist/context/DashboardProvider/DashboardProvider.js +26 -20
  129. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  130. package/dist/context/DashboardProvider/common.d.ts +1 -1
  131. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  132. package/dist/context/DashboardProvider/common.js +1 -1
  133. package/dist/context/DashboardProvider/common.js.map +1 -1
  134. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +1 -2
  135. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -1
  136. package/dist/context/DashboardProvider/dashboard-provider-api.js +2 -4
  137. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -1
  138. package/dist/context/DashboardProvider/index.d.ts +1 -0
  139. package/dist/context/DashboardProvider/index.d.ts.map +1 -1
  140. package/dist/context/DashboardProvider/index.js.map +1 -1
  141. package/dist/context/DashboardProvider/panel-group-slice.d.ts +1 -15
  142. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  143. package/dist/context/DashboardProvider/panel-group-slice.js +38 -49
  144. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  145. package/dist/context/DashboardProvider/panel-slice.d.ts +0 -9
  146. package/dist/context/DashboardProvider/panel-slice.d.ts.map +1 -1
  147. package/dist/context/DashboardProvider/panel-slice.js +2 -13
  148. package/dist/context/DashboardProvider/panel-slice.js.map +1 -1
  149. package/dist/context/{TemplateVariableProvider.d.ts → TemplateVariableProvider/TemplateVariableProvider.d.ts} +0 -0
  150. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.d.ts.map +1 -0
  151. package/dist/context/{TemplateVariableProvider.js → TemplateVariableProvider/TemplateVariableProvider.js} +25 -12
  152. package/dist/context/TemplateVariableProvider/TemplateVariableProvider.js.map +1 -0
  153. package/dist/context/TemplateVariableProvider/index.d.ts +2 -0
  154. package/dist/context/TemplateVariableProvider/index.d.ts.map +1 -0
  155. package/dist/context/TemplateVariableProvider/index.js +15 -0
  156. package/dist/context/TemplateVariableProvider/index.js.map +1 -0
  157. package/dist/context/TemplateVariableProvider/query-params.d.ts +12 -0
  158. package/dist/context/TemplateVariableProvider/query-params.d.ts.map +1 -0
  159. package/dist/context/TemplateVariableProvider/query-params.js +64 -0
  160. package/dist/context/TemplateVariableProvider/query-params.js.map +1 -0
  161. package/dist/context/TemplateVariableProvider/query-params.test.d.ts +2 -0
  162. package/dist/context/TemplateVariableProvider/query-params.test.d.ts.map +1 -0
  163. package/dist/context/TemplateVariableProvider/query-params.test.js +80 -0
  164. package/dist/context/TemplateVariableProvider/query-params.test.js.map +1 -0
  165. package/dist/context/index.d.ts +1 -1
  166. package/dist/context/index.d.ts.map +1 -1
  167. package/dist/context/index.js +1 -1
  168. package/dist/context/index.js.map +1 -1
  169. package/dist/context/useDashboard.d.ts +6 -0
  170. package/dist/context/useDashboard.d.ts.map +1 -0
  171. package/dist/context/{useDashboardSpec.js → useDashboard.js} +19 -15
  172. package/dist/context/useDashboard.js.map +1 -0
  173. package/dist/test/plugin-registry.d.ts +2 -11
  174. package/dist/test/plugin-registry.d.ts.map +1 -1
  175. package/dist/test/plugin-registry.js +12 -49
  176. package/dist/test/plugin-registry.js.map +1 -1
  177. package/dist/test/render.d.ts.map +1 -1
  178. package/dist/test/render.js +6 -2
  179. package/dist/test/render.js.map +1 -1
  180. package/dist/utils/component-ids.d.ts +8 -0
  181. package/dist/utils/component-ids.d.ts.map +1 -0
  182. package/dist/utils/component-ids.js +27 -0
  183. package/dist/utils/component-ids.js.map +1 -0
  184. package/dist/views/ViewDashboard/DashboardApp.d.ts +1 -0
  185. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  186. package/dist/views/ViewDashboard/DashboardApp.js +42 -6
  187. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  188. package/dist/views/ViewDashboard/ViewDashboard.d.ts +1 -0
  189. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  190. package/dist/views/ViewDashboard/ViewDashboard.js +4 -3
  191. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  192. package/dist/views/ViewDashboard/tests/panelGroups.test.js +1 -1
  193. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -1
  194. package/package.json +5 -4
  195. package/dist/components/Dashboard.d.ts.map +0 -1
  196. package/dist/components/Dashboard.js.map +0 -1
  197. package/dist/components/DashboardToolbar.d.ts.map +0 -1
  198. package/dist/components/DashboardToolbar.js.map +0 -1
  199. package/dist/components/Panel/DeletePanelDialog.d.ts +0 -4
  200. package/dist/components/Panel/DeletePanelDialog.d.ts.map +0 -1
  201. package/dist/components/Panel/DeletePanelDialog.js.map +0 -1
  202. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +0 -1
  203. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +0 -1
  204. package/dist/context/TemplateVariableProvider.d.ts.map +0 -1
  205. package/dist/context/TemplateVariableProvider.js.map +0 -1
  206. package/dist/context/useDashboardSpec.d.ts +0 -11
  207. package/dist/context/useDashboardSpec.d.ts.map +0 -1
  208. package/dist/context/useDashboardSpec.js.map +0 -1
@@ -15,9 +15,9 @@ import { createStore, useStore } from 'zustand';
15
15
  import { devtools } from 'zustand/middleware';
16
16
  import { immer } from 'zustand/middleware/immer';
17
17
  import shallow from 'zustand/shallow';
18
- import { createContext, useContext } from 'react';
18
+ import { createContext, useCallback, useContext, useState } from 'react';
19
19
  import { createPanelGroupEditorSlice } from './panel-group-editor-slice';
20
- import { createPanelGroupSlice } from './panel-group-slice';
20
+ import { convertLayoutsToPanelGroups, createPanelGroupSlice } from './panel-group-slice';
21
21
  import { createPanelEditorSlice } from './panel-editor-slice';
22
22
  import { createPanelSlice } from './panel-slice';
23
23
  import { createDeletePanelGroupSlice } from './delete-panel-group-slice';
@@ -31,10 +31,20 @@ export function useDashboardStore(selector) {
31
31
  return useStore(store, selector, shallow);
32
32
  }
33
33
  export function DashboardProvider(props) {
34
- const { children , initialState: { dashboardSpec , isEditMode } , } = props;
35
- const { layouts , panels } = dashboardSpec;
36
- const dashboardStore = createStore()(immer(devtools((...args)=>{
37
- const [set, get] = args;
34
+ const createDashboardStore = useCallback(initStore, [
35
+ props
36
+ ]);
37
+ const [store] = useState(createDashboardStore(props)); // prevent calling createDashboardStore every time it rerenders
38
+ return /*#__PURE__*/ _jsx(DashboardContext.Provider, {
39
+ value: store,
40
+ children: props.children
41
+ });
42
+ }
43
+ function initStore(props) {
44
+ const { initialState: { dashboardResource , isEditMode } , } = props;
45
+ const { spec: { layouts , panels , duration } , metadata , } = dashboardResource;
46
+ const store = createStore()(immer(devtools((...args)=>{
47
+ const [set] = args;
38
48
  return {
39
49
  ...createPanelGroupSlice(layouts)(...args),
40
50
  ...createPanelSlice(panels)(...args),
@@ -42,29 +52,25 @@ export function DashboardProvider(props) {
42
52
  ...createDeletePanelGroupSlice(...args),
43
53
  ...createPanelEditorSlice()(...args),
44
54
  ...createDeletePanelSlice()(...args),
55
+ metadata,
45
56
  defaultTimeRange: {
46
- pastDuration: dashboardSpec.duration
57
+ pastDuration: duration
47
58
  },
48
59
  isEditMode: !!isEditMode,
49
60
  setEditMode: (isEditMode)=>set({
50
61
  isEditMode
51
62
  }),
52
- reset: ()=>{
53
- const { resetPanels , resetPanelGroups } = get();
54
- resetPanels();
55
- resetPanelGroups();
56
- },
57
- save: ()=>{
58
- const { savePanels , savePanelGroups } = get();
59
- savePanels();
60
- savePanelGroups();
63
+ setDashboard: ({ spec: { panels , layouts } })=>{
64
+ set((state)=>{
65
+ const { panelGroups , panelGroupOrder } = convertLayoutsToPanelGroups(layouts);
66
+ state.panels = panels;
67
+ state.panelGroups = panelGroups;
68
+ state.panelGroupOrder = panelGroupOrder;
69
+ });
61
70
  }
62
71
  };
63
72
  })));
64
- return /*#__PURE__*/ _jsx(DashboardContext.Provider, {
65
- value: dashboardStore,
66
- children: children
67
- });
73
+ return store;
68
74
  }
69
75
 
70
76
  //# sourceMappingURL=DashboardProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/DashboardProvider.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 { createStore, useStore } from 'zustand';\nimport type { StoreApi } from 'zustand';\nimport { devtools } from 'zustand/middleware';\nimport { immer } from 'zustand/middleware/immer';\nimport shallow from 'zustand/shallow';\nimport { createContext, useContext } from 'react';\nimport { DashboardSpec, RelativeTimeRange } from '@perses-dev/core';\nimport { createPanelGroupEditorSlice, PanelGroupEditorSlice } from './panel-group-editor-slice';\nimport { createPanelGroupSlice, PanelGroupSlice } from './panel-group-slice';\nimport { createPanelEditorSlice, PanelEditorSlice } from './panel-editor-slice';\nimport { createPanelSlice, PanelSlice } from './panel-slice';\nimport { createDeletePanelGroupSlice, DeletePanelGroupSlice } from './delete-panel-group-slice';\nimport { createDeletePanelSlice, DeletePanelSlice } from './delete-panel-slice';\n\nexport interface DashboardStoreState\n extends PanelGroupSlice,\n PanelSlice,\n PanelGroupEditorSlice,\n DeletePanelGroupSlice,\n PanelEditorSlice,\n DeletePanelSlice {\n isEditMode: boolean;\n setEditMode: (isEditMode: boolean) => void;\n defaultTimeRange: RelativeTimeRange;\n reset: () => void;\n save: () => void;\n}\n\nexport interface DashboardStoreProps {\n dashboardSpec: DashboardSpec;\n isEditMode?: boolean;\n}\n\nexport interface DashboardProviderProps {\n initialState: DashboardStoreProps;\n children?: React.ReactNode;\n}\n\nexport const DashboardContext = createContext<StoreApi<DashboardStoreState> | undefined>(undefined);\n\nexport function useDashboardStore<T>(selector: (state: DashboardStoreState) => T) {\n const store = useContext(DashboardContext);\n if (store === undefined) {\n throw new Error('No DashboardContext found. Did you forget a Provider?');\n }\n return useStore(store, selector, shallow);\n}\n\nexport function DashboardProvider(props: DashboardProviderProps) {\n const {\n children,\n initialState: { dashboardSpec, isEditMode },\n } = props;\n\n const { layouts, panels } = dashboardSpec;\n\n const dashboardStore = createStore<DashboardStoreState>()(\n immer(\n devtools((...args) => {\n const [set, get] = args;\n return {\n ...createPanelGroupSlice(layouts)(...args),\n ...createPanelSlice(panels)(...args),\n ...createPanelGroupEditorSlice(...args),\n ...createDeletePanelGroupSlice(...args),\n ...createPanelEditorSlice()(...args),\n ...createDeletePanelSlice()(...args),\n defaultTimeRange: { pastDuration: dashboardSpec.duration },\n isEditMode: !!isEditMode,\n setEditMode: (isEditMode: boolean) => set({ isEditMode }),\n reset: () => {\n const { resetPanels, resetPanelGroups } = get();\n resetPanels();\n resetPanelGroups();\n },\n save: () => {\n const { savePanels, savePanelGroups } = get();\n savePanels();\n savePanelGroups();\n },\n };\n })\n )\n );\n\n return (\n <DashboardContext.Provider value={dashboardStore as StoreApi<DashboardStoreState>}>\n {children}\n </DashboardContext.Provider>\n );\n}\n"],"names":["createStore","useStore","devtools","immer","shallow","createContext","useContext","createPanelGroupEditorSlice","createPanelGroupSlice","createPanelEditorSlice","createPanelSlice","createDeletePanelGroupSlice","createDeletePanelSlice","DashboardContext","undefined","useDashboardStore","selector","store","Error","DashboardProvider","props","children","initialState","dashboardSpec","isEditMode","layouts","panels","dashboardStore","args","set","get","defaultTimeRange","pastDuration","duration","setEditMode","reset","resetPanels","resetPanelGroups","save","savePanels","savePanelGroups","Provider","value"],"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;AAAA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,SAAS,CAAC;AAEhD,SAASC,QAAQ,QAAQ,oBAAoB,CAAC;AAC9C,SAASC,KAAK,QAAQ,0BAA0B,CAAC;AACjD,OAAOC,OAAO,MAAM,iBAAiB,CAAC;AACtC,SAASC,aAAa,EAAEC,UAAU,QAAQ,OAAO,CAAC;AAElD,SAASC,2BAA2B,QAA+B,4BAA4B,CAAC;AAChG,SAASC,qBAAqB,QAAyB,qBAAqB,CAAC;AAC7E,SAASC,sBAAsB,QAA0B,sBAAsB,CAAC;AAChF,SAASC,gBAAgB,QAAoB,eAAe,CAAC;AAC7D,SAASC,2BAA2B,QAA+B,4BAA4B,CAAC;AAChG,SAASC,sBAAsB,QAA0B,sBAAsB,CAAC;AA0BhF,OAAO,MAAMC,gBAAgB,iBAAGR,aAAa,CAA4CS,SAAS,CAAC,CAAC;AAEpG,OAAO,SAASC,iBAAiB,CAAIC,QAA2C,EAAE;IAChF,MAAMC,KAAK,GAAGX,UAAU,CAACO,gBAAgB,CAAC,AAAC;IAC3C,IAAII,KAAK,KAAKH,SAAS,EAAE;Q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ACrB,CAAC;YACDC,IAAI,EAAE,IAAM;gBACV,MAAM,EAAEC,UAAU,CAAA,EAAEC,eAAe,CAAA,EAAE,GAAGV,GAAG,EAAE,AAAC;gBAC9CS,UAAU,EAAE,CAAC;gBACbC,eAAe,EAAE,CAAC;YACpB,CAAC;SACF,CAAC;IACJ,CAAC,CAAC,CACH,CACF,AAAC;IAEF,qBACE,KAAC3B,gBAAgB,CAAC4B,QAAQ;QAACC,KAAK,EAAEf,cAAc;kBAC7CN,QAAQ;MACiB,CAC5B;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/DashboardProvider.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 { createStore, useStore } from 'zustand';\nimport type { StoreApi } from 'zustand';\nimport { devtools } from 'zustand/middleware';\nimport { immer } from 'zustand/middleware/immer';\nimport shallow from 'zustand/shallow';\nimport { createContext, useCallback, useContext, useState } from 'react';\nimport { DashboardResource, ProjectMetadata, RelativeTimeRange } from '@perses-dev/core';\nimport { createPanelGroupEditorSlice, PanelGroupEditorSlice } from './panel-group-editor-slice';\nimport { convertLayoutsToPanelGroups, createPanelGroupSlice, PanelGroupSlice } from './panel-group-slice';\nimport { createPanelEditorSlice, PanelEditorSlice } from './panel-editor-slice';\nimport { createPanelSlice, PanelSlice } from './panel-slice';\nimport { createDeletePanelGroupSlice, DeletePanelGroupSlice } from './delete-panel-group-slice';\nimport { createDeletePanelSlice, DeletePanelSlice } from './delete-panel-slice';\n\nexport interface DashboardStoreState\n extends PanelGroupSlice,\n PanelSlice,\n PanelGroupEditorSlice,\n DeletePanelGroupSlice,\n PanelEditorSlice,\n DeletePanelSlice {\n isEditMode: boolean;\n setEditMode: (isEditMode: boolean) => void;\n defaultTimeRange: RelativeTimeRange;\n setDashboard: (dashboard: DashboardResource) => void;\n metadata: ProjectMetadata;\n}\n\nexport interface DashboardStoreProps {\n dashboardResource: DashboardResource;\n isEditMode?: boolean;\n}\n\nexport interface DashboardProviderProps {\n initialState: DashboardStoreProps;\n children?: React.ReactNode;\n}\n\nexport const DashboardContext = createContext<StoreApi<DashboardStoreState> | undefined>(undefined);\n\nexport function useDashboardStore<T>(selector: (state: DashboardStoreState) => T) {\n const store = useContext(DashboardContext);\n if (store === undefined) {\n throw new Error('No DashboardContext found. Did you forget a Provider?');\n }\n return useStore(store, selector, shallow);\n}\n\nexport function DashboardProvider(props: DashboardProviderProps) {\n const createDashboardStore = useCallback(initStore, [props]);\n\n const [store] = useState(createDashboardStore(props)); // prevent calling createDashboardStore every time it rerenders\n\n return (\n <DashboardContext.Provider value={store as StoreApi<DashboardStoreState>}>\n {props.children}\n </DashboardContext.Provider>\n );\n}\n\nfunction initStore(props: DashboardProviderProps) {\n const {\n initialState: { dashboardResource, isEditMode },\n } = props;\n\n const {\n spec: { layouts, panels, duration },\n metadata,\n } = dashboardResource;\n const store = createStore<DashboardStoreState>()(\n immer(\n devtools((...args) => {\n const [set] = args;\n return {\n ...createPanelGroupSlice(layouts)(...args),\n ...createPanelSlice(panels)(...args),\n ...createPanelGroupEditorSlice(...args),\n ...createDeletePanelGroupSlice(...args),\n ...createPanelEditorSlice()(...args),\n ...createDeletePanelSlice()(...args),\n metadata,\n defaultTimeRange: { pastDuration: duration },\n isEditMode: !!isEditMode,\n setEditMode: (isEditMode: boolean) => set({ isEditMode }),\n setDashboard: ({ spec: { panels, layouts } }) => {\n set((state) => {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n state.panels = panels;\n state.panelGroups = panelGroups;\n state.panelGroupOrder = panelGroupOrder;\n });\n },\n };\n })\n )\n );\n\n return store;\n}\n"],"names":["createStore","useStore","devtools","immer","shallow","createContext","useCallback","useContext","useState","createPanelGroupEditorSlice","convertLayoutsToPanelGroups","createPanelGroupSlice","createPanelEditorSlice","createPanelSlice","createDeletePanelGroupSlice","createDeletePanelSlice","DashboardContext","undefined","useDashboardStore","selector","store","Error","DashboardProvider","props","createDashboardStore","initStore","Provider","value","children","initialState","dashboardResource","isEditMode","spec","layouts","panels","duration","metadata","args","set","defaultTimeRange","pastDuration","setEditMode","setDashboard","state","panelGroups","panelGroupOrder"],"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;AAAA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,SAAS,CAAC;AAEhD,SAASC,QAAQ,QAAQ,oBAAoB,CAAC;AAC9C,SAASC,KAAK,QAAQ,0BAA0B,CAAC;AACjD,OAAOC,OAAO,MAAM,iBAAiB,CAAC;AACtC,SAASC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,OAAO,CAAC;AAEzE,SAASC,2BAA2B,QAA+B,4BAA4B,CAAC;AAChG,SAASC,2BAA2B,EAAEC,qBAAqB,QAAyB,qBAAqB,CAAC;AAC1G,SAASC,sBAAsB,QAA0B,sBAAsB,CAAC;AAChF,SAASC,gBAAgB,QAAoB,eAAe,CAAC;AAC7D,SAASC,2BAA2B,QAA+B,4BAA4B,CAAC;AAChG,SAASC,sBAAsB,QAA0B,sBAAsB,CAAC;AA0BhF,OAAO,MAAMC,gBAAgB,iBAAGX,aAAa,CAA4CY,SAAS,CAAC,CAAC;AAEpG,OAAO,SAASC,iBAAiB,CAAIC,QAA2C,EAAE;IAChF,MAAMC,KAAK,GAAGb,UAAU,CAACS,gBAAgB,CAAC,AAAC;IAC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,IAAIyB,IAAI,CAAC;YACpC,GAAGtB,sBAAsB,EAAE,IAAIsB,IAAI,CAAC;YACpCD,QAAQ;YACRG,gBAAgB,EAAE;gBAAEC,YAAY,EAAEL,QAAQ;aAAE;YAC5CJ,UAAU,EAAE,CAAC,CAACA,UAAU;YACxBU,WAAW,EAAE,CAACV,UAAmB,GAAKO,GAAG,CAAC;oBAAEP,UAAU;iBAAE,CAAC;YACzDW,YAAY,EAAE,CAAC,EAAEV,IAAI,EAAE,EAAEE,MAAM,CAAA,EAAED,OAAO,CAAA,EAAE,CAAA,EAAE,GAAK;gBAC/CK,GAAG,CAAC,CAACK,KAAK,GAAK;oBACb,MAAM,EAAEC,WAAW,CAAA,EAAEC,eAAe,CAAA,EAAE,GAAGnC,2BAA2B,CAACuB,OAAO,CAAC,AAAC;oBAC9EU,KAAK,CAACT,MAAM,GAAGA,MAAM,CAAC;oBACtBS,KAAK,CAACC,WAAW,GAAGA,WAAW,CAAC;oBAChCD,KAAK,CAACE,eAAe,GAAGA,eAAe,CAAC;gBAC1C,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC,CAAC,CACH,CACF,AAAC;IAEF,OAAOzB,KAAK,CAAC;AACf,CAAC"}
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export declare type Middleware = [['zustand/immer', never], ['zustand/devtools', never]];
5
5
  declare global {
6
- var dashboardStoreId: number | undefined;
6
+ var dashboardStoreId: number;
7
7
  }
8
8
  /**
9
9
  * Helper function to generate unique IDs for things in the dashboard store that don't have a "natural" ID.
@@ -1 +1 @@
1
- {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/common.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,oBAAY,UAAU,GAAG,CAAC,CAAC,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC;AAEjF,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,gBAAgB,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1C;AAED;;GAEG;AACH,wBAAgB,UAAU,WAKzB"}
1
+ {"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/common.ts"],"names":[],"mappings":"AAaA;;GAEG;AACH,oBAAY,UAAU,GAAG,CAAC,CAAC,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC,CAAC;AAEjF,OAAO,CAAC,MAAM,CAAC;IAEb,IAAI,gBAAgB,EAAE,MAAM,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,UAAU,WAKzB"}
@@ -16,7 +16,7 @@
16
16
  * Helper function to generate unique IDs for things in the dashboard store that don't have a "natural" ID.
17
17
  */ export function generateId() {
18
18
  if (globalThis.dashboardStoreId === undefined) {
19
- globalThis.dashboardStoreId = -1;
19
+ globalThis.dashboardStoreId = 0;
20
20
  }
21
21
  return globalThis.dashboardStoreId++;
22
22
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/common.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\n/**\n * The middleware applied to the DashboardStore (can be used as generic argument in StateCreator).\n */\nexport type Middleware = [['zustand/immer', never], ['zustand/devtools', never]];\n\ndeclare global {\n // eslint-disable-next-line no-var\n var dashboardStoreId: number | undefined;\n}\n\n/**\n * Helper function to generate unique IDs for things in the dashboard store that don't have a \"natural\" ID.\n */\nexport function generateId() {\n if (globalThis.dashboardStoreId === undefined) {\n globalThis.dashboardStoreId = -1;\n }\n return globalThis.dashboardStoreId++;\n}\n"],"names":["generateId","globalThis","dashboardStoreId","undefined"],"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;;CAEC,GACD,AAOA;;CAEC,GACD,OAAO,SAASA,UAAU,GAAG;IAC3B,IAAIC,UAAU,CAACC,gBAAgB,KAAKC,SAAS,EAAE;QAC7CF,UAAU,CAACC,gBAAgB,GAAG,CAAC,CAAC,CAAC;IACnC,CAAC;IACD,OAAOD,UAAU,CAACC,gBAAgB,EAAE,CAAC;AACvC,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/common.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\n/**\n * The middleware applied to the DashboardStore (can be used as generic argument in StateCreator).\n */\nexport type Middleware = [['zustand/immer', never], ['zustand/devtools', never]];\n\ndeclare global {\n // eslint-disable-next-line no-var\n var dashboardStoreId: number;\n}\n\n/**\n * Helper function to generate unique IDs for things in the dashboard store that don't have a \"natural\" ID.\n */\nexport function generateId() {\n if (globalThis.dashboardStoreId === undefined) {\n globalThis.dashboardStoreId = 0;\n }\n return globalThis.dashboardStoreId++;\n}\n"],"names":["generateId","globalThis","dashboardStoreId","undefined"],"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;;CAEC,GACD,AAOA;;CAEC,GACD,OAAO,SAASA,UAAU,GAAG;IAC3B,IAAIC,UAAU,CAACC,gBAAgB,KAAKC,SAAS,EAAE;QAC7CF,UAAU,CAACC,gBAAgB,GAAG,CAAC,CAAC;IAClC,CAAC;IACD,OAAOD,UAAU,CAACC,gBAAgB,EAAE,CAAC;AACvC,CAAC"}
@@ -7,8 +7,7 @@ export declare function useEditMode(): {
7
7
  * Returns actions that can be performed on the current dashboard.
8
8
  */
9
9
  export declare function useDashboardActions(): {
10
- save: () => void;
11
- reset: () => void;
10
+ setDashboard: (dashboard: import("@perses-dev/core").DashboardResource) => void;
12
11
  openAddPanelGroup: () => void;
13
12
  openAddPanel: () => void;
14
13
  };
@@ -1 +1 @@
1
- {"version":3,"file":"dashboard-provider-api.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3F,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;;;;;;2CAapB,oBAAoB,EAAE;EAGhE;AAuBD;;GAEG;AACH,wBAAgB,mBAAmB,sEAElC;AAED;;GAEG;AACH,wBAAgB,yBAAyB;;;;;EASxC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,sFAa1D;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"}
1
+ {"version":3,"file":"dashboard-provider-api.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/dashboard-provider-api.ts"],"names":[],"mappings":"AAeA,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAE3F,wBAAgB,WAAW;;;EAE1B;AAED;;GAEG;AACH,wBAAgB,mBAAmB;;;;EAUlC;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;;;;;;2CAapB,oBAAoB,EAAE;EAGhE;AAuBD;;GAEG;AACH,wBAAgB,mBAAmB,sEAElC;AAED;;GAEG;AACH,wBAAgB,yBAAyB;;;;;EASxC;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,gBAAgB,EAAE,gBAAgB,sFAa1D;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"}
@@ -21,13 +21,11 @@ export function useEditMode() {
21
21
  /**
22
22
  * Returns actions that can be performed on the current dashboard.
23
23
  */ export function useDashboardActions() {
24
- const save = useDashboardStore((store)=>store.save);
25
- const reset = useDashboardStore((store)=>store.reset);
24
+ const setDashboard = useDashboardStore((store)=>store.setDashboard);
26
25
  const openAddPanelGroup = useDashboardStore((store)=>store.openAddPanelGroup);
27
26
  const openAddPanel = useDashboardStore((store)=>store.openAddPanel);
28
27
  return {
29
- save,
30
- reset,
28
+ setDashboard,
31
29
  openAddPanelGroup,
32
30
  openAddPanel: ()=>openAddPanel(undefined)
33
31
  };
@@ -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 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.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","save","store","reset","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,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,AAAC;IACtD,MAAME,KAAK,GAAGP,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK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AAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACkD,iBAAiB,CAAC,AAAC;IAChF,0FAA0F;IAC1F,MAAMC,WAAW,GAAGzD,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACmD,WAAW,CAAC,AAAC;IACpE,MAAMC,sBAAsB,GAAG1D,iBAAiB,CAAC,CAACM,KAAK,GAAKA,KAAK,CAACoD,sBAAsB,CAAC,AAAC;IAE1F,OAAO;QACLF,iBAAiB;QACjBC,WAAW;QACXC,sBAAsB;KACvB,CAAC;AACJ,CAAC;AAED,OAAO,SAASC,mBAAmB,GAAG;IACpC,OAAO3D,iBAAiB,CAAC,CAAC4D,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 { 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,OAAOD,iBAAiB,CAAC,C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AAC;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"}
@@ -3,4 +3,5 @@ export * from './DashboardProvider';
3
3
  export type { PanelGroupId, PanelGroupDefinition, PanelGroupItemId, PanelGroupItemLayoutId as PanelGroupLayoutId, } from './panel-group-slice';
4
4
  export type { PanelGroupEditor, PanelGroupEditorValues } from './panel-group-editor-slice';
5
5
  export type { DeletePanelDialogState } from './delete-panel-slice';
6
+ export type { PanelEditorValues } from './panel-editor-slice';
6
7
  //# 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;AACpC,YAAY,EACV,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,IAAI,kBAAkB,GAC7C,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC3F,YAAY,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,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,EACV,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,IAAI,kBAAkB,GAC7C,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EAAE,gBAAgB,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAC3F,YAAY,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,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';\nexport type {\n PanelGroupId,\n PanelGroupDefinition,\n PanelGroupItemId,\n PanelGroupItemLayoutId as PanelGroupLayoutId,\n} from './panel-group-slice';\nexport type { PanelGroupEditor, PanelGroupEditorValues } from './panel-group-editor-slice';\nexport type { DeletePanelDialogState } from './delete-panel-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
+ {"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 {\n PanelGroupId,\n PanelGroupDefinition,\n PanelGroupItemId,\n PanelGroupItemLayoutId as PanelGroupLayoutId,\n} from './panel-group-slice';\nexport type { PanelGroupEditor, PanelGroupEditorValues } from './panel-group-editor-slice';\nexport type { DeletePanelDialogState } from './delete-panel-slice';\nexport type { PanelEditorValues } from './panel-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"}
@@ -14,13 +14,6 @@ export interface PanelGroupSlice {
14
14
  * An array of panel group IDs, representing their order in the dashboard.
15
15
  */
16
16
  panelGroupOrder: PanelGroupId[];
17
- /**
18
- * previous state
19
- */
20
- previousPanelGroupState: {
21
- panelGroups: PanelGroupSlice['panelGroups'];
22
- panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'];
23
- };
24
17
  /**
25
18
  * Rearrange the order of panel groups by swapping the positions
26
19
  */
@@ -29,14 +22,6 @@ export interface PanelGroupSlice {
29
22
  * Update the item layouts for a panel group when, for example, a panel is moved or resized.
30
23
  */
31
24
  updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;
32
- /**
33
- * save
34
- */
35
- savePanelGroups: () => void;
36
- /**
37
- * reset to previous panel group states
38
- */
39
- resetPanelGroups: () => void;
40
25
  }
41
26
  export declare type PanelGroupId = number;
42
27
  export interface PanelGroupDefinition {
@@ -61,4 +46,5 @@ export interface PanelGroupItemId {
61
46
  * Curried function for creating a PanelGroupSlice.
62
47
  */
63
48
  export declare function createPanelGroupSlice(layouts: LayoutDefinition[]): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice>;
49
+ export declare function convertLayoutsToPanelGroups(layouts: LayoutDefinition[]): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'>;
64
50
  //# sourceMappingURL=panel-group-slice.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAsB,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACxE,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,uBAAuB,EAAE;QACvB,WAAW,EAAE,eAAe,CAAC,aAAa,CAAC,CAAC;QAC5C,iBAAiB,EAAE,eAAe,CAAC,iBAAiB,CAAC,CAAC;KACvD,CAAC;IAEF;;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;IAEhH;;OAEG;IACH,eAAe,EAAE,MAAM,IAAI,CAAC;IAE5B;;OAEG;IACH,gBAAgB,EAAE,MAAM,IAAI,CAAC;CAC9B;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,CAkFhE"}
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,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"}
@@ -15,58 +15,11 @@ import { generateId } from './common';
15
15
  /**
16
16
  * Curried function for creating a PanelGroupSlice.
17
17
  */ export function createPanelGroupSlice(layouts) {
18
- // Convert the initial layouts from the JSON
19
- const panelGroups = {};
20
- const panelGroupIdOrder = [];
21
- for (const layout of layouts){
22
- var ref, ref1, ref2;
23
- const itemLayouts = [];
24
- const itemPanelKeys = {};
25
- // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
26
- for (const item of layout.spec.items){
27
- const panelGroupLayoutId = generateId().toString();
28
- itemLayouts.push({
29
- i: panelGroupLayoutId,
30
- w: item.width,
31
- h: item.height,
32
- x: item.x,
33
- y: item.y
34
- });
35
- itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);
36
- }
37
- // Create the panel group and keep track of the ID order
38
- const panelGroupId = generateId();
39
- panelGroups[panelGroupId] = {
40
- id: panelGroupId,
41
- isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
42
- title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
43
- itemLayouts,
44
- itemPanelKeys
45
- };
46
- panelGroupIdOrder.push(panelGroupId);
47
- }
18
+ const { panelGroups , panelGroupOrder } = convertLayoutsToPanelGroups(layouts);
48
19
  // Return the state creator function for Zustand
49
20
  return (set)=>({
50
21
  panelGroups,
51
- panelGroupOrder: panelGroupIdOrder,
52
- previousPanelGroupState: {
53
- panelGroups,
54
- panelGroupIdOrder
55
- },
56
- savePanelGroups () {
57
- set((state)=>{
58
- state.previousPanelGroupState = {
59
- panelGroups: state.panelGroups,
60
- panelGroupIdOrder: state.panelGroupOrder
61
- };
62
- });
63
- },
64
- resetPanelGroups () {
65
- set((state)=>{
66
- state.panelGroups = state.previousPanelGroupState.panelGroups;
67
- state.panelGroupOrder = state.previousPanelGroupState.panelGroupIdOrder;
68
- });
69
- },
22
+ panelGroupOrder,
70
23
  swapPanelGroups (x, y) {
71
24
  set((state)=>{
72
25
  if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {
@@ -95,5 +48,41 @@ import { generateId } from './common';
95
48
  }
96
49
  });
97
50
  }
51
+ export function convertLayoutsToPanelGroups(layouts) {
52
+ // Convert the initial layouts from the JSON
53
+ const panelGroups = {};
54
+ const panelGroupIdOrder = [];
55
+ for (const layout of layouts){
56
+ var ref, ref1, ref2;
57
+ const itemLayouts = [];
58
+ const itemPanelKeys = {};
59
+ // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels
60
+ for (const item of layout.spec.items){
61
+ const panelGroupLayoutId = generateId().toString();
62
+ itemLayouts.push({
63
+ i: panelGroupLayoutId,
64
+ w: item.width,
65
+ h: item.height,
66
+ x: item.x,
67
+ y: item.y
68
+ });
69
+ itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);
70
+ }
71
+ // Create the panel group and keep track of the ID order
72
+ const panelGroupId = generateId();
73
+ panelGroups[panelGroupId] = {
74
+ id: panelGroupId,
75
+ isCollapsed: ((ref = layout.spec.display) === null || ref === void 0 ? void 0 : (ref1 = ref.collapse) === null || ref1 === void 0 ? void 0 : ref1.open) === false,
76
+ title: (ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : ref2.title,
77
+ itemLayouts,
78
+ itemPanelKeys
79
+ };
80
+ panelGroupIdOrder.push(panelGroupId);
81
+ }
82
+ return {
83
+ panelGroups,
84
+ panelGroupOrder: panelGroupIdOrder
85
+ };
86
+ }
98
87
 
99
88
  //# sourceMappingURL=panel-group-slice.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-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 { getPanelKeyFromRef, LayoutDefinition } from '@perses-dev/core';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * previous state\n */\n previousPanelGroupState: {\n panelGroups: PanelGroupSlice['panelGroups'];\n panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'];\n };\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n\n /**\n * save\n */\n savePanelGroups: () => void;\n\n /**\n * reset to previous panel group states\n */\n resetPanelGroups: () => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n\n previousPanelGroupState: { panelGroups, panelGroupIdOrder },\n\n savePanelGroups() {\n set((state) => {\n state.previousPanelGroupState = {\n panelGroups: state.panelGroups,\n panelGroupIdOrder: state.panelGroupOrder,\n };\n });\n },\n\n resetPanelGroups() {\n set((state) => {\n state.panelGroups = state.previousPanelGroupState.panelGroups;\n state.panelGroupOrder = state.previousPanelGroupState.panelGroupIdOrder;\n });\n },\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n"],"names":["getPanelKeyFromRef","generateId","createPanelGroupSlice","layouts","panelGroups","panelGroupIdOrder","layout","itemLayouts","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","x","y","content","panelGroupId","id","isCollapsed","display","collapse","open","title","set","panelGroupOrder","previousPanelGroupState","savePanelGroups","state","resetPanelGroups","swapPanelGroups","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","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;AAEjC,SAASA,kBAAkB,QAA0B,kBAAkB,CAAC;AAGxE,SAASC,UAAU,QAAoB,UAAU,CAAC;AAqElD;;CAEC,GACD,OAAO,SAASC,qBAAqB,CACnCC,OAA2B,EACqC;IAChE,4CAA4C;IAC5C,MAAMC,WAAW,GAAmC,EAAE,AAAC;IACvD,MAAMC,iBAAiB,GAAuC,EAAE,AAAC;IACjE,KAAK,MAAMC,MAAM,IAAIH,OAAO,CAAE;YAqBbG,GAAmB,QACzBA,IAAmB;QArB5B,MAAMC,WAAW,GAAwC,EAAE,AAAC;QAC5D,MAAMC,aAAa,GAA0C,EAAE,AAAC;QAEhE,6GAA6G;QAC7G,KAAK,MAAMC,IAAI,IAAIH,MAAM,CAACI,IAAI,CAACC,KAAK,CAAE;YACpC,MAAMC,kBAAkB,GAAGX,UAAU,EAAE,CAACY,QAAQ,EAAE,AAAC;YACnDN,WAAW,CAACO,IAAI,CAAC;gBACfC,CAAC,EAAEH,kBAAkB;gBACrBI,CAAC,EAAEP,IAAI,CAACQ,KAAK;gBACbC,CAAC,E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wBACvB,MAAM,IAAIH,KAAK,CAAC,CAAC,wBAAwB,EAAEf,YAAY,CAAC,CAAC,CAAC,CAAC;oBAC7D,CAAC;oBACDoB,KAAK,CAACpC,WAAW,GAAGA,WAAW,CAAC;gBAClC,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAA,AAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-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 { getPanelKeyFromRef, LayoutDefinition } from '@perses-dev/core';\nimport { Layout } from 'react-grid-layout';\nimport { StateCreator } from 'zustand';\nimport { generateId, Middleware } from './common';\n\n/**\n * Slice with the state of Panel Groups, as well as any actions that modify only Panel Group state.\n */\nexport interface PanelGroupSlice {\n /**\n * Panel groups indexed by their ID.\n */\n panelGroups: Record<PanelGroupId, PanelGroupDefinition>;\n\n /**\n * An array of panel group IDs, representing their order in the dashboard.\n */\n panelGroupOrder: PanelGroupId[];\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Update the item layouts for a panel group when, for example, a panel is moved or resized.\n */\n updatePanelGroupLayouts: (panelGroupId: PanelGroupId, itemLayouts: PanelGroupDefinition['itemLayouts']) => void;\n}\n\nexport type PanelGroupId = number;\n\nexport interface PanelGroupDefinition {\n id: PanelGroupId;\n isCollapsed: boolean;\n title?: string;\n itemLayouts: PanelGroupItemLayout[];\n itemPanelKeys: Record<PanelGroupItemLayoutId, string>;\n}\n\nexport interface PanelGroupItemLayout extends Layout {\n i: PanelGroupItemLayoutId;\n}\n\nexport type PanelGroupItemLayoutId = string;\n\n/**\n * Uniquely identifies an item in a PanelGroup.\n */\nexport interface PanelGroupItemId {\n panelGroupId: PanelGroupId;\n panelGroupItemLayoutId: PanelGroupItemLayoutId;\n}\n\n/**\n * Curried function for creating a PanelGroupSlice.\n */\nexport function createPanelGroupSlice(\n layouts: LayoutDefinition[]\n): StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> {\n const { panelGroups, panelGroupOrder } = convertLayoutsToPanelGroups(layouts);\n\n // Return the state creator function for Zustand\n return (set) => ({\n panelGroups,\n panelGroupOrder,\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.panelGroupOrder.length || y < 0 || y >= state.panelGroupOrder.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.panelGroupOrder[x];\n const yPanelGroup = state.panelGroupOrder[y];\n\n if (xPanelGroup === undefined || yPanelGroup === undefined) {\n throw new Error('panel group is undefined');\n }\n // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups\n [state.panelGroupOrder[x], state.panelGroupOrder[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n updatePanelGroupLayouts(panelGroupId, itemLayouts) {\n set((state) => {\n const group = state.panelGroups[panelGroupId];\n if (group === undefined) {\n throw new Error(`Cannot find panel group ${panelGroupId}`);\n }\n group.itemLayouts = itemLayouts;\n });\n },\n });\n}\n\nexport function convertLayoutsToPanelGroups(\n layouts: LayoutDefinition[]\n): Pick<PanelGroupSlice, 'panelGroups' | 'panelGroupOrder'> {\n // Convert the initial layouts from the JSON\n const panelGroups: PanelGroupSlice['panelGroups'] = {};\n const panelGroupIdOrder: PanelGroupSlice['panelGroupOrder'] = [];\n for (const layout of layouts) {\n const itemLayouts: PanelGroupDefinition['itemLayouts'] = [];\n const itemPanelKeys: PanelGroupDefinition['itemPanelKeys'] = {};\n\n // Split layout information from panel keys to make it easier to update just layouts on move/resize of panels\n for (const item of layout.spec.items) {\n const panelGroupLayoutId = generateId().toString();\n itemLayouts.push({\n i: panelGroupLayoutId,\n w: item.width,\n h: item.height,\n x: item.x,\n y: item.y,\n });\n itemPanelKeys[panelGroupLayoutId] = getPanelKeyFromRef(item.content);\n }\n\n // Create the panel group and keep track of the ID order\n const panelGroupId = generateId();\n panelGroups[panelGroupId] = {\n id: panelGroupId,\n isCollapsed: layout.spec.display?.collapse?.open === false,\n title: layout.spec.display?.title,\n itemLayouts,\n itemPanelKeys,\n };\n panelGroupIdOrder.push(panelGroupId);\n }\n return {\n panelGroups,\n panelGroupOrder: panelGroupIdOrder,\n };\n}\n"],"names":["getPanelKeyFromRef","generateId","createPanelGroupSlice","layouts","panelGroups","panelGroupOrder","convertLayoutsToPanelGroups","set","swapPanelGroups","x","y","state","length","Error","xPanelGroup","yPanelGroup","undefined","updatePanelGroupLayouts","panelGroupId","itemLayouts","group","panelGroupIdOrder","layout","itemPanelKeys","item","spec","items","panelGroupLayoutId","toString","push","i","w","width","h","height","content","id","isCollapsed","display","collapse","open","title"],"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,QAA0B,kBAAkB,CAAC;AAGxE,SAASC,UAAU,QAAoB,UAAU,CAAC;AAmDlD;;CAEC,GACD,OAAO,SAASC,qBAAqB,CACnCC,OAA2B,EACqC;IAChE,MAAM,EAAEC,WAAW,CAAA,EAAEC,eAAe,CAAA,EAAE,GAAGC,2BAA2B,CAACH,OAAO,CAAC,AAAC;IAE9E,gDAAgD;IAChD,OAAO,CAACI,GAAG,GAAM,CAAA;YACfH,WAAW;YACXC,eAAe;YAEfG,eAAe,EAACC,CAAC,EAAEC,CAAC,EAAE;gBACpBH,GAAG,CAAC,CAACI,KAAK,GAAK;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CAACQ,IAAI,CAACX,YAAY,CAAC,CAAC;IACvC,CAAC;IACD,OAAO;QACLd,WAAW;QACXC,eAAe,EAAEgB,iBAAiB;KACnC,CAAC;AACJ,CAAC"}
@@ -6,15 +6,6 @@ import { Middleware } from './common';
6
6
  */
7
7
  export interface PanelSlice {
8
8
  panels: Record<string, PanelDefinition>;
9
- previousPanels: Record<string, PanelDefinition>;
10
- /**
11
- * Reset panels to previous state
12
- */
13
- resetPanels: () => void;
14
- /**
15
- * Save panels
16
- */
17
- savePanels: () => void;
18
9
  }
19
10
  /**
20
11
  * Curried function for creating the PanelSlice.
@@ -1 +1 @@
1
- {"version":3,"file":"panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACxC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAEhD;;OAEG;IACH,WAAW,EAAE,MAAM,IAAI,CAAC;IAExB;;OAEG;IACH,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,CAAC,CAiBnH"}
1
+ {"version":3,"file":"panel-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-slice.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,UAAU,CAAC,QAAQ,CAAC,GAAG,YAAY,CAAC,UAAU,EAAE,UAAU,EAAE,EAAE,EAAE,UAAU,CAAC,CAInH"}
@@ -13,19 +13,8 @@
13
13
  /**
14
14
  * Curried function for creating the PanelSlice.
15
15
  */ export function createPanelSlice(panels) {
16
- return (set)=>({
17
- panels,
18
- previousPanels: panels,
19
- resetPanels () {
20
- set((state)=>{
21
- state.panels = state.previousPanels;
22
- });
23
- },
24
- savePanels () {
25
- set((state)=>{
26
- state.previousPanels = state.panels;
27
- });
28
- }
16
+ return ()=>({
17
+ panels
29
18
  });
30
19
  }
31
20
 
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/context/DashboardProvider/panel-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 } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\n/**\n * Slice with the state of Panels, along with any actions that modify only the Panels state.\n */\nexport interface PanelSlice {\n panels: Record<string, PanelDefinition>;\n previousPanels: Record<string, PanelDefinition>;\n\n /**\n * Reset panels to previous state\n */\n resetPanels: () => void;\n\n /**\n * Save panels\n */\n savePanels: () => void;\n}\n\n/**\n * Curried function for creating the PanelSlice.\n */\nexport function createPanelSlice(panels: PanelSlice['panels']): StateCreator<PanelSlice, Middleware, [], PanelSlice> {\n return (set) => ({\n panels,\n previousPanels: panels,\n\n resetPanels() {\n set((state) => {\n state.panels = state.previousPanels;\n });\n },\n\n savePanels() {\n set((state) => {\n state.previousPanels = state.panels;\n });\n },\n });\n}\n"],"names":["createPanelSlice","panels","set","previousPanels","resetPanels","state","savePanels"],"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;AAwBjC;;CAEC,GACD,OAAO,SAASA,gBAAgB,CAACC,MAA4B,EAAwD;IACnH,OAAO,CAACC,GAAG,GAAM,CAAA;YACfD,MAAM;YACNE,cAAc,EAAEF,MAAM;YAEtBG,WAAW,IAAG;gBACZF,GAAG,CAAC,CAACG,KAAK,GAAK;oBACbA,KAAK,CAACJ,MAAM,GAAGI,KAAK,CAACF,cAAc,CAAC;gBACtC,CAAC,CAAC,CAAC;YACL,CAAC;YAEDG,UAAU,IAAG;gBACXJ,GAAG,CAAC,CAACG,KAAK,GAAK;oBACbA,KAAK,CAACF,cAAc,GAAGE,KAAK,CAACJ,MAAM,CAAC;gBACtC,CAAC,CAAC,CAAC;YACL,CAAC;SACF,CAAA,AAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-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 } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\n/**\n * Slice with the state of Panels, along with any actions that modify only the Panels state.\n */\nexport interface PanelSlice {\n panels: Record<string, PanelDefinition>;\n}\n\n/**\n * Curried function for creating the PanelSlice.\n */\nexport function createPanelSlice(panels: PanelSlice['panels']): StateCreator<PanelSlice, Middleware, [], PanelSlice> {\n return () => ({\n panels,\n });\n}\n"],"names":["createPanelSlice","panels"],"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;AAajC;;CAEC,GACD,OAAO,SAASA,gBAAgB,CAACC,MAA4B,EAAwD;IACnH,OAAO,IAAO,CAAA;YACZA,MAAM;SACP,CAAA,AAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TemplateVariableProvider.d.ts","sourceRoot":"","sources":["../../../src/context/TemplateVariableProvider/TemplateVariableProvider.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAEL,gBAAgB,EAChB,aAAa,EACb,cAAc,EAEf,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAGnF,aAAK,qBAAqB,GAAG;IAC3B,mBAAmB,EAAE,kBAAkB,EAAE,CAAC;IAC1C,aAAa,EAAE,gBAAgB,CAAC;IAChC,gBAAgB,EAAE,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,aAAa,KAAK,IAAI,CAAC;IAC7E,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;IAC5E,kBAAkB,EAAE,CAAC,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,CAAC;IACnE,sBAAsB,EAAE,CAAC,WAAW,EAAE,kBAAkB,EAAE,KAAK,IAAI,CAAC;CACrE,CAAC;AAaF,wBAAgB,yBAAyB,CAAC,aAAa,CAAC,EAAE,MAAM,EAAE,oBAqBjE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM;;;EAU/C;AAED,wBAAgB,0BAA0B;;;;;EAUzC;AAED,wBAAgB,8BAA8B,yBAG7C;AAED,wBAAgB,wBAAwB,0BAGvC;AA0FD,wBAAgB,wBAAwB,CAAC,EACvC,QAAQ,EACR,0BAA+B,GAChC,EAAE;IACD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,0BAA0B,CAAC,EAAE,kBAAkB,EAAE,CAAC;CACnD,eASA"}