@perses-dev/dashboards 0.8.1 → 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 (258) hide show
  1. package/dist/cjs/components/Dashboard.js +25 -14
  2. package/dist/cjs/components/DashboardToolbar.js +148 -20
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +25 -19
  4. package/dist/cjs/components/GridLayout/GridLayout.js +92 -27
  5. package/dist/cjs/components/GridLayout/GridTitle.js +91 -31
  6. package/dist/cjs/components/GridLayout/index.js +18 -19
  7. package/dist/cjs/components/Panel/DeletePanelDialog.js +91 -0
  8. package/dist/cjs/components/Panel/Panel.js +156 -55
  9. package/dist/cjs/components/Panel/Panel.test.js +58 -41
  10. package/dist/cjs/components/Panel/PanelContent.js +41 -12
  11. package/dist/cjs/components/Panel/index.js +16 -17
  12. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +84 -108
  13. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +87 -92
  14. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +194 -0
  15. package/dist/cjs/components/PanelDrawer/PanelPreview.js +48 -0
  16. package/dist/cjs/components/PanelDrawer/index.js +28 -0
  17. package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +86 -0
  18. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +121 -39
  19. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +74 -88
  20. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +120 -38
  21. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +42 -27
  22. package/dist/cjs/components/TimeRangeControls/index.js +16 -17
  23. package/dist/cjs/components/Variables/Variable.js +195 -36
  24. package/dist/cjs/components/Variables/VariableEditor.js +207 -0
  25. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +236 -0
  26. package/dist/cjs/components/Variables/VariableEditorForm/index.js +28 -0
  27. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +88 -0
  28. package/dist/cjs/components/Variables/VariableList.js +81 -13
  29. package/dist/cjs/components/Variables/index.js +18 -18
  30. package/dist/cjs/components/index.js +21 -21
  31. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +70 -0
  32. package/dist/cjs/context/DashboardProvider/common.js +18 -0
  33. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +71 -0
  34. package/dist/cjs/context/DashboardProvider/index.js +29 -0
  35. package/dist/cjs/context/DashboardProvider/layout-slice.js +200 -0
  36. package/dist/cjs/context/DashboardProvider/panel-editing-slice.js +156 -0
  37. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +38 -0
  38. package/dist/cjs/context/DatasourceStoreProvider.js +170 -0
  39. package/dist/cjs/context/QueryStringProvider.js +69 -15
  40. package/dist/cjs/context/TemplateVariableProvider.js +135 -136
  41. package/dist/cjs/context/TimeRangeProvider.js +79 -30
  42. package/dist/cjs/context/index.js +20 -22
  43. package/dist/cjs/css/styles.js +43 -39
  44. package/dist/cjs/index.js +19 -20
  45. package/dist/cjs/test/dashboard-provider.js +51 -0
  46. package/dist/cjs/test/index.js +18 -18
  47. package/dist/cjs/test/plugin-registry.js +52 -25
  48. package/dist/cjs/test/render.js +25 -22
  49. package/dist/cjs/test/setup-tests.js +4 -2
  50. package/dist/cjs/test/testDashboard.js +203 -107
  51. package/dist/cjs/utils/functions.js +9 -5
  52. package/dist/cjs/views/ViewDashboard/DashboardApp.js +49 -23
  53. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +62 -31
  54. package/dist/cjs/views/ViewDashboard/index.js +16 -17
  55. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +165 -0
  56. package/dist/cjs/views/index.js +16 -17
  57. package/dist/components/Dashboard.d.ts +1 -4
  58. package/dist/components/Dashboard.d.ts.map +1 -1
  59. package/dist/components/Dashboard.js +34 -1
  60. package/dist/components/Dashboard.js.map +1 -0
  61. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  62. package/dist/components/DashboardToolbar.js +154 -1
  63. package/dist/components/DashboardToolbar.js.map +1 -0
  64. package/dist/components/GridLayout/GridItemContent.d.ts +3 -3
  65. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  66. package/dist/components/GridLayout/GridItemContent.js +35 -1
  67. package/dist/components/GridLayout/GridItemContent.js.map +1 -0
  68. package/dist/components/GridLayout/GridLayout.d.ts +2 -3
  69. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  70. package/dist/components/GridLayout/GridLayout.js +102 -1
  71. package/dist/components/GridLayout/GridLayout.js.map +1 -0
  72. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  73. package/dist/components/GridLayout/GridTitle.js +99 -1
  74. package/dist/components/GridLayout/GridTitle.js.map +1 -0
  75. package/dist/components/GridLayout/index.js +16 -1
  76. package/dist/components/GridLayout/index.js.map +1 -0
  77. package/dist/components/Panel/DeletePanelDialog.d.ts +5 -0
  78. package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -0
  79. package/dist/components/Panel/DeletePanelDialog.js +80 -0
  80. package/dist/components/Panel/DeletePanelDialog.js.map +1 -0
  81. package/dist/components/Panel/Panel.d.ts +1 -1
  82. package/dist/components/Panel/Panel.d.ts.map +1 -1
  83. package/dist/components/Panel/Panel.js +181 -1
  84. package/dist/components/Panel/Panel.js.map +1 -0
  85. package/dist/components/Panel/Panel.test.js +74 -1
  86. package/dist/components/Panel/Panel.test.js.map +1 -0
  87. package/dist/components/Panel/PanelContent.d.ts +5 -4
  88. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  89. package/dist/components/Panel/PanelContent.js +41 -1
  90. package/dist/components/Panel/PanelContent.js.map +1 -0
  91. package/dist/components/Panel/index.js +15 -1
  92. package/dist/components/Panel/index.js.map +1 -0
  93. package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
  94. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  95. package/dist/components/PanelDrawer/PanelDrawer.js +96 -1
  96. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
  97. package/dist/components/PanelDrawer/PanelDrawer.test.js +99 -1
  98. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
  99. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
  100. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
  101. package/dist/components/PanelDrawer/PanelEditorForm.js +184 -0
  102. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
  103. package/dist/components/PanelDrawer/PanelPreview.d.ts +4 -0
  104. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -0
  105. package/dist/components/PanelDrawer/PanelPreview.js +42 -0
  106. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -0
  107. package/dist/components/PanelDrawer/index.d.ts +2 -0
  108. package/dist/components/PanelDrawer/index.d.ts.map +1 -0
  109. package/dist/components/PanelDrawer/index.js +15 -0
  110. package/dist/components/PanelDrawer/index.js.map +1 -0
  111. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +4 -0
  112. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
  113. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +75 -0
  114. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
  115. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  116. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +131 -1
  117. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
  118. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +74 -1
  119. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
  120. package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
  121. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
  122. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
  123. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
  124. package/dist/components/TimeRangeControls/index.js +15 -1
  125. package/dist/components/TimeRangeControls/index.js.map +1 -0
  126. package/dist/components/Variables/Variable.d.ts.map +1 -1
  127. package/dist/components/Variables/Variable.js +210 -1
  128. package/dist/components/Variables/Variable.js.map +1 -0
  129. package/dist/components/Variables/VariableEditor.d.ts +8 -0
  130. package/dist/components/Variables/VariableEditor.d.ts.map +1 -0
  131. package/dist/components/Variables/VariableEditor.js +196 -0
  132. package/dist/components/Variables/VariableEditor.js.map +1 -0
  133. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +8 -0
  134. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
  135. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +225 -0
  136. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
  137. package/dist/components/Variables/VariableEditorForm/index.d.ts +2 -0
  138. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
  139. package/dist/components/Variables/VariableEditorForm/index.js +15 -0
  140. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
  141. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +21 -0
  142. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
  143. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +76 -0
  144. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
  145. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  146. package/dist/components/Variables/VariableList.js +84 -1
  147. package/dist/components/Variables/VariableList.js.map +1 -0
  148. package/dist/components/Variables/index.d.ts +1 -0
  149. package/dist/components/Variables/index.d.ts.map +1 -1
  150. package/dist/components/Variables/index.js +17 -1
  151. package/dist/components/Variables/index.js.map +1 -0
  152. package/dist/components/index.d.ts +1 -0
  153. package/dist/components/index.d.ts.map +1 -1
  154. package/dist/components/index.js +20 -1
  155. package/dist/components/index.js.map +1 -0
  156. package/dist/context/DashboardProvider/DashboardProvider.d.ts +23 -0
  157. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -0
  158. package/dist/context/DashboardProvider/DashboardProvider.js +52 -0
  159. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -0
  160. package/dist/context/DashboardProvider/common.d.ts +5 -0
  161. package/dist/context/DashboardProvider/common.d.ts.map +1 -0
  162. package/dist/context/DashboardProvider/common.js +17 -0
  163. package/dist/context/DashboardProvider/common.js.map +1 -0
  164. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +32 -0
  165. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -0
  166. package/dist/context/DashboardProvider/dashboard-provider-api.js +56 -0
  167. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -0
  168. package/dist/context/DashboardProvider/index.d.ts +3 -0
  169. package/dist/context/DashboardProvider/index.d.ts.map +1 -0
  170. package/dist/context/DashboardProvider/index.js +16 -0
  171. package/dist/context/DashboardProvider/index.js.map +1 -0
  172. package/dist/context/DashboardProvider/layout-slice.d.ts +57 -0
  173. package/dist/context/DashboardProvider/layout-slice.d.ts.map +1 -0
  174. package/dist/context/DashboardProvider/layout-slice.js +196 -0
  175. package/dist/context/DashboardProvider/layout-slice.js.map +1 -0
  176. package/dist/context/DashboardProvider/panel-editing-slice.d.ts +70 -0
  177. package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +1 -0
  178. package/dist/context/DashboardProvider/panel-editing-slice.js +152 -0
  179. package/dist/context/DashboardProvider/panel-editing-slice.js.map +1 -0
  180. package/dist/context/DashboardProvider/panel-group-slice.d.ts +15 -0
  181. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -0
  182. package/dist/context/DashboardProvider/panel-group-slice.js +32 -0
  183. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -0
  184. package/dist/context/DatasourceStoreProvider.d.ts +24 -0
  185. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
  186. package/dist/context/DatasourceStoreProvider.js +166 -0
  187. package/dist/context/DatasourceStoreProvider.js.map +1 -0
  188. package/dist/context/QueryStringProvider.js +40 -1
  189. package/dist/context/QueryStringProvider.js.map +1 -0
  190. package/dist/context/TemplateVariableProvider.d.ts +8 -3
  191. package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
  192. package/dist/context/TemplateVariableProvider.js +199 -1
  193. package/dist/context/TemplateVariableProvider.js.map +1 -0
  194. package/dist/context/TimeRangeProvider.js +72 -1
  195. package/dist/context/TimeRangeProvider.js.map +1 -0
  196. package/dist/context/index.d.ts +3 -4
  197. package/dist/context/index.d.ts.map +1 -1
  198. package/dist/context/index.js +19 -1
  199. package/dist/context/index.js.map +1 -0
  200. package/dist/css/styles.js +186 -1
  201. package/dist/css/styles.js.map +1 -0
  202. package/dist/index.js +17 -1
  203. package/dist/index.js.map +1 -0
  204. package/dist/test/dashboard-provider.d.ts +19 -0
  205. package/dist/test/dashboard-provider.d.ts.map +1 -0
  206. package/dist/test/dashboard-provider.js +40 -0
  207. package/dist/test/dashboard-provider.js.map +1 -0
  208. package/dist/test/index.d.ts +1 -0
  209. package/dist/test/index.d.ts.map +1 -1
  210. package/dist/test/index.js +17 -1
  211. package/dist/test/index.js.map +1 -0
  212. package/dist/test/plugin-registry.d.ts +3 -4
  213. package/dist/test/plugin-registry.d.ts.map +1 -1
  214. package/dist/test/plugin-registry.js +74 -1
  215. package/dist/test/plugin-registry.js.map +1 -0
  216. package/dist/test/render.d.ts +1 -2
  217. package/dist/test/render.d.ts.map +1 -1
  218. package/dist/test/render.js +34 -1
  219. package/dist/test/render.js.map +1 -0
  220. package/dist/test/setup-tests.js +18 -1
  221. package/dist/test/setup-tests.js.map +1 -0
  222. package/dist/test/testDashboard.d.ts.map +1 -1
  223. package/dist/test/testDashboard.js +286 -1
  224. package/dist/test/testDashboard.js.map +1 -0
  225. package/dist/utils/functions.js +17 -1
  226. package/dist/utils/functions.js.map +1 -0
  227. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  228. package/dist/views/ViewDashboard/DashboardApp.js +55 -1
  229. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
  230. package/dist/views/ViewDashboard/ViewDashboard.d.ts +2 -0
  231. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  232. package/dist/views/ViewDashboard/ViewDashboard.js +79 -1
  233. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
  234. package/dist/views/ViewDashboard/index.js +15 -1
  235. package/dist/views/ViewDashboard/index.js.map +1 -0
  236. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +2 -0
  237. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +1 -0
  238. package/dist/views/ViewDashboard/tests/panelGroups.test.js +158 -0
  239. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -0
  240. package/dist/views/index.js +15 -1
  241. package/dist/views/index.js.map +1 -0
  242. package/package.json +13 -7
  243. package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
  244. package/dist/cjs/context/DashboardAppSlice.js +0 -45
  245. package/dist/cjs/context/DashboardProvider.js +0 -98
  246. package/dist/cjs/context/LayoutsSlice.js +0 -42
  247. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
  248. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
  249. package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
  250. package/dist/context/DashboardAppSlice.d.ts +0 -26
  251. package/dist/context/DashboardAppSlice.d.ts.map +0 -1
  252. package/dist/context/DashboardAppSlice.js +0 -1
  253. package/dist/context/DashboardProvider.d.ts +0 -34
  254. package/dist/context/DashboardProvider.d.ts.map +0 -1
  255. package/dist/context/DashboardProvider.js +0 -1
  256. package/dist/context/LayoutsSlice.d.ts +0 -12
  257. package/dist/context/LayoutsSlice.d.ts.map +0 -1
  258. package/dist/context/LayoutsSlice.js +0 -1
