@perses-dev/dashboards 0.9.0 → 0.10.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 (201) hide show
  1. package/dist/cjs/components/Dashboard.js +7 -11
  2. package/dist/cjs/components/DashboardToolbar.js +4 -4
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +13 -13
  4. package/dist/cjs/components/GridLayout/GridLayout.js +24 -21
  5. package/dist/cjs/components/GridLayout/GridTitle.js +27 -5
  6. package/dist/cjs/components/Panel/DeletePanelDialog.js +91 -0
  7. package/dist/cjs/components/Panel/Panel.js +16 -5
  8. package/dist/cjs/components/Panel/Panel.test.js +12 -4
  9. package/dist/cjs/components/Panel/PanelContent.js +3 -2
  10. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +13 -12
  11. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +8 -12
  12. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +77 -35
  13. package/dist/cjs/components/PanelDrawer/PanelPreview.js +48 -0
  14. package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +86 -0
  15. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +12 -19
  16. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +10 -31
  17. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +2 -2
  18. package/dist/cjs/components/Variables/Variable.js +19 -11
  19. package/dist/cjs/components/Variables/VariableEditor.js +207 -0
  20. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +236 -0
  21. package/dist/cjs/components/Variables/VariableEditorForm/index.js +28 -0
  22. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +88 -0
  23. package/dist/cjs/components/Variables/VariableList.js +50 -69
  24. package/dist/cjs/components/Variables/index.js +1 -0
  25. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +70 -0
  26. package/dist/cjs/context/DashboardProvider/common.js +18 -0
  27. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +71 -0
  28. package/dist/cjs/context/DashboardProvider/index.js +29 -0
  29. package/dist/cjs/context/DashboardProvider/layout-slice.js +200 -0
  30. package/dist/cjs/context/DashboardProvider/panel-editing-slice.js +156 -0
  31. package/dist/{context/DashboardAppSlice.js → cjs/context/DashboardProvider/panel-group-slice.js} +18 -25
  32. package/dist/cjs/context/DatasourceStoreProvider.js +109 -7
  33. package/dist/cjs/context/TemplateVariableProvider.js +8 -1
  34. package/dist/cjs/context/index.js +0 -2
  35. package/dist/cjs/test/testDashboard.js +13 -1
  36. package/dist/cjs/views/ViewDashboard/DashboardApp.js +6 -7
  37. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +165 -0
  38. package/dist/components/Dashboard.d.ts +1 -4
  39. package/dist/components/Dashboard.d.ts.map +1 -1
  40. package/dist/components/Dashboard.js +8 -12
  41. package/dist/components/Dashboard.js.map +1 -1
  42. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  43. package/dist/components/DashboardToolbar.js +5 -5
  44. package/dist/components/DashboardToolbar.js.map +1 -1
  45. package/dist/components/GridLayout/GridItemContent.d.ts +3 -3
  46. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  47. package/dist/components/GridLayout/GridItemContent.js +14 -14
  48. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  49. package/dist/components/GridLayout/GridLayout.d.ts +2 -3
  50. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  51. package/dist/components/GridLayout/GridLayout.js +24 -21
  52. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  53. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  54. package/dist/components/GridLayout/GridTitle.js +28 -6
  55. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  56. package/dist/components/Panel/DeletePanelDialog.d.ts +5 -0
  57. package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -0
  58. package/dist/components/Panel/DeletePanelDialog.js +80 -0
  59. package/dist/components/Panel/DeletePanelDialog.js.map +1 -0
  60. package/dist/components/Panel/Panel.d.ts +1 -1
  61. package/dist/components/Panel/Panel.d.ts.map +1 -1
  62. package/dist/components/Panel/Panel.js +17 -6
  63. package/dist/components/Panel/Panel.js.map +1 -1
  64. package/dist/components/Panel/Panel.test.js +7 -4
  65. package/dist/components/Panel/Panel.test.js.map +1 -1
  66. package/dist/components/Panel/PanelContent.d.ts +4 -1
  67. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  68. package/dist/components/Panel/PanelContent.js +3 -2
  69. package/dist/components/Panel/PanelContent.js.map +1 -1
  70. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  71. package/dist/components/PanelDrawer/PanelDrawer.js +14 -13
  72. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  73. package/dist/components/PanelDrawer/PanelDrawer.test.js +8 -12
  74. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  75. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +3 -3
  76. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  77. package/dist/components/PanelDrawer/PanelEditorForm.js +78 -36
  78. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  79. package/dist/components/PanelDrawer/PanelPreview.d.ts +4 -0
  80. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -0
  81. package/dist/components/PanelDrawer/PanelPreview.js +42 -0
  82. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -0
  83. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +4 -0
  84. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
  85. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +75 -0
  86. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
  87. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  88. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +13 -20
  89. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  90. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +10 -31
  91. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
  92. package/dist/components/TimeRangeControls/TimeRangeControls.js +3 -3
  93. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  94. package/dist/components/Variables/Variable.js +21 -13
  95. package/dist/components/Variables/Variable.js.map +1 -1
  96. package/dist/components/Variables/VariableEditor.d.ts +8 -0
  97. package/dist/components/Variables/VariableEditor.d.ts.map +1 -0
  98. package/dist/components/Variables/VariableEditor.js +196 -0
  99. package/dist/components/Variables/VariableEditor.js.map +1 -0
  100. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +8 -0
  101. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
  102. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +225 -0
  103. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
  104. package/dist/components/Variables/VariableEditorForm/index.d.ts +2 -0
  105. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
  106. package/dist/components/Variables/VariableEditorForm/index.js +15 -0
  107. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
  108. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +21 -0
  109. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
  110. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +76 -0
  111. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
  112. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  113. package/dist/components/Variables/VariableList.js +48 -72
  114. package/dist/components/Variables/VariableList.js.map +1 -1
  115. package/dist/components/Variables/index.d.ts +1 -0
  116. package/dist/components/Variables/index.d.ts.map +1 -1
  117. package/dist/components/Variables/index.js +1 -0
  118. package/dist/components/Variables/index.js.map +1 -1
  119. package/dist/context/DashboardProvider/DashboardProvider.d.ts +23 -0
  120. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -0
  121. package/dist/context/DashboardProvider/DashboardProvider.js +52 -0
  122. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -0
  123. package/dist/context/DashboardProvider/common.d.ts +5 -0
  124. package/dist/context/DashboardProvider/common.d.ts.map +1 -0
  125. package/dist/context/DashboardProvider/common.js +17 -0
  126. package/dist/context/DashboardProvider/common.js.map +1 -0
  127. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +32 -0
  128. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -0
  129. package/dist/context/DashboardProvider/dashboard-provider-api.js +56 -0
  130. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -0
  131. package/dist/context/DashboardProvider/index.d.ts +3 -0
  132. package/dist/context/DashboardProvider/index.d.ts.map +1 -0
  133. package/dist/context/DashboardProvider/index.js +16 -0
  134. package/dist/context/DashboardProvider/index.js.map +1 -0
  135. package/dist/context/DashboardProvider/layout-slice.d.ts +57 -0
  136. package/dist/context/DashboardProvider/layout-slice.d.ts.map +1 -0
  137. package/dist/context/DashboardProvider/layout-slice.js +196 -0
  138. package/dist/context/DashboardProvider/layout-slice.js.map +1 -0
  139. package/dist/context/DashboardProvider/panel-editing-slice.d.ts +70 -0
  140. package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +1 -0
  141. package/dist/context/DashboardProvider/panel-editing-slice.js +152 -0
  142. package/dist/context/DashboardProvider/panel-editing-slice.js.map +1 -0
  143. package/dist/context/DashboardProvider/panel-group-slice.d.ts +15 -0
  144. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -0
  145. package/dist/context/DashboardProvider/panel-group-slice.js +32 -0
  146. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -0
  147. package/dist/context/DatasourceStoreProvider.d.ts +10 -2
  148. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  149. package/dist/context/DatasourceStoreProvider.js +111 -9
  150. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  151. package/dist/context/TemplateVariableProvider.d.ts +2 -0
  152. package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
  153. package/dist/context/TemplateVariableProvider.js +8 -1
  154. package/dist/context/TemplateVariableProvider.js.map +1 -1
  155. package/dist/context/index.d.ts +0 -2
  156. package/dist/context/index.d.ts.map +1 -1
  157. package/dist/context/index.js +0 -2
  158. package/dist/context/index.js.map +1 -1
  159. package/dist/test/plugin-registry.d.ts +2 -2
  160. package/dist/test/plugin-registry.d.ts.map +1 -1
  161. package/dist/test/plugin-registry.js.map +1 -1
  162. package/dist/test/testDashboard.d.ts.map +1 -1
  163. package/dist/test/testDashboard.js +13 -1
  164. package/dist/test/testDashboard.js.map +1 -1
  165. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  166. package/dist/views/ViewDashboard/DashboardApp.js +6 -7
  167. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  168. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +2 -0
  169. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +1 -0
  170. package/dist/views/ViewDashboard/tests/panelGroups.test.js +158 -0
  171. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -0
  172. package/package.json +4 -4
  173. package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +0 -40
  174. package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +0 -38
  175. package/dist/cjs/components/PanelDrawer/panel-editor-model.js +0 -140
  176. package/dist/cjs/context/DashboardAppSlice.js +0 -57
  177. package/dist/cjs/context/DashboardProvider.js +0 -128
  178. package/dist/cjs/context/LayoutsSlice.js +0 -55
  179. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +0 -7
  180. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +0 -1
  181. package/dist/components/PanelDrawer/PanelSpecEditor.js +0 -34
  182. package/dist/components/PanelDrawer/PanelSpecEditor.js.map +0 -1
  183. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +0 -8
  184. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +0 -1
  185. package/dist/components/PanelDrawer/PanelTypeSelect.js +0 -34
  186. package/dist/components/PanelDrawer/PanelTypeSelect.js.map +0 -1
  187. package/dist/components/PanelDrawer/panel-editor-model.d.ts +0 -27
  188. package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +0 -1
  189. package/dist/components/PanelDrawer/panel-editor-model.js +0 -133
  190. package/dist/components/PanelDrawer/panel-editor-model.js.map +0 -1
  191. package/dist/context/DashboardAppSlice.d.ts +0 -26
  192. package/dist/context/DashboardAppSlice.d.ts.map +0 -1
  193. package/dist/context/DashboardAppSlice.js.map +0 -1
  194. package/dist/context/DashboardProvider.d.ts +0 -36
  195. package/dist/context/DashboardProvider.d.ts.map +0 -1
  196. package/dist/context/DashboardProvider.js +0 -107
  197. package/dist/context/DashboardProvider.js.map +0 -1
  198. package/dist/context/LayoutsSlice.d.ts +0 -12
  199. package/dist/context/LayoutsSlice.d.ts.map +0 -1
  200. package/dist/context/LayoutsSlice.js +0 -43
  201. package/dist/context/LayoutsSlice.js.map +0 -1