@@ -0,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,OAAO,SAASC,iBAAiB,CAC/BC,OAA2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Q,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,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,IAAI,EAAE,KAAK,GAAG,MAAM,CAAC;IAErB;;OAEG;IACH,aAAa,EAAE,iBAAiB,CAAC;IAEjC;;OAEG;IACH,YAAY,EAAE,CAAC,IAAI,EAAE,iBAAiB,KAAK,IAAI,CAAC;IAEhD;;OAEG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;CACnB;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,gBAAgB,CAAC,QAAQ,CAAC,GACjC,YAAY,CAAC,gBAAgB,GAAG,WAAW,EAAE,UAAU,EAAE,EAAE,EAAE,gBAAgB,CAAC,CAyHhF"}
@@ -0,0 +1,152 @@
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 { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
14
+ /**
15
+ * Curried function for creating the PanelEditorSlice.
16
+ */ export function createPanelEditorSlice(panels) {
17
+ // Return the state creator function for Zustand that uses the panels provided as intitial state
18
+ return (set, get)=>{
19
+ return {
20
+ panels,
21
+ panelEditor: undefined,
22
+ editPanel (item) {
23
+ const { panels , getPanelKey } = get();
24
+ // Ask the layout store for the panel key at that location
25
+ const panelKey = getPanelKey(item);
26
+ // Find the panel to edit
27
+ const panelToEdit = panels[panelKey];
28
+ if (panelToEdit === undefined) {
29
+ throw new Error(`Cannot find Panel with key '${panelKey}'`);
30
+ }
31
+ var _description;
32
+ const editorState = {
33
+ mode: 'Edit',
34
+ initialValues: {
35
+ name: panelToEdit.spec.display.name,
36
+ description: (_description = panelToEdit.spec.display.description) !== null && _description !== void 0 ? _description : '',
37
+ groupIndex: item.groupIndex,
38
+ kind: panelToEdit.spec.plugin.kind,
39
+ spec: panelToEdit.spec.plugin.spec
40
+ },
41
+ applyChanges: (next)=>{
42
+ const panelDefinititon = createPanelDefinitionFromEditorValues(next);
43
+ set((state)=>{
44
+ state.panels[panelKey] = panelDefinititon;
45
+ });
46
+ // Move the panel to another group if it changed
47
+ if (next.groupIndex !== item.groupIndex) {
48
+ get().movePanelToGroup(item, next.groupIndex);
49
+ }
50
+ },
51
+ close: ()=>{
52
+ set((state)=>{
53
+ state.panelEditor = undefined;
54
+ });
55
+ }
56
+ };
57
+ // Open the editor with the new state
58
+ set((state)=>{
59
+ state.panelEditor = editorState;
60
+ });
61
+ },
62
+ addPanel (initialGroup) {
63
+ const editorState = {
64
+ mode: 'Add',
65
+ initialValues: {
66
+ name: '',
67
+ description: '',
68
+ groupIndex: initialGroup,
69
+ // TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to
70
+ // set a smarter default here?
71
+ kind: '',
72
+ spec: {}
73
+ },
74
+ applyChanges: (next)=>{
75
+ const panelDef = createPanelDefinitionFromEditorValues(next);
76
+ const panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);
77
+ set((state)=>{
78
+ state.panels[panelKey] = panelDef;
79
+ });
80
+ get().addPanelToGroup(panelKey, next.groupIndex);
81
+ },
82
+ close: ()=>{
83
+ set((state)=>{
84
+ state.panelEditor = undefined;
85
+ });
86
+ }
87
+ };
88
+ // Open the editor with the new state
89
+ set((state)=>{
90
+ state.panelEditor = editorState;
91
+ });
92
+ },
93
+ deletePanels (items) {
94
+ const { mapPanelToPanelGroups , deletePanelInPanelGroup , getPanelKey } = get();
95
+ const map = mapPanelToPanelGroups();
96
+ // get panel key first before deleting panel from panel group since getPanelKey relies on index
97
+ const panels = items.map((panel)=>{
98
+ return {
99
+ ...panel,
100
+ panelKey: getPanelKey(panel)
101
+ };
102
+ });
103
+ panels.forEach(({ panelKey , ...panel })=>{
104
+ var ref;
105
+ deletePanelInPanelGroup(panel);
106
+ // make sure panel is only referenced in one panel group before deleting it from state.panels
107
+ if (map[panelKey] && ((ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.length) === 1) {
108
+ set((state)=>{
109
+ delete state.panels[panelKey];
110
+ });
111
+ }
112
+ });
113
+ },
114
+ openDeletePanelDialog (item) {
115
+ set((state)=>{
116
+ var ref;
117
+ const { panels , getPanelKey } = get();
118
+ const panelKey = getPanelKey(item);
119
+ var _name;
120
+ state.deletePanelDialog = {
121
+ panelKey,
122
+ panelName: (_name = (ref = panels[panelKey]) === null || ref === void 0 ? void 0 : ref.spec.display.name) !== null && _name !== void 0 ? _name : '',
123
+ layoutItem: item
124
+ };
125
+ });
126
+ },
127
+ closeDeletePanelDialog () {
128
+ set((state)=>{
129
+ state.deletePanelDialog = undefined;
130
+ });
131
+ }
132
+ };
133
+ };
134
+ }
135
+ // Helper to create PanelDefinitions when saving
136
+ function createPanelDefinitionFromEditorValues(editorValues) {
137
+ return {
138
+ kind: 'Panel',
139
+ spec: {
140
+ display: {
141
+ name: editorValues.name,
142
+ description: editorValues.description !== '' ? editorValues.description : undefined
143
+ },
144
+ plugin: {
145
+ kind: editorValues.kind,
146
+ spec: editorValues.spec
147
+ }
148
+ }
149
+ };
150
+ }
151
+
152
+ //# sourceMappingURL=panel-editing-slice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-editing-slice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PanelDefinition, UnknownSpec } from '@perses-dev/core';\nimport { StateCreator } from 'zustand';\nimport { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';\nimport { Middleware } from './common';\nimport { LayoutSlice, LayoutItem } from './layout-slice';\n\nexport interface PanelEditorSlice {\n panels: Record<string, PanelDefinition>;\n deletePanelDialog?: DeletePanelDialog;\n /**\n * State for the panel editor when its open, otherwise undefined when it's closed.\n */\n panelEditor?: PanelEditorState;\n\n /**\n * Edit an existing panel by providing its layout coordinates.\n */\n editPanel: (item: LayoutItem) => void;\n\n /**\n * Add a new Panel to a panel group.\n */\n addPanel: (initialGroup: number) => void;\n\n /**\n * Delete panels\n */\n deletePanels: (panels: LayoutItem[]) => void;\n\n /**\n * Open delete panel dialog\n */\n openDeletePanelDialog: (item: LayoutItem) => void;\n\n /**\n * Close delete panel dialog\n */\n closeDeletePanelDialog: () => void;\n}\n\nexport interface DeletePanelDialog {\n panelKey: string;\n panelName: string;\n layoutItem: LayoutItem;\n}\n\nexport interface PanelEditorState {\n /**\n * Whether we're adding a new panel, or editing an existing panel.\n */\n mode: 'Add' | 'Edit';\n\n /**\n * Initial values for the things that can be edited about a panel.\n */\n initialValues: PanelEditorValues;\n\n /**\n * Applies changes, but doesn't close the editor.\n */\n applyChanges: (next: PanelEditorValues) => void;\n\n /**\n * Close the editor.\n */\n close: () => void;\n}\n\n/**\n * Panel values that can be edited in the panel editor.\n */\nexport interface PanelEditorValues {\n name: string;\n description: string;\n groupIndex: number;\n kind: string;\n spec: UnknownSpec;\n}\n\n/**\n * Curried function for creating the PanelEditorSlice.\n */\nexport function createPanelEditorSlice(\n panels: PanelEditorSlice['panels']\n): StateCreator<PanelEditorSlice & LayoutSlice, Middleware, [], PanelEditorSlice> {\n // Return the state creator function for Zustand that uses the panels provided as intitial state\n return (set, get) => ({\n panels,\n\n panelEditor: undefined,\n\n editPanel(item) {\n const { panels, getPanelKey } = get();\n\n // Ask the layout store for the panel key at that location\n const panelKey = getPanelKey(item);\n\n // Find the panel to edit\n const panelToEdit = panels[panelKey];\n if (panelToEdit === undefined) {\n throw new Error(`Cannot find Panel with key '${panelKey}'`);\n }\n\n const editorState: PanelEditorState = {\n mode: 'Edit',\n initialValues: {\n name: panelToEdit.spec.display.name,\n description: panelToEdit.spec.display.description ?? '',\n groupIndex: item.groupIndex,\n kind: panelToEdit.spec.plugin.kind,\n spec: panelToEdit.spec.plugin.spec,\n },\n applyChanges: (next) => {\n const panelDefinititon = createPanelDefinitionFromEditorValues(next);\n set((state) => {\n state.panels[panelKey] = panelDefinititon;\n });\n\n // Move the panel to another group if it changed\n if (next.groupIndex !== item.groupIndex) {\n get().movePanelToGroup(item, next.groupIndex);\n }\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n addPanel(initialGroup) {\n const editorState: PanelEditorState = {\n mode: 'Add',\n initialValues: {\n name: '',\n description: '',\n groupIndex: initialGroup,\n // TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to\n // set a smarter default here?\n kind: '',\n spec: {},\n },\n applyChanges: (next) => {\n const panelDef = createPanelDefinitionFromEditorValues(next);\n const panelKey = removeWhiteSpacesAndSpecialCharacters(next.name);\n set((state) => {\n state.panels[panelKey] = panelDef;\n });\n get().addPanelToGroup(panelKey, next.groupIndex);\n },\n close: () => {\n set((state) => {\n state.panelEditor = undefined;\n });\n },\n };\n\n // Open the editor with the new state\n set((state) => {\n state.panelEditor = editorState;\n });\n },\n\n deletePanels(items: LayoutItem[]) {\n const { mapPanelToPanelGroups, deletePanelInPanelGroup, getPanelKey } = get();\n const map = mapPanelToPanelGroups();\n // get panel key first before deleting panel from panel group since getPanelKey relies on index\n const panels = items.map((panel) => {\n return { ...panel, panelKey: getPanelKey(panel) };\n });\n panels.forEach(({ panelKey, ...panel }) => {\n deletePanelInPanelGroup(panel);\n // make sure panel is only referenced in one panel group before deleting it from state.panels\n if (map[panelKey] && map[panelKey]?.length === 1) {\n set((state) => {\n delete state.panels[panelKey];\n });\n }\n });\n },\n\n openDeletePanelDialog(item: LayoutItem) {\n set((state) => {\n const { panels, getPanelKey } = get();\n const panelKey = getPanelKey(item);\n state.deletePanelDialog = {\n panelKey,\n panelName: panels[panelKey]?.spec.display.name ?? '',\n layoutItem: item,\n };\n });\n },\n\n closeDeletePanelDialog() {\n set((state) => {\n state.deletePanelDialog = undefined;\n });\n },\n });\n}\n\n// Helper to create PanelDefinitions when saving\nfunction createPanelDefinitionFromEditorValues(editorValues: PanelEditorValues): PanelDefinition {\n return {\n kind: 'Panel',\n spec: {\n display: {\n name: editorValues.name,\n description: editorValues.description !== '' ? editorValues.description : undefined,\n },\n plugin: {\n kind: editorValues.kind,\n spec: editorValues.spec,\n },\n },\n };\n}\n"],"names":["removeWhiteSpacesAndSpecialCharacters","createPanelEditorSlice","panels","set","get","panelEditor","undefined","editPanel","item","getPanelKey","panelKey","panelToEdit","Error","editorState","mode","initialValues","name","spec","display","description","groupIndex","kind","plugin","applyChanges","next","panelDefinititon","createPanelDefinitionFromEditorValues","state","movePanelToGroup","close","addPanel","initialGroup","panelDef","addPanelToGroup","deletePanels","items","mapPanelToPanelGroups","deletePanelInPanelGroup","map","panel","forEach","length","openDeletePanelDialog","deletePanelDialog","panelName","layoutItem","closeDeletePanelDialog","editorValues"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAs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CAAC9B,IAAI;aACxB;SACF;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { StateCreator } from 'zustand';
2
+ import { Middleware } from './common';
3
+ export interface PanelGroupDialog {
4
+ groupIndex?: number;
5
+ }
6
+ export interface PanelGroupSlice {
7
+ panelGroupDialog?: PanelGroupDialog;
8
+ openPanelGroupDialog: (groupIndex?: number) => void;
9
+ closePanelGroupDialog: () => void;
10
+ deletePanelGroupDialog?: PanelGroupDialog;
11
+ openDeletePanelGroupDialog: (groupIndex: number) => void;
12
+ closeDeletePanelGroupDialog: () => void;
13
+ }
14
+ export declare const createPanelGroupSlice: StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice>;
15
+ //# sourceMappingURL=panel-group-slice.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"panel-group-slice.d.ts","sourceRoot":"","sources":["../../../src/context/DashboardProvider/panel-group-slice.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAEtC,MAAM,WAAW,gBAAgB;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,eAAe;IAC9B,gBAAgB,CAAC,EAAE,gBAAgB,CAAC;IACpC,oBAAoB,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IACpD,qBAAqB,EAAE,MAAM,IAAI,CAAC;IAClC,sBAAsB,CAAC,EAAE,gBAAgB,CAAC;IAC1C,0BAA0B,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,2BAA2B,EAAE,MAAM,IAAI,CAAC;CACzC;AAED,eAAO,MAAM,qBAAqB,EAAE,YAAY,CAAC,eAAe,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe,CAiB/F,CAAC"}
@@ -0,0 +1,32 @@
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 const createPanelGroupSlice = (set)=>({
14
+ openPanelGroupDialog: (groupIndex)=>set((state)=>{
15
+ state.panelGroupDialog = {
16
+ groupIndex
17
+ };
18
+ }),
19
+ closePanelGroupDialog: ()=>set((state)=>{
20
+ state.panelGroupDialog = undefined;
21
+ }),
22
+ openDeletePanelGroupDialog: (groupIndex)=>set((state)=>{
23
+ state.deletePanelGroupDialog = {
24
+ groupIndex
25
+ };
26
+ }),
27
+ closeDeletePanelGroupDialog: ()=>set((state)=>{
28
+ state.deletePanelGroupDialog = undefined;
29
+ })
30
+ });
31
+
32
+ //# sourceMappingURL=panel-group-slice.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/context/DashboardProvider/panel-group-slice.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { StateCreator } from 'zustand';\nimport { Middleware } from './common';\n\nexport interface PanelGroupDialog {\n groupIndex?: number;\n}\n\nexport interface PanelGroupSlice {\n panelGroupDialog?: PanelGroupDialog;\n openPanelGroupDialog: (groupIndex?: number) => void;\n closePanelGroupDialog: () => void;\n deletePanelGroupDialog?: PanelGroupDialog;\n openDeletePanelGroupDialog: (groupIndex: number) => void;\n closeDeletePanelGroupDialog: () => void;\n}\n\nexport const createPanelGroupSlice: StateCreator<PanelGroupSlice, Middleware, [], PanelGroupSlice> = (set) => ({\n openPanelGroupDialog: (groupIndex?: number) =>\n set((state) => {\n state.panelGroupDialog = { groupIndex };\n }),\n closePanelGroupDialog: () =>\n set((state) => {\n state.panelGroupDialog = undefined;\n }),\n openDeletePanelGroupDialog: (groupIndex: number) =>\n set((state) => {\n state.deletePanelGroupDialog = { groupIndex };\n }),\n closeDeletePanelGroupDialog: () =>\n set((state) => {\n state.deletePanelGroupDialog = undefined;\n }),\n});\n"],"names":["createPanelGroupSlice","set","openPanelGroupDialog","groupIndex","state","panelGroupDialog","closePanelGroupDialog","undefined","openDeletePanelGroupDialog","deletePanelGroupDialog","closeDeletePanelGroupDialog"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAkBjC,OAAO,MAAMA,qBAAqB,GAAmE,CAACC,GAAG,GAAM,CAAA;QAC7GC,oBAAoB,EAAE,CAACC,UAAmB,GACxCF,GAAG,CAAC,CAACG,KAAK,GAAK;gBACbA,KAAK,CAACC,gBAAgB,GAAG;oBAAEF,UAAU;iBAAE,CAAC;YAC1C,CAAC,CAAC;QACJG,qBAAqB,EAAE,IACrBL,GAAG,CAAC,CAACG,KAAK,GAAK;gBACbA,KAAK,CAACC,gBAAgB,GAAGE,SAAS,CAAC;YACrC,CAAC,CAAC;QACJC,0BAA0B,EAAE,CAACL,UAAkB,GAC7CF,GAAG,CAAC,CAACG,KAAK,GAAK;gBACbA,KAAK,CAACK,sBAAsB,GAAG;oBAAEN,UAAU;iBAAE,CAAC;YAChD,CAAC,CAAC;QACJO,2BAA2B,EAAE,IAC3BT,GAAG,CAAC,CAACG,KAAK,GAAK;gBACbA,KAAK,CAACK,sBAAsB,GAAGF,SAAS,CAAC;YAC3C,CAAC,CAAC;KACL,CAAA,AAAC,CAAC"}
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { DashboardResource, Datasource, DatasourceSelector, GlobalDatasource } from '@perses-dev/core';
3
+ export interface DatasourceStoreProviderProps {
4
+ dashboardResource: DashboardResource;
5
+ datasourceApi: DatasourceApi;
6
+ children?: React.ReactNode;
7
+ }
8
+ export interface DatasourceApi {
9
+ getDatasource: (project: string, selector: DatasourceSelector) => Promise<{
10
+ resource: Datasource;
11
+ proxyUrl: string;
12
+ } | undefined>;
13
+ getGlobalDatasource: (selector: DatasourceSelector) => Promise<{
14
+ resource: GlobalDatasource;
15
+ proxyUrl: string;
16
+ } | undefined>;
17
+ listDatasources: (project: string, pluginKind?: string) => Promise<Datasource[]>;
18
+ listGlobalDatasources: (pluginKind?: string) => Promise<GlobalDatasource[]>;
19
+ }
20
+ /**
21
+ * A `DatasourceContext` provider that uses an external API to resolve datasource selectors.
22
+ */
23
+ export declare function DatasourceStoreProvider(props: DatasourceStoreProviderProps): JSX.Element;
24
+ //# sourceMappingURL=DatasourceStoreProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DatasourceStoreProvider.d.ts","sourceRoot":"","sources":["../../src/context/DatasourceStoreProvider.tsx"],"names":[],"mappings":";AAcA,OAAO,EACL,iBAAiB,EAEjB,UAAU,EACV,kBAAkB,EAElB,gBAAgB,EAEjB,MAAM,kBAAkB,CAAC;AAQ1B,MAAM,WAAW,4BAA4B;IAC3C,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,aAAa,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAGD,MAAM,WAAW,aAAa;IAC5B,aAAa,EAAE,CACb,OAAO,EAAE,MAAM,EACf,QAAQ,EAAE,kBAAkB,KACzB,OAAO,CAAC;QAAE,QAAQ,EAAE,UAAU,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAErE,mBAAmB,EAAE,CACnB,QAAQ,EAAE,kBAAkB,KACzB,OAAO,CAAC;QAAE,QAAQ,EAAE,gBAAgB,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,GAAG,SAAS,CAAC,CAAC;IAE3E,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;IAEjF,qBAAqB,EAAE,CAAC,UAAU,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;CAC7E;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,4BAA4B,eAkG1E"}