@@ -0,0 +1,23 @@
1
+ /// <reference types="react" />
2
+ import type { StoreApi } from 'zustand';
3
+ import { DashboardSpec, DurationString } from '@perses-dev/core';
4
+ import { PanelGroupSlice } from './panel-group-slice';
5
+ import { LayoutSlice } from './layout-slice';
6
+ import { PanelEditorSlice } from './panel-editing-slice';
7
+ export interface DashboardStoreState extends PanelGroupSlice, LayoutSlice, PanelEditorSlice {
8
+ defaultTimeRange: DurationString;
9
+ isEditMode: boolean;
10
+ setEditMode: (isEditMode: boolean) => void;
11
+ }
12
+ export interface DashboardStoreProps {
13
+ dashboardSpec: DashboardSpec;
14
+ isEditMode?: boolean;
15
+ }
16
+ export interface DashboardProviderProps {
17
+ initialState: DashboardStoreProps;
18
+ children?: React.ReactNode;
19
+ }
20
+ export declare const DashboardContext: import("react").Context<StoreApi<DashboardStoreState> | undefined>;
21
+ export declare function useDashboardStore<T>(selector: (state: DashboardStoreState) => T): T;
22
+ export declare function DashboardProvider(props: DashboardProviderProps): JSX.Element;
23
+ //# sourceMappingURL=DashboardProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DashboardProvider.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/DashboardProvider.tsx"],"names":[],"mappings":";AAcA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAKxC,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACjE,OAAO,EAAyB,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAqB,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAA0B,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEjF,MAAM,WAAW,mBAAoB,SAAQ,eAAe,EAAE,WAAW,EAAE,gBAAgB;IACzF,gBAAgB,EAAE,cAAc,CAAC;IACjC,UAAU,EAAE,OAAO,CAAC;IACpB,WAAW,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,mBAAmB;IAClC,aAAa,EAAE,aAAa,CAAC;IAC7B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,mBAAmB,CAAC;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,eAAO,MAAM,gBAAgB,oEAAsE,CAAC;AAEpG,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,mBAAmB,KAAK,CAAC,KAM/E;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,eA6B9D"}
@@ -0,0 +1,52 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { createStore, useStore } from 'zustand';
15
+ import { devtools } from 'zustand/middleware';
16
+ import { immer } from 'zustand/middleware/immer';
17
+ import shallow from 'zustand/shallow';
18
+ import { createContext, useContext } from 'react';
19
+ import { createPanelGroupSlice } from './panel-group-slice';
20
+ import { createLayoutSlice } from './layout-slice';
21
+ import { createPanelEditorSlice } from './panel-editing-slice';
22
+ export const DashboardContext = /*#__PURE__*/ createContext(undefined);
23
+ export function useDashboardStore(selector) {
24
+ const store = useContext(DashboardContext);
25
+ if (store === undefined) {
26
+ throw new Error('No DashboardContext found. Did you forget a Provider?');
27
+ }
28
+ return useStore(store, selector, shallow);
29
+ }
30
+ export function DashboardProvider(props) {
31
+ const { children , initialState: { dashboardSpec , isEditMode } , } = props;
32
+ const { layouts , panels } = dashboardSpec;
33
+ const dashboardStore = createStore()(immer(devtools((...args)=>{
34
+ const [set] = args;
35
+ return {
36
+ ...createPanelGroupSlice(...args),
37
+ ...createLayoutSlice(layouts)(...args),
38
+ ...createPanelEditorSlice(panels)(...args),
39
+ defaultTimeRange: dashboardSpec.duration,
40
+ isEditMode: !!isEditMode,
41
+ setEditMode: (isEditMode)=>set({
42
+ isEditMode
43
+ })
44
+ };
45
+ })));
46
+ return /*#__PURE__*/ _jsx(DashboardContext.Provider, {
47
+ value: dashboardStore,
48
+ children: children
49
+ });
50
+ }
51
+
52
+ //# sourceMappingURL=DashboardProvider.js.map
@@ -0,0 +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, DurationString } from '@perses-dev/core';\nimport { createPanelGroupSlice, PanelGroupSlice } from './panel-group-slice';\nimport { createLayoutSlice, LayoutSlice } from './layout-slice';\nimport { createPanelEditorSlice, PanelEditorSlice } from './panel-editing-slice';\n\nexport interface DashboardStoreState extends PanelGroupSlice, LayoutSlice, PanelEditorSlice {\n defaultTimeRange: DurationString;\n isEditMode: boolean;\n setEditMode: (isEditMode: boolean) => 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] = args;\n return {\n ...createPanelGroupSlice(...args),\n ...createLayoutSlice(layouts)(...args),\n ...createPanelEditorSlice(panels)(...args),\n defaultTimeRange: dashboardSpec.duration,\n isEditMode: !!isEditMode,\n setEditMode: (isEditMode: boolean) => set({ isEditMode }),\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","createPanelGroupSlice","createLayoutSlice","createPanelEditorSlice","DashboardContext","undefined","useDashboardStore","selector","store","Error","DashboardProvider","props","children","initialState","dashboardSpec","isEditMode","layouts","panels","dashboardStore","args","set","defaultTimeRange","duration","setEditMode","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,qBAAqB,QAAyB,qBAAqB,CAAC;AAC7E,SAASC,iBAAiB,QAAqB,gBAAgB,CAAC;AAChE,SAASC,sBAAsB,QAA0B,uBAAuB,CAAC;AAkBjF,OAAO,MAAMC,gBAAgB,iBAAGL,aAAa,CAA4CM,SAAS,CAAC,CAAC;AAEpG,OAAO,SAASC,iBAAiB,CAAIC,QAA2C,EAAE;IAChF,MAAMC,KAAK,GAAGR,UAAU,CAACI,gBAAgB,CAAC,AAAC;IAC3C,IAAII,KAAK,KAAKH,SAAS,EAAE;QACvB,MAAM,IAAII,KAAK,CAAC,uDAAuD,CAAC,CAAC;IAC3E,CAAC;IACD,OAAOd,QAAQ,CAACa,KAAK,EAAED,QAAQ,EAAET,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,OAAO,SAASY,iBAAiB,CAACC,KAA6B,EAAE;IAC/D,MAAM,EACJC,QAAQ,CAAA,EACRC,YAAY,EAAE,EAAEC,aAAa,CAAA,EAAEC,UAAU,CAAA,EAAE,CAAA,IAC5C,GAAGJ,KAAK,AAAC;IAEV,MAAM,EAAEK,OAAO,CAAA,EAAEC,MAAM,CAAA,EAAE,GAAGH,aAAa,AAAC;IAE1C,MAAMI,cAAc,GAAGxB,WAAW,EAAuB,CACvDG,KAAK,CACHD,QAAQ,CAAC,CAAIuB,GAAAA,IAAI,GAAK;QACpB,MAAM,CAACC,GAAG,CAAC,GAAGD,IAAI,AAAC;QACnB,OAAO;YACL,GAAGlB,qBAAqB,IAAIkB,IAAI,CAAC;YACjC,GAAGjB,iBAAiB,CAACc,OAAO,CAAC,IAAIG,IAAI,CAAC;YACtC,GAAGhB,sBAAsB,CAACc,MAAM,CAAC,IAAIE,IAAI,CAAC;YAC1CE,gBAAgB,EAAEP,aAAa,CAACQ,QAAQ;YACxCP,UAAU,EAAE,CAAC,CAACA,UAAU;YACxBQ,WAAW,EAAE,CAACR,UAAmB,GAAKK,GAAG,CAAC;oBAAEL,UAAU;iBAAE,CAAC;SAC1D,CAAC;IACJ,CAAC,CAAC,CACH,CACF,AAAC;IAEF,qBACE,KAACX,gBAAgB,CAACoB,QAAQ;QAACC,KAAK,EAAEP,cAAc;kBAC7CN,QAAQ;MACiB,CAC5B;AACJ,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * The middleware applied to the DashboardStore (can be used as generic argument in StateCreator).
3
+ */
4
+ export declare type Middleware = [['zustand/immer', never], ['zustand/devtools', never]];
5
+ //# sourceMappingURL=common.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,17 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ /**
14
+ * The middleware applied to the DashboardStore (can be used as generic argument in StateCreator).
15
+ */ export { };
16
+
17
+ //# sourceMappingURL=common.js.map
@@ -0,0 +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"],"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;;CAEC,GACD,WAAiF"}
@@ -0,0 +1,32 @@
1
+ export declare function useEditMode(): {
2
+ isEditMode: boolean;
3
+ setEditMode: (isEditMode: boolean) => void;
4
+ };
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;
12
+ };
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;
19
+ closeDeletePanelGroupDialog: () => void;
20
+ };
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;
29
+ closeDeletePanelDialog: () => void;
30
+ };
31
+ export declare function useDefaultTimeRange(): import("@perses-dev/core").DurationString;
32
+ //# sourceMappingURL=dashboard-provider-api.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,56 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { useDashboardStore } from './DashboardProvider';
14
+ export function useEditMode() {
15
+ return useDashboardStore(({ isEditMode , setEditMode })=>({
16
+ isEditMode,
17
+ setEditMode
18
+ }));
19
+ }
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
+ }));
29
+ }
30
+ export function usePanelGroupDialog() {
31
+ return useDashboardStore(({ panelGroupDialog , openPanelGroupDialog , closePanelGroupDialog , deletePanelGroupDialog , openDeletePanelGroupDialog , closeDeletePanelGroupDialog , })=>({
32
+ panelGroupDialog,
33
+ openPanelGroupDialog,
34
+ closePanelGroupDialog,
35
+ deletePanelGroupDialog,
36
+ openDeletePanelGroupDialog,
37
+ closeDeletePanelGroupDialog
38
+ }));
39
+ }
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
+ }));
51
+ }
52
+ export function useDefaultTimeRange() {
53
+ return useDashboardStore((state)=>state.defaultTimeRange);
54
+ }
55
+
56
+ //# sourceMappingURL=dashboard-provider-api.js.map
@@ -0,0 +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;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,iBAAiB,QAAQ,qBAAqB,CAAC;AAExD,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,OAAO,SAASC,UAAU,GAAG;IAC3B,OAAOJ,iBAAiB,CACtB,CAAC,EAAEK,OAAO,CAAA,EAAEC,eAAe,CAAA,EAAEC,gBAAgB,CAAA,EAAEC,gBAAgB,CAAA,EAAEC,eAAe,CAAA,EAAEC,gBAAgB,CAAA,EAAE,GAAM,CAAA;YACxGL,OAAO;YACPC,eAAe;YACfC,gBAAgB;YAChBC,gBAAgB;YAChBC,eAAe;YACfC,gBAAgB;SACjB,CAAA,AAAC,CACH,CAAC;AACJ,CAAC;AAED,OAAO,SAASC,mBAAmB,GAAG;IACpC,OAAOX,iBAAiB,CACtB,CAAC,EACCY,gBAAgB,CAAA,EAChBC,oBAAoB,CAAA,EACpBC,qBAAqB,CAAA,EACrBC,sBAAsB,CAAA,EACtBC,0BAA0B,CAAA,EAC1BC,2BAA2B,CAAA,IAC5B,GAAM,CAAA;YACLL,gBAAgB;YAChBC,oBAAoB;YACpBC,qBAAqB;YACrBC,sBAAsB;YACtBC,0BAA0B;YAC1BC,2BAA2B;SAC5B,CAAA,AAAC,CACH,CAAC;AACJ,CAAC;AAED,OAAO,SAASC,SAAS,GAAG;IAC1B,OAAOlB,iBAAiB,CACtB,CAAC,EACCmB,MAAM,CAAA,EACNC,WAAW,CAAA,EACXC,QAAQ,CAAA,EACRC,SAAS,CAAA,EACTC,iBAAiB,CAAA,EACjBC,YAAY,CAAA,EACZC,qBAAqB,CAAA,EACrBC,sBAAsB,CAAA,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"}
@@ -0,0 +1,3 @@
1
+ export * from './dashboard-provider-api';
2
+ export * from './DashboardProvider';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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"}
@@ -0,0 +1,16 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ export * from './dashboard-provider-api';
14
+ export * from './DashboardProvider';
15
+
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,57 @@
1
+ import { GridItemDefinition, LayoutDefinition } from '@perses-dev/core';
2
+ import { StateCreator } from 'zustand';
3
+ import { Middleware } from './common';
4
+ import { PanelEditorSlice } from './panel-editing-slice';
5
+ export interface LayoutSlice {
6
+ layouts: PanelGroupDefinition[];
7
+ /**
8
+ * Given a LayoutItem location, returns the panel's unique key at that location.
9
+ */
10
+ getPanelKey: (layoutItem: LayoutItem) => string;
11
+ /**
12
+ * Add a panel with the specified key to an existing group.
13
+ */
14
+ addPanelToGroup: (panelKey: string, groupIndex: number) => void;
15
+ /**
16
+ * Move an existing Panel to a new panel group.
17
+ */
18
+ movePanelToGroup: (layoutItem: LayoutItem, newGroupIndex: number) => void;
19
+ /**
20
+ * Updates an existing panel group to, for example, change its display properties.
21
+ */
22
+ updatePanelGroup: (layout: Omit<PanelGroupDefinition, 'id'>, groupIndex?: number) => void;
23
+ /**
24
+ * Rearrange the order of panel groups by swapping the positions
25
+ */
26
+ swapPanelGroups: (xIndex: number, yIndex: number) => void;
27
+ /**
28
+ * Delete panel group and all the panels within the group
29
+ */
30
+ deletePanelGroup: (groupIndex: number) => void;
31
+ /**
32
+ * Delete panel in panel group
33
+ */
34
+ deletePanelInPanelGroup: (layoutItem: LayoutItem) => void;
35
+ /**
36
+ * Map panel to panel groups
37
+ */
38
+ mapPanelToPanelGroups: () => Record<string, PanelGroupDefinition['id'][]>;
39
+ }
40
+ export interface PanelGroupDefinition {
41
+ id: number;
42
+ items: GridItemDefinition[];
43
+ isCollapsed?: boolean;
44
+ title?: string;
45
+ }
46
+ /**
47
+ * The location of an item (e.g. a Panel) in layouts.
48
+ */
49
+ export interface LayoutItem {
50
+ groupIndex: number;
51
+ itemIndex: number;
52
+ }
53
+ /**
54
+ * Curried function for creating a LayoutEditorSlice.
55
+ */
56
+ export declare function createLayoutSlice(layouts: LayoutDefinition[]): StateCreator<LayoutSlice & PanelEditorSlice, Middleware, [], LayoutSlice>;
57
+ //# sourceMappingURL=layout-slice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layout-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/layout-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAsC,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAC5G,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,oBA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,0 +1,196 @@
1
+ // Copyright 2022 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ import { createPanelRef, getPanelKeyFromRef } from '@perses-dev/core';
14
+ /**
15
+ * Curried function for creating a LayoutEditorSlice.
16
+ */ export function createLayoutSlice(layouts) {
17
+ // Return the state creator function for Zustand that uses the layouts provided as initial state
18
+ let id = -1;
19
+ function createPanelGroupId() {
20
+ id++;
21
+ return id;
22
+ }
23
+ var ref;
24
+ return (set, get)=>{
25
+ return {
26
+ layouts: layouts.map((layout)=>{
27
+ var ref1, ref2, ref3;
28
+ return {
29
+ ...layout,
30
+ id: createPanelGroupId(),
31
+ title: (ref1 = layout.spec.display) === null || ref1 === void 0 ? void 0 : ref1.title,
32
+ isCollapsed: (ref = !((ref2 = layout.spec.display) === null || ref2 === void 0 ? void 0 : (ref3 = ref2.collapse) === null || ref3 === void 0 ? void 0 : ref3.open)) !== null && ref !== void 0 ? ref : false,
33
+ items: layout.spec.items
34
+ };
35
+ }),
36
+ getPanelKey ({ groupIndex , itemIndex }) {
37
+ const { layouts } = get();
38
+ const group = findGroup(layouts, groupIndex);
39
+ const item = findItem(group, itemIndex);
40
+ return getPanelKeyFromRef(item.content);
41
+ },
42
+ addPanelToGroup (panelKey, groupIndex) {
43
+ const { layouts } = get();
44
+ const group = findGroup(layouts, groupIndex);
45
+ const gridItem = {
46
+ x: 0,
47
+ y: getYForNewRow(group),
48
+ width: 12,
49
+ height: 6,
50
+ content: createPanelRef(panelKey)
51
+ };
52
+ set((state)=>{
53
+ var ref;
54
+ (ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.items.push(gridItem);
55
+ });
56
+ },
57
+ movePanelToGroup ({ groupIndex , itemIndex }, newGroupIndex) {
58
+ const { layouts } = get();
59
+ // Find the existing item to make sure it exists
60
+ const group = findGroup(layouts, groupIndex);
61
+ const item = findItem(group, itemIndex);
62
+ // Find the new group and figure out where a new row should go
63
+ const newGroup = findGroup(layouts, newGroupIndex);
64
+ const newGroupY = getYForNewRow(newGroup);
65
+ set((state)=>{
66
+ var // Remove the item from its current group
67
+ ref, // Add a new item to the new group
68
+ ref1;
69
+ (ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.items.splice(itemIndex, 1);
70
+ (ref1 = state.layouts[newGroupIndex]) === null || ref1 === void 0 ? void 0 : ref1.items.push({
71
+ x: 0,
72
+ y: newGroupY,
73
+ width: item.width,
74
+ height: item.height,
75
+ content: item.content
76
+ });
77
+ });
78
+ },
79
+ // TODO: Maybe combine this into some kind of groupEditor state
80
+ updatePanelGroup (next, groupIndex) {
81
+ set((state)=>{
82
+ if (groupIndex === undefined) {
83
+ state.layouts.unshift({
84
+ ...next,
85
+ id: createPanelGroupId()
86
+ });
87
+ } else {
88
+ const layout = state.layouts[groupIndex];
89
+ if (layout === undefined) {
90
+ throw new Error(`No layout at index ${groupIndex}`);
91
+ }
92
+ state.layouts[groupIndex] = {
93
+ ...next,
94
+ id: layout.id
95
+ };
96
+ }
97
+ });
98
+ },
99
+ swapPanelGroups (x, y) {
100
+ set((state)=>{
101
+ if (x < 0 || x >= state.layouts.length || y < 0 || y >= state.layouts.length) {
102
+ throw new Error('index out of bound');
103
+ }
104
+ const xPanelGroup = state.layouts[x];
105
+ const yPanelGroup = state.layouts[y];
106
+ if (xPanelGroup === undefined || yPanelGroup === undefined) {
107
+ throw new Error('panel group is undefined');
108
+ }
109
+ // assign yPanelGroup to layouts[x] and assign xGroup to layouts[y], swapping two panel groups
110
+ [state.layouts[x], state.layouts[y]] = [
111
+ yPanelGroup,
112
+ xPanelGroup
113
+ ];
114
+ });
115
+ },
116
+ deletePanelInPanelGroup ({ groupIndex , itemIndex }) {
117
+ set((state)=>{
118
+ const group = state.layouts[groupIndex];
119
+ if (group === undefined) {
120
+ throw new Error(`No panel group found: ${groupIndex}`);
121
+ }
122
+ // remove panel from panel group
123
+ group.items.splice(itemIndex, 1);
124
+ });
125
+ },
126
+ deletePanelGroup (groupIndex) {
127
+ const { layouts , deletePanels } = get();
128
+ const group = layouts[groupIndex];
129
+ if (group === undefined) {
130
+ throw new Error(`No panel group found: ${groupIndex}`);
131
+ }
132
+ // remove panels from group first
133
+ const panelsToBeDeleted = [];
134
+ for(let i = 0; i < group.items.length; i++){
135
+ panelsToBeDeleted.push({
136
+ groupIndex,
137
+ itemIndex: i
138
+ });
139
+ }
140
+ deletePanels(panelsToBeDeleted);
141
+ // remove group from state.layouts
142
+ set((state)=>{
143
+ state.layouts.splice(groupIndex, 1);
144
+ });
145
+ },
146
+ // Return an object that maps each panel to the groups it belongs
147
+ mapPanelToPanelGroups () {
148
+ const map = {}; // { panel key: [group ids] }
149
+ get().layouts.forEach((group)=>{
150
+ // for each panel in a group, add the group id to map[panelKey]
151
+ group.items.forEach((panel)=>{
152
+ const panelKey = getPanelKeyFromRef(panel.content);
153
+ if (map[panelKey]) {
154
+ var ref;
155
+ (ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.push(group.id);
156
+ } else {
157
+ map[panelKey] = [
158
+ group.id
159
+ ];
160
+ }
161
+ });
162
+ });
163
+ return map;
164
+ }
165
+ };
166
+ };
167
+ }
168
+ // Helper to find a group and throw if not found
169
+ function findGroup(layouts, groupIndex) {
170
+ const group = layouts[groupIndex];
171
+ if (group === undefined) {
172
+ throw new Error(`No layout at index ${groupIndex}`);
173
+ }
174
+ return group;
175
+ }
176
+ // Helper to get an item in a group and throw if not found
177
+ function findItem(group, itemIndex) {
178
+ const item = group.items[itemIndex];
179
+ if (item === undefined) {
180
+ throw new Error(`No grid item found at position ${itemIndex}`);
181
+ }
182
+ return item;
183
+ }
184
+ // Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present
185
+ function getYForNewRow(group) {
186
+ let newRowY = 0;
187
+ for (const item of group.items){
188
+ const itemMaxY = item.y + item.height;
189
+ if (itemMaxY > newRowY) {
190
+ newRowY = itemMaxY;
191
+ }
192
+ }
193
+ return newRowY;
194
+ }
195
+
196
+ //# sourceMappingURL=layout-slice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/layout-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 { createPanelRef, getPanelKeyFromRef, GridItemDefinition, LayoutDefinition } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\nimport { PanelEditorSlice } from './panel-editing-slice';\n\nexport interface LayoutSlice {\n layouts: PanelGroupDefinition[];\n\n /**\n * Given a LayoutItem location, returns the panel's unique key at that location.\n */\n getPanelKey: (layoutItem: LayoutItem) => string;\n\n /**\n * Add a panel with the specified key to an existing group.\n */\n addPanelToGroup: (panelKey: string, groupIndex: number) => void;\n\n /**\n * Move an existing Panel to a new panel group.\n */\n movePanelToGroup: (layoutItem: LayoutItem, newGroupIndex: number) => void;\n\n /**\n * Updates an existing panel group to, for example, change its display properties.\n */\n updatePanelGroup: (layout: Omit<PanelGroupDefinition, 'id'>, groupIndex?: number) => void;\n\n /**\n * Rearrange the order of panel groups by swapping the positions\n */\n swapPanelGroups: (xIndex: number, yIndex: number) => void;\n\n /**\n * Delete panel group and all the panels within the group\n */\n deletePanelGroup: (groupIndex: number) => void;\n\n /**\n * Delete panel in panel group\n */\n deletePanelInPanelGroup: (layoutItem: LayoutItem) => void;\n\n /**\n * Map panel to panel groups\n */\n mapPanelToPanelGroups: () => Record<string, PanelGroupDefinition['id'][]>;\n}\n\nexport interface PanelGroupDefinition {\n id: number;\n items: GridItemDefinition[];\n isCollapsed?: boolean;\n title?: string;\n}\n\n/**\n * The location of an item (e.g. a Panel) in layouts.\n */\nexport interface LayoutItem {\n groupIndex: number;\n itemIndex: number;\n}\n\n/**\n * Curried function for creating a LayoutEditorSlice.\n */\nexport function createLayoutSlice(\n layouts: LayoutDefinition[]\n): StateCreator<LayoutSlice & PanelEditorSlice, Middleware, [], LayoutSlice> {\n // Return the state creator function for Zustand that uses the layouts provided as initial state\n let id = -1;\n\n function createPanelGroupId() {\n id++;\n return id;\n }\n\n return (set, get) => ({\n layouts: layouts.map((layout) => ({\n ...layout,\n id: createPanelGroupId(),\n title: layout.spec.display?.title,\n isCollapsed: !layout.spec.display?.collapse?.open ?? false,\n items: layout.spec.items,\n })),\n\n getPanelKey({ groupIndex, itemIndex }) {\n const { layouts } = get();\n const group = findGroup(layouts, groupIndex);\n const item = findItem(group, itemIndex);\n return getPanelKeyFromRef(item.content);\n },\n\n addPanelToGroup(panelKey, groupIndex) {\n const { layouts } = get();\n const group = findGroup(layouts, groupIndex);\n const gridItem: GridItemDefinition = {\n x: 0,\n y: getYForNewRow(group),\n width: 12,\n height: 6,\n content: createPanelRef(panelKey),\n };\n set((state) => {\n state.layouts[groupIndex]?.items.push(gridItem);\n });\n },\n\n movePanelToGroup({ groupIndex, itemIndex }, newGroupIndex) {\n const { layouts } = get();\n\n // Find the existing item to make sure it exists\n const group = findGroup(layouts, groupIndex);\n const item = findItem(group, itemIndex);\n\n // Find the new group and figure out where a new row should go\n const newGroup = findGroup(layouts, newGroupIndex);\n const newGroupY = getYForNewRow(newGroup);\n\n set((state) => {\n // Remove the item from its current group\n state.layouts[groupIndex]?.items.splice(itemIndex, 1);\n\n // Add a new item to the new group\n state.layouts[newGroupIndex]?.items.push({\n x: 0,\n y: newGroupY,\n width: item.width,\n height: item.height,\n content: item.content,\n });\n });\n },\n\n // TODO: Maybe combine this into some kind of groupEditor state\n updatePanelGroup(next, groupIndex) {\n set((state) => {\n if (groupIndex === undefined) {\n state.layouts.unshift({ ...next, id: createPanelGroupId() });\n } else {\n const layout = state.layouts[groupIndex];\n if (layout === undefined) {\n throw new Error(`No layout at index ${groupIndex}`);\n }\n state.layouts[groupIndex] = { ...next, id: layout.id };\n }\n });\n },\n\n swapPanelGroups(x, y) {\n set((state) => {\n if (x < 0 || x >= state.layouts.length || y < 0 || y >= state.layouts.length) {\n throw new Error('index out of bound');\n }\n const xPanelGroup = state.layouts[x];\n const yPanelGroup = state.layouts[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.layouts[x], state.layouts[y]] = [yPanelGroup, xPanelGroup];\n });\n },\n\n deletePanelInPanelGroup({ groupIndex, itemIndex }) {\n set((state) => {\n const group = state.layouts[groupIndex];\n if (group === undefined) {\n throw new Error(`No panel group found: ${groupIndex}`);\n }\n // remove panel from panel group\n group.items.splice(itemIndex, 1);\n });\n },\n\n deletePanelGroup(groupIndex) {\n const { layouts, deletePanels } = get();\n const group = layouts[groupIndex];\n if (group === undefined) {\n throw new Error(`No panel group found: ${groupIndex}`);\n }\n\n // remove panels from group first\n const panelsToBeDeleted: LayoutItem[] = [];\n for (let i = 0; i < group.items.length; i++) {\n panelsToBeDeleted.push({ groupIndex, itemIndex: i });\n }\n deletePanels(panelsToBeDeleted);\n\n // remove group from state.layouts\n set((state) => {\n state.layouts.splice(groupIndex, 1);\n });\n },\n\n // Return an object that maps each panel to the groups it belongs\n mapPanelToPanelGroups() {\n const map: Record<string, PanelGroupDefinition['id'][]> = {}; // { panel key: [group ids] }\n get().layouts.forEach((group) => {\n // for each panel in a group, add the group id to map[panelKey]\n group.items.forEach((panel) => {\n const panelKey = getPanelKeyFromRef(panel.content);\n if (map[panelKey]) {\n map[panelKey]?.push(group.id);\n } else {\n map[panelKey] = [group.id];\n }\n });\n });\n return map;\n },\n });\n}\n\n// Helper to find a group and throw if not found\nfunction findGroup(layouts: PanelGroupDefinition[], groupIndex: number) {\n const group = layouts[groupIndex];\n if (group === undefined) {\n throw new Error(`No layout at index ${groupIndex}`);\n }\n return group;\n}\n\n// Helper to get an item in a group and throw if not found\nfunction findItem(group: PanelGroupDefinition, itemIndex: number) {\n const item = group.items[itemIndex];\n if (item === undefined) {\n throw new Error(`No grid item found at position ${itemIndex}`);\n }\n return item;\n}\n\n// Given a Grid, will find the Y coordinate for adding a new row to the grid, taking into account the items present\nfunction getYForNewRow(group: PanelGroupDefinition) {\n let newRowY = 0;\n for (const item of group.items) {\n const itemMaxY = item.y + item.height;\n if (itemMaxY > newRowY) {\n newRowY = itemMaxY;\n }\n }\n return newRowY;\n}\n"],"names":["createPanelRef","getPanelKeyFromRef","createLayoutSlice","layouts","id","createPanelGroupId","set","get","map","layout","title","spec","display","isCollapsed","collapse","open","items","getPanelKey","groupIndex","itemIndex","group","findGroup","item","findItem","content","addPanelToGroup","panelKey","gridItem","x","y","getYForNewRow","width","height","state","push","movePanelToGroup","newGroupIndex","newGroup","newGroupY","splice","updatePanelGroup","next","undefined","unshift","Error","swapPanelGroups","length","xPanelGroup","yPanelGroup","deletePanelInPanelGroup","deletePanelGroup","deletePanels","panelsToBeDeleted","i","mapPanelToPanelGroups","forEach","panel","newRowY","itemMaxY"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,cAAc,EAAEC,kBAAkB,QAA8C,kBAAkB,CAAC;AAgE5G;;CAEC,GACD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J,KAAK,CAAE;QAC9B,MAAM0C,QAAQ,GAAGpC,IAAI,CAACO,CAAC,GAAGP,IAAI,CAACU,MAAM,AAAC;QACtC,IAAI0B,QAAQ,GAAGD,OAAO,EAAE;YACtBA,OAAO,GAAGC,QAAQ,CAAC;QACrB,CAAC;IACH,CAAC;IACD,OAAOD,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,70 @@
1
+ import { PanelDefinition, UnknownSpec } from '@perses-dev/core';
2
+ import { StateCreator } from 'zustand';
3
+ import { Middleware } from './common';
4
+ import { LayoutSlice, LayoutItem } from './layout-slice';
5
+ export interface PanelEditorSlice {
6
+ panels: Record<string, PanelDefinition>;
7
+ deletePanelDialog?: DeletePanelDialog;
8
+ /**
9
+ * State for the panel editor when its open, otherwise undefined when it's closed.
10
+ */
11
+ panelEditor?: PanelEditorState;
12
+ /**
13
+ * Edit an existing panel by providing its layout coordinates.
14
+ */
15
+ editPanel: (item: LayoutItem) => void;
16
+ /**
17
+ * Add a new Panel to a panel group.
18
+ */
19
+ addPanel: (initialGroup: number) => void;
20
+ /**
21
+ * Delete panels
22
+ */
23
+ deletePanels: (panels: LayoutItem[]) => void;
24
+ /**
25
+ * Open delete panel dialog
26
+ */
27
+ openDeletePanelDialog: (item: LayoutItem) => void;
28
+ /**
29
+ * Close delete panel dialog
30
+ */
31
+ closeDeletePanelDialog: () => void;
32
+ }
33
+ export interface DeletePanelDialog {
34
+ panelKey: string;
35
+ panelName: string;
36
+ layoutItem: LayoutItem;
37
+ }
38
+ export interface PanelEditorState {
39
+ /**
40
+ * Whether we're adding a new panel, or editing an existing panel.
41
+ */
42
+ mode: 'Add' | 'Edit';
43
+ /**
44
+ * Initial values for the things that can be edited about a panel.
45
+ */
46
+ initialValues: PanelEditorValues;
47
+ /**
48
+ * Applies changes, but doesn't close the editor.
49
+ */
50
+ applyChanges: (next: PanelEditorValues) => void;
51
+ /**
52
+ * Close the editor.
53
+ */
54
+ close: () => void;
55
+ }
56
+ /**
57
+ * Panel values that can be edited in the panel editor.
58
+ */
59
+ export interface PanelEditorValues {
60
+ name: string;
61
+ description: string;
62
+ groupIndex: number;
63
+ kind: string;
64
+ spec: UnknownSpec;
65
+ }
66
+ /**
67
+ * Curried function for creating the PanelEditorSlice.
68
+ */
69
+ export declare function createPanelEditorSlice(panels: PanelEditorSlice['panels']): StateCreator<PanelEditorSlice & LayoutSlice, Middleware, [], PanelEditorSlice>;
70
+ //# sourceMappingURL=panel-editing-slice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel-editing-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-editing-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,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEzD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IACxC,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC;;OAEG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAE/B;;OAEG;IACH,SAAS,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IAEtC;;OAEG;IACH,QAAQ,EAAE,CAAC,YAAY,EAAE,MAAM,KAAK,IAAI,CAAC;IAEzC;;OAEG;IACH,YAAY,EAAE,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,IAAI,CAAC;IAE7C;;OAEG;IACH,qBAAqB,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAC;IAElD;;OAEG;IACH,sBAAsB,EAAE,MAAM,IAAI,CAAC;CACpC;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,C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