@perses-dev/dashboards 0.8.0 → 0.9.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 (196) hide show
  1. package/dist/cjs/components/Dashboard.js +29 -14
  2. package/dist/cjs/components/DashboardToolbar.js +148 -20
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +24 -18
  4. package/dist/cjs/components/GridLayout/GridLayout.js +88 -26
  5. package/dist/cjs/components/GridLayout/GridTitle.js +69 -31
  6. package/dist/cjs/components/GridLayout/index.js +18 -19
  7. package/dist/cjs/components/Panel/Panel.js +145 -55
  8. package/dist/cjs/components/Panel/Panel.test.js +50 -41
  9. package/dist/cjs/components/Panel/PanelContent.js +40 -12
  10. package/dist/cjs/components/Panel/index.js +16 -17
  11. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +82 -107
  12. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +91 -92
  13. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +152 -0
  14. package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +40 -0
  15. package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +38 -0
  16. package/dist/cjs/components/PanelDrawer/index.js +28 -0
  17. package/dist/cjs/components/PanelDrawer/panel-editor-model.js +140 -0
  18. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +120 -31
  19. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +90 -83
  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 +186 -35
  24. package/dist/cjs/components/Variables/VariableList.js +100 -13
  25. package/dist/cjs/components/Variables/index.js +17 -18
  26. package/dist/cjs/components/index.js +21 -21
  27. package/dist/cjs/context/DashboardAppSlice.js +43 -31
  28. package/dist/cjs/context/DashboardProvider.js +88 -58
  29. package/dist/cjs/context/DatasourceStoreProvider.js +68 -0
  30. package/dist/cjs/context/LayoutsSlice.js +40 -27
  31. package/dist/cjs/context/QueryStringProvider.js +69 -15
  32. package/dist/cjs/context/TemplateVariableProvider.js +128 -136
  33. package/dist/cjs/context/TimeRangeProvider.js +79 -30
  34. package/dist/cjs/context/index.js +22 -22
  35. package/dist/cjs/css/styles.js +43 -39
  36. package/dist/cjs/index.js +19 -20
  37. package/dist/cjs/test/dashboard-provider.js +51 -0
  38. package/dist/cjs/test/index.js +18 -18
  39. package/dist/cjs/test/plugin-registry.js +52 -25
  40. package/dist/cjs/test/render.js +25 -22
  41. package/dist/cjs/test/setup-tests.js +4 -2
  42. package/dist/cjs/test/testDashboard.js +193 -109
  43. package/dist/cjs/utils/functions.js +9 -5
  44. package/dist/cjs/views/ViewDashboard/DashboardApp.js +67 -0
  45. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +83 -0
  46. package/dist/cjs/views/ViewDashboard/index.js +28 -0
  47. package/dist/cjs/views/index.js +16 -17
  48. package/dist/components/Dashboard.js +38 -1
  49. package/dist/components/Dashboard.js.map +1 -0
  50. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  51. package/dist/components/DashboardToolbar.js +154 -1
  52. package/dist/components/DashboardToolbar.js.map +1 -0
  53. package/dist/components/GridLayout/GridItemContent.js +35 -1
  54. package/dist/components/GridLayout/GridItemContent.js.map +1 -0
  55. package/dist/components/GridLayout/GridLayout.js +99 -1
  56. package/dist/components/GridLayout/GridLayout.js.map +1 -0
  57. package/dist/components/GridLayout/GridTitle.js +77 -1
  58. package/dist/components/GridLayout/GridTitle.js.map +1 -0
  59. package/dist/components/GridLayout/index.js +16 -1
  60. package/dist/components/GridLayout/index.js.map +1 -0
  61. package/dist/components/Panel/Panel.d.ts.map +1 -1
  62. package/dist/components/Panel/Panel.js +170 -1
  63. package/dist/components/Panel/Panel.js.map +1 -0
  64. package/dist/components/Panel/Panel.test.js +71 -1
  65. package/dist/components/Panel/Panel.test.js.map +1 -0
  66. package/dist/components/Panel/PanelContent.d.ts +2 -4
  67. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  68. package/dist/components/Panel/PanelContent.js +40 -1
  69. package/dist/components/Panel/PanelContent.js.map +1 -0
  70. package/dist/components/Panel/index.js +15 -1
  71. package/dist/components/Panel/index.js.map +1 -0
  72. package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
  73. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  74. package/dist/components/PanelDrawer/PanelDrawer.js +95 -1
  75. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
  76. package/dist/components/PanelDrawer/PanelDrawer.test.js +103 -1
  77. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
  78. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
  79. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
  80. package/dist/components/PanelDrawer/PanelEditorForm.js +142 -0
  81. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
  82. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +7 -0
  83. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +1 -0
  84. package/dist/components/PanelDrawer/PanelSpecEditor.js +34 -0
  85. package/dist/components/PanelDrawer/PanelSpecEditor.js.map +1 -0
  86. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +8 -0
  87. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +1 -0
  88. package/dist/components/PanelDrawer/PanelTypeSelect.js +34 -0
  89. package/dist/components/PanelDrawer/PanelTypeSelect.js.map +1 -0
  90. package/dist/components/PanelDrawer/index.d.ts +2 -0
  91. package/dist/components/PanelDrawer/index.d.ts.map +1 -0
  92. package/dist/components/PanelDrawer/index.js +15 -0
  93. package/dist/components/PanelDrawer/index.js.map +1 -0
  94. package/dist/components/PanelDrawer/panel-editor-model.d.ts +27 -0
  95. package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +1 -0
  96. package/dist/components/PanelDrawer/panel-editor-model.js +133 -0
  97. package/dist/components/PanelDrawer/panel-editor-model.js.map +1 -0
  98. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  99. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +138 -1
  100. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
  101. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -1
  102. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
  103. package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
  104. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
  105. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
  106. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
  107. package/dist/components/TimeRangeControls/index.js +15 -1
  108. package/dist/components/TimeRangeControls/index.js.map +1 -0
  109. package/dist/components/Variables/Variable.d.ts.map +1 -1
  110. package/dist/components/Variables/Variable.js +202 -1
  111. package/dist/components/Variables/Variable.js.map +1 -0
  112. package/dist/components/Variables/VariableList.js +108 -1
  113. package/dist/components/Variables/VariableList.js.map +1 -0
  114. package/dist/components/Variables/index.js +16 -1
  115. package/dist/components/Variables/index.js.map +1 -0
  116. package/dist/components/index.d.ts +1 -0
  117. package/dist/components/index.d.ts.map +1 -1
  118. package/dist/components/index.js +20 -1
  119. package/dist/components/index.js.map +1 -0
  120. package/dist/context/DashboardAppSlice.js +45 -1
  121. package/dist/context/DashboardAppSlice.js.map +1 -0
  122. package/dist/context/DashboardProvider.d.ts +4 -2
  123. package/dist/context/DashboardProvider.d.ts.map +1 -1
  124. package/dist/context/DashboardProvider.js +107 -1
  125. package/dist/context/DashboardProvider.js.map +1 -0
  126. package/dist/context/DatasourceStoreProvider.d.ts +16 -0
  127. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
  128. package/dist/context/DatasourceStoreProvider.js +64 -0
  129. package/dist/context/DatasourceStoreProvider.js.map +1 -0
  130. package/dist/context/LayoutsSlice.js +43 -1
  131. package/dist/context/LayoutsSlice.js.map +1 -0
  132. package/dist/context/QueryStringProvider.js +40 -1
  133. package/dist/context/QueryStringProvider.js.map +1 -0
  134. package/dist/context/TemplateVariableProvider.d.ts +6 -3
  135. package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
  136. package/dist/context/TemplateVariableProvider.js +192 -1
  137. package/dist/context/TemplateVariableProvider.js.map +1 -0
  138. package/dist/context/TimeRangeProvider.js +72 -1
  139. package/dist/context/TimeRangeProvider.js.map +1 -0
  140. package/dist/context/index.d.ts +3 -2
  141. package/dist/context/index.d.ts.map +1 -1
  142. package/dist/context/index.js +21 -1
  143. package/dist/context/index.js.map +1 -0
  144. package/dist/css/styles.js +186 -1
  145. package/dist/css/styles.js.map +1 -0
  146. package/dist/index.js +17 -1
  147. package/dist/index.js.map +1 -0
  148. package/dist/test/dashboard-provider.d.ts +19 -0
  149. package/dist/test/dashboard-provider.d.ts.map +1 -0
  150. package/dist/test/dashboard-provider.js +40 -0
  151. package/dist/test/dashboard-provider.js.map +1 -0
  152. package/dist/test/index.d.ts +1 -0
  153. package/dist/test/index.d.ts.map +1 -1
  154. package/dist/test/index.js +17 -1
  155. package/dist/test/index.js.map +1 -0
  156. package/dist/test/plugin-registry.d.ts +2 -3
  157. package/dist/test/plugin-registry.d.ts.map +1 -1
  158. package/dist/test/plugin-registry.js +74 -1
  159. package/dist/test/plugin-registry.js.map +1 -0
  160. package/dist/test/render.d.ts +1 -2
  161. package/dist/test/render.d.ts.map +1 -1
  162. package/dist/test/render.js +34 -1
  163. package/dist/test/render.js.map +1 -0
  164. package/dist/test/setup-tests.js +18 -1
  165. package/dist/test/setup-tests.js.map +1 -0
  166. package/dist/test/testDashboard.d.ts.map +1 -1
  167. package/dist/test/testDashboard.js +274 -1
  168. package/dist/test/testDashboard.js.map +1 -0
  169. package/dist/utils/functions.js +17 -1
  170. package/dist/utils/functions.js.map +1 -0
  171. package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -0
  172. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -0
  173. package/dist/views/ViewDashboard/DashboardApp.js +56 -0
  174. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
  175. package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +3 -1
  176. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
  177. package/dist/views/ViewDashboard/ViewDashboard.js +79 -0
  178. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
  179. package/dist/views/ViewDashboard/index.d.ts +2 -0
  180. package/dist/views/ViewDashboard/index.d.ts.map +1 -0
  181. package/dist/views/ViewDashboard/index.js +15 -0
  182. package/dist/views/ViewDashboard/index.js.map +1 -0
  183. package/dist/views/index.js +15 -1
  184. package/dist/views/index.js.map +1 -0
  185. package/package.json +13 -7
  186. package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
  187. package/dist/cjs/views/DashboardApp.js +0 -46
  188. package/dist/cjs/views/ViewDashboard.js +0 -43
  189. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
  190. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
  191. package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
  192. package/dist/views/DashboardApp.d.ts +0 -4
  193. package/dist/views/DashboardApp.d.ts.map +0 -1
  194. package/dist/views/DashboardApp.js +0 -1
  195. package/dist/views/ViewDashboard.d.ts.map +0 -1
  196. package/dist/views/ViewDashboard.js +0 -1
@@ -1,6 +1,3 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const jsx_runtime_1 = require("react/jsx-runtime");
4
1
  // Copyright 2022 The Perses Authors
5
2
  // Licensed under the Apache License, Version 2.0 (the "License");
6
3
  // you may not use this file except in compliance with the License.
@@ -13,112 +10,90 @@ const jsx_runtime_1 = require("react/jsx-runtime");
13
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
11
  // See the License for the specific language governing permissions and
15
12
  // limitations under the License.
16
- const material_1 = require("@mui/material");
17
- const components_1 = require("@perses-dev/components");
18
- const plugin_system_1 = require("@perses-dev/plugin-system");
19
- const react_1 = require("react");
20
- const context_1 = require("../../context");
21
- const functions_1 = require("../../utils/functions");
22
- const PanelOptionsEditor_1 = require("./PanelOptionsEditor");
23
- const PanelDrawer = () => {
24
- var _a, _b, _c, _d;
25
- const { layouts } = (0, context_1.useLayouts)();
26
- const { panels, updatePanel } = (0, context_1.usePanels)();
27
- const { panelDrawer, closePanelDrawer } = (0, context_1.useDashboardApp)();
28
- let defaultPanelName = '';
29
- let defaultDescription = '';
30
- if (panelDrawer === null || panelDrawer === void 0 ? void 0 : panelDrawer.panelKey) {
31
- // editing an existing panel
32
- defaultPanelName = (_b = (_a = panels[panelDrawer.panelKey]) === null || _a === void 0 ? void 0 : _a.display.name) !== null && _b !== void 0 ? _b : '';
33
- defaultDescription = (_d = (_c = panels[panelDrawer.panelKey]) === null || _c === void 0 ? void 0 : _c.display.description) !== null && _d !== void 0 ? _d : '';
34
- }
35
- const [group, setGroup] = (0, react_1.useState)(panelDrawer === null || panelDrawer === void 0 ? void 0 : panelDrawer.groupIndex);
36
- const [panelName, setPanelName] = (0, react_1.useState)(defaultPanelName);
37
- const [panelDescription, setPanelDescription] = (0, react_1.useState)(defaultDescription);
38
- const [kind, setKind] = (0, react_1.useState)('');
39
- const [options, setOptions] = (0, react_1.useState)({});
40
- // TO DO: we might want to make the form a sub component we don't need this useEffect
41
- // currently, we need to reset the states whenever panelDrawer is reopened
42
- // since this component does not get remounted when it open/closes (otherwise we lose the animation of sliding in/out)
43
- (0, react_1.useEffect)(() => {
44
- var _a, _b, _c, _d;
45
- setGroup(panelDrawer === null || panelDrawer === void 0 ? void 0 : panelDrawer.groupIndex);
46
- if (panelDrawer === null || panelDrawer === void 0 ? void 0 : panelDrawer.panelKey) {
47
- // display panel name and description in text fields when editing an existing panel
48
- setPanelName((_b = (_a = panels[panelDrawer.panelKey]) === null || _a === void 0 ? void 0 : _a.display.name) !== null && _b !== void 0 ? _b : '');
49
- setPanelDescription((_d = (_c = panels[panelDrawer.panelKey]) === null || _c === void 0 ? void 0 : _c.display.description) !== null && _d !== void 0 ? _d : '');
50
- }
51
- else {
52
- setPanelName('');
53
- setPanelDescription('');
54
- }
55
- }, [panelDrawer, panels]);
56
- const handleGroupChange = (e) => {
57
- const { value } = e.target;
58
- // Handle string (which would be empty string but shouldn't happen since we don't allow a "None" option) by
59
- // just ignoring it
60
- if (typeof value === 'string')
61
- return;
62
- setGroup(value);
63
- };
64
- const handlePanelNameChange = (e) => {
65
- setPanelName(e.target.value);
66
- };
67
- const handlePanelDescriptionChange = (e) => {
68
- setPanelDescription(e.target.value);
69
- };
70
- const handleKindChange = (e) => {
71
- setKind(e.target.value);
72
- };
73
- const handleOptionsChange = (next) => {
74
- setOptions(next);
75
- };
76
- const handleSubmit = (e) => {
77
- e.preventDefault();
78
- if ((panelDrawer === null || panelDrawer === void 0 ? void 0 : panelDrawer.groupIndex) !== undefined && !(panelDrawer === null || panelDrawer === void 0 ? void 0 : panelDrawer.panelKey)) {
79
- addNewPanel();
80
- }
81
- else if (panelDrawer === null || panelDrawer === void 0 ? void 0 : panelDrawer.panelKey) {
82
- editPanel();
83
- }
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "PanelDrawer", {
18
+ enumerable: true,
19
+ get: ()=>PanelDrawer
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _react = require("react");
23
+ const _material = require("@mui/material");
24
+ const _components = require("@perses-dev/components");
25
+ const _context = require("../../context");
26
+ const _panelEditorModel = require("./panel-editor-model");
27
+ const _panelEditorForm = require("./PanelEditorForm");
28
+ const PanelDrawer = ()=>{
29
+ const { closePanelDrawer } = (0, _context.useDashboardApp)();
30
+ const model = (0, _panelEditorModel.usePanelDrawerModel)();
31
+ // When the user clicks close, start closing but don't call the store yet to keep values stable during animtation
32
+ const [isClosing, setIsClosing] = (0, _react.useState)(false);
33
+ const handleClose = ()=>setIsClosing(true);
34
+ // Don't call closeDrawer on the store until the Drawer has completely transitioned out
35
+ const handleExited = ()=>{
84
36
  closePanelDrawer();
37
+ setIsClosing(false);
85
38
  };
86
- const addNewPanel = () => {
87
- if ((panelDrawer === null || panelDrawer === void 0 ? void 0 : panelDrawer.groupIndex) === undefined) {
88
- return;
39
+ // Drawer is open if we have a model and we're not transitioning out
40
+ const isOpen = model !== undefined && isClosing === false;
41
+ const handleSubmit = (values)=>{
42
+ // This shouldn't happen since we don't render the submit button until we have a model, but check to make TS happy
43
+ if (model === undefined) {
44
+ throw new Error('Cannot apply changes');
89
45
  }
90
- const panelKey = (0, functions_1.removeWhiteSpacesAndSpecialCharacters)(panelName);
91
- updatePanel(panelKey, {
92
- kind,
93
- options,
94
- display: { name: panelName, description: panelDescription },
95
- }, panelDrawer.groupIndex);
46
+ model.applyChanges(values);
47
+ handleClose();
96
48
  };
97
- const editPanel = () => {
98
- if ((panelDrawer === null || panelDrawer === void 0 ? void 0 : panelDrawer.panelKey) === undefined) {
99
- return;
100
- }
101
- updatePanel(panelDrawer.panelKey, {
102
- ...panels[panelDrawer.panelKey],
103
- kind,
104
- options,
105
- display: { name: panelName !== null && panelName !== void 0 ? panelName : '', description: panelDescription },
106
- });
107
- // TO DO: need to move panel if panel group changes
108
- };
109
- return ((0, jsx_runtime_1.jsx)(components_1.Drawer, { isOpen: !!panelDrawer, onClose: () => closePanelDrawer(), children: (0, jsx_runtime_1.jsxs)("form", { onSubmit: handleSubmit, children: [(0, jsx_runtime_1.jsx)(PanelDrawerHeader, { panelKey: panelDrawer === null || panelDrawer === void 0 ? void 0 : panelDrawer.panelKey, onClose: () => closePanelDrawer() }), (0, jsx_runtime_1.jsxs)(material_1.Grid, { container: true, spacing: 2, children: [(0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 4, children: (0, jsx_runtime_1.jsxs)(material_1.FormControl, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { id: "select-group", children: "Group" }), (0, jsx_runtime_1.jsx)(material_1.Select, { required: true, labelId: "select-group", label: "Group", value: group !== null && group !== void 0 ? group : 0, onChange: handleGroupChange, children: layouts.map((layout, index) => {
110
- var _a;
111
- return ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: index, children: ((_a = layout.spec.display) === null || _a === void 0 ? void 0 : _a.title) || `Group ${index + 1}` }, index));
112
- }) })] }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 8, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 2, sx: { flexGrow: '1' }, children: [(0, jsx_runtime_1.jsx)(material_1.TextField, { required: true, label: "Panel Name", value: panelName, variant: "outlined", onChange: handlePanelNameChange }), (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "Description", value: panelDescription, variant: "outlined", onChange: handlePanelDescriptionChange })] }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 4, children: (0, jsx_runtime_1.jsxs)(material_1.FormControl, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { id: "panel-type-label", children: "Panel Type" }), (0, jsx_runtime_1.jsxs)(material_1.Select, { required: true, labelId: "panel-type-label", label: "Panel Type", value: kind, onChange: handleKindChange, children: [(0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: "LineChart", children: "Line Chart" }), (0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: "GaugeChart", children: "Gauge Chart" }), (0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: "StatChart", children: "Stat Chart" })] })] }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 8, children: (0, jsx_runtime_1.jsx)(plugin_system_1.PluginBoundary, { loadingFallback: "Loading...", ErrorFallbackComponent: components_1.ErrorAlert, children: kind !== '' && (0, jsx_runtime_1.jsx)(PanelOptionsEditor_1.PanelOptionsEditor, { kind: kind, value: options, onChange: handleOptionsChange }) }) })] })] }) }));
113
- };
114
- const PanelDrawerHeader = ({ panelKey, onClose }) => {
115
- const action = panelKey ? 'Edit' : 'Add';
116
- return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
117
- display: 'flex',
118
- alignItems: 'center',
119
- marginBottom: (theme) => theme.spacing(2),
120
- paddingBottom: (theme) => theme.spacing(2),
121
- borderBottom: (theme) => `1px solid ${theme.palette.grey[100]}`,
122
- }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h2", children: `${action} Panel` }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1, sx: { marginLeft: 'auto' }, children: [(0, jsx_runtime_1.jsx)(material_1.Button, { type: "submit", variant: "contained", children: panelKey ? 'Apply' : 'Add' }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", onClick: onClose, children: "Cancel" })] })] }));
49
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.Drawer, {
50
+ isOpen: isOpen,
51
+ onClose: handleClose,
52
+ SlideProps: {
53
+ onExited: handleExited
54
+ },
55
+ children: model !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
56
+ children: [
57
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
58
+ sx: {
59
+ display: 'flex',
60
+ alignItems: 'center',
61
+ marginBottom: (theme)=>theme.spacing(2),
62
+ paddingBottom: (theme)=>theme.spacing(2),
63
+ borderBottom: (theme)=>`1px solid ${theme.palette.grey[100]}`
64
+ },
65
+ children: [
66
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
67
+ variant: "h2",
68
+ children: model.drawerTitle
69
+ }),
70
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
71
+ direction: "row",
72
+ spacing: 1,
73
+ sx: {
74
+ marginLeft: 'auto'
75
+ },
76
+ children: [
77
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
78
+ type: "submit",
79
+ variant: "contained",
80
+ form: _panelEditorForm.panelEditorFormId,
81
+ children: model.submitButtonText
82
+ }),
83
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
84
+ variant: "outlined",
85
+ onClick: handleClose,
86
+ children: "Cancel"
87
+ })
88
+ ]
89
+ })
90
+ ]
91
+ }),
92
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelEditorForm.PanelEditorForm, {
93
+ onSubmit: handleSubmit,
94
+ initialValues: model.initialValues
95
+ })
96
+ ]
97
+ })
98
+ });
123
99
  };
124
- exports.default = PanelDrawer;
@@ -1,32 +1,3 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const jsx_runtime_1 = require("react/jsx-runtime");
30
1
  // Copyright 2022 The Perses Authors
31
2
  // Licensed under the Apache License, Version 2.0 (the "License");
32
3
  // you may not use this file except in compliance with the License.
@@ -39,73 +10,101 @@ const jsx_runtime_1 = require("react/jsx-runtime");
39
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
40
11
  // See the License for the specific language governing permissions and
41
12
  // limitations under the License.
42
- const plugin_system_1 = require("@perses-dev/plugin-system");
43
- const react_1 = require("@testing-library/react");
44
- const user_event_1 = __importDefault(require("@testing-library/user-event"));
45
- const dashboardAppSlice = __importStar(require("../../context/DashboardAppSlice"));
46
- const layoutsSlice = __importStar(require("../../context/LayoutsSlice"));
47
- const context = __importStar(require("../../context/DashboardProvider"));
48
- const test_1 = require("../../test");
49
- const testDashboard_1 = __importDefault(require("../../test/testDashboard"));
50
- const PanelDrawer_1 = __importDefault(require("./PanelDrawer"));
51
- const updatePanel = jest.fn();
52
- jest.spyOn(context, 'usePanels').mockReturnValue({
53
- updatePanel,
54
- panels: {},
55
- });
56
- const addItemToLayout = jest.fn();
57
- jest.spyOn(layoutsSlice, 'useLayouts').mockReturnValue({
58
- addItemToLayout,
59
- updateLayout: jest.fn(),
60
- layouts: testDashboard_1.default.spec.layouts,
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
61
16
  });
62
- const dashboardApp = {
63
- panelDrawer: {
64
- groupIndex: 0,
65
- },
66
- openPanelDrawer: jest.fn(),
67
- closePanelDrawer: jest.fn(),
68
- panelGroupDialog: undefined,
69
- openPanelGroupDialog: jest.fn(),
70
- closePanelGroupDialog: jest.fn(),
71
- };
72
- describe('Panel Drawer', () => {
73
- beforeEach(() => {
74
- jest.clearAllMocks();
75
- });
76
- const renderPanelDrawer = () => {
77
- const { addMockPlugin, pluginRegistryProps } = (0, test_1.mockPluginRegistryProps)();
78
- addMockPlugin('Panel', 'FakePanel', test_1.FAKE_PANEL_PLUGIN);
79
- (0, test_1.renderWithContext)((0, jsx_runtime_1.jsxs)(plugin_system_1.PluginRegistry, { ...pluginRegistryProps, children: [(0, jsx_runtime_1.jsx)(PanelDrawer_1.default, {}), ","] }));
17
+ const _jsxRuntime = require("react/jsx-runtime");
18
+ const _pluginSystem = require("@perses-dev/plugin-system");
19
+ const _react = require("@testing-library/react");
20
+ const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
21
+ const _testUtils = require("react-dom/test-utils");
22
+ const _test = require("../../test");
23
+ const _dashboardProvider = require("../../context/DashboardProvider");
24
+ const _panelDrawer = require("./PanelDrawer");
25
+ function _interopRequireDefault(obj) {
26
+ return obj && obj.__esModule ? obj : {
27
+ default: obj
28
+ };
29
+ }
30
+ describe('Panel Drawer', ()=>{
31
+ const renderPanelDrawer = ()=>{
32
+ const { addMockPlugin , pluginRegistryProps } = (0, _test.mockPluginRegistryProps)();
33
+ addMockPlugin('Panel', 'LineChart', _test.FAKE_PANEL_PLUGIN);
34
+ const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
35
+ (0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.PluginRegistry, {
36
+ ...pluginRegistryProps,
37
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_dashboardProvider.DashboardProvider, {
38
+ initialState: {
39
+ dashboardSpec: (0, _test.getTestDashboard)().spec,
40
+ isEditMode: true
41
+ },
42
+ children: [
43
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardProviderSpy, {}),
44
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelDrawer.PanelDrawer, {})
45
+ ]
46
+ })
47
+ }));
48
+ const { value: storeApi } = store;
49
+ if (storeApi === undefined) {
50
+ throw new Error('Expected dashboard store to be set after initial render');
51
+ }
52
+ return storeApi;
80
53
  };
81
- it('should add new panel', () => {
82
- jest.spyOn(dashboardAppSlice, 'useDashboardApp').mockReturnValue(dashboardApp);
83
- renderPanelDrawer();
84
- const nameInput = react_1.screen.getByLabelText(/Panel Name/);
85
- user_event_1.default.type(nameInput, 'New Panel');
86
- user_event_1.default.click(react_1.screen.getByText('Add'));
87
- expect(updatePanel).toHaveBeenCalledWith('NewPanel', {
88
- kind: '',
89
- display: { name: 'New Panel', description: '' },
90
- options: {},
91
- }, 0);
54
+ it('should add new panel', async ()=>{
55
+ const storeApi = renderPanelDrawer();
56
+ // Open the drawer for a new panel (i.e. no panel key)
57
+ (0, _testUtils.act)(()=>storeApi.getState().openPanelDrawer({
58
+ groupIndex: 0
59
+ }));
60
+ const nameInput = await _react.screen.findByLabelText(/Panel Name/);
61
+ _userEvent.default.type(nameInput, 'New Panel');
62
+ _userEvent.default.click(_react.screen.getByText('Add'));
63
+ // TODO: Assert drawer is closed?
64
+ const panels = storeApi.getState().panels;
65
+ expect(panels).toMatchObject({
66
+ // Should have the new panel in the store
67
+ NewPanel: {
68
+ kind: 'Panel',
69
+ spec: {
70
+ display: {
71
+ name: 'New Panel',
72
+ description: ''
73
+ },
74
+ plugin: {
75
+ kind: '',
76
+ spec: {}
77
+ }
78
+ }
79
+ }
80
+ });
92
81
  });
93
- it('should edit an existing panel', () => {
94
- jest.spyOn(dashboardAppSlice, 'useDashboardApp').mockReturnValue({
95
- ...dashboardApp,
96
- panelDrawer: {
82
+ it('should edit an existing panel', async ()=>{
83
+ const storeApi = renderPanelDrawer();
84
+ // Open the drawer for an existing panel
85
+ (0, _testUtils.act)(()=>storeApi.getState().openPanelDrawer({
97
86
  groupIndex: 0,
98
- panelKey: 'cpu',
99
- },
100
- });
101
- renderPanelDrawer();
102
- const nameInput = react_1.screen.getByLabelText(/Panel Name/);
103
- user_event_1.default.type(nameInput, 'cpu usage');
104
- user_event_1.default.click(react_1.screen.getByText('Apply'));
105
- expect(updatePanel).toHaveBeenCalledWith('cpu', {
106
- display: { name: 'cpu usage', description: '' },
107
- kind: '',
108
- options: {},
87
+ panelKey: 'cpu'
88
+ }));
89
+ const nameInput = await _react.screen.findByLabelText(/Panel Name/);
90
+ _userEvent.default.clear(nameInput);
91
+ _userEvent.default.type(nameInput, 'cpu usage');
92
+ _userEvent.default.click(_react.screen.getByText('Apply'));
93
+ const panels = storeApi.getState().panels;
94
+ expect(panels).toMatchObject({
95
+ cpu: {
96
+ kind: 'Panel',
97
+ spec: {
98
+ display: {
99
+ name: 'cpu usage',
100
+ description: ''
101
+ },
102
+ plugin: {
103
+ kind: 'TimeSeriesChart',
104
+ spec: {}
105
+ }
106
+ }
107
+ }
109
108
  });
110
109
  });
111
110
  });
@@ -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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ PanelEditorForm: ()=>PanelEditorForm,
25
+ panelEditorFormId: ()=>panelEditorFormId
26
+ });
27
+ const _jsxRuntime = require("react/jsx-runtime");
28
+ const _react = require("react");
29
+ const _material = require("@mui/material");
30
+ const _components = require("@perses-dev/components");
31
+ const _context = require("../../context");
32
+ const _panelEditorModel = require("./panel-editor-model");
33
+ const _panelTypeSelect = require("./PanelTypeSelect");
34
+ const _panelSpecEditor = require("./PanelSpecEditor");
35
+ function PanelEditorForm(props) {
36
+ const { initialValues , onSubmit } = props;
37
+ const { layouts } = (0, _context.useLayouts)();
38
+ const [name, setName] = (0, _react.useState)(initialValues.name);
39
+ const [description, setDescription] = (0, _react.useState)(initialValues.description);
40
+ const [group, setGroup] = (0, _react.useState)(initialValues.group);
41
+ const [kind, setKind] = (0, _react.useState)(initialValues.kind);
42
+ const { spec , onSpecChange } = (0, _panelEditorModel.usePanelSpecState)(kind, initialValues.spec);
43
+ // Ignore string values (which would be an "empty" value from the Select) since we don't allow them to unset it
44
+ const handleGroupChange = (e)=>{
45
+ const { value } = e.target;
46
+ if (typeof value === 'string') {
47
+ return;
48
+ }
49
+ setGroup(value);
50
+ };
51
+ const handleSubmit = (e)=>{
52
+ e.preventDefault();
53
+ const values = {
54
+ name,
55
+ description,
56
+ group,
57
+ kind,
58
+ spec
59
+ };
60
+ onSubmit(values);
61
+ };
62
+ var ref;
63
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)("form", {
64
+ id: panelEditorFormId,
65
+ onSubmit: handleSubmit,
66
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Grid, {
67
+ container: true,
68
+ spacing: 2,
69
+ children: [
70
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
71
+ item: true,
72
+ xs: 8,
73
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
74
+ required: true,
75
+ label: "Panel Name",
76
+ value: name,
77
+ variant: "outlined",
78
+ onChange: (e)=>setName(e.target.value)
79
+ })
80
+ }),
81
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
82
+ item: true,
83
+ xs: 4,
84
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
85
+ children: [
86
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
87
+ id: "select-group",
88
+ children: "Group"
89
+ }),
90
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Select, {
91
+ required: true,
92
+ labelId: "select-group",
93
+ label: "Group",
94
+ value: group !== null && group !== void 0 ? group : 0,
95
+ onChange: handleGroupChange,
96
+ children: layouts.map((layout, index)=>{
97
+ var ref1;
98
+ /*#__PURE__*/ return (0, _jsxRuntime.jsx)(_material.MenuItem, {
99
+ value: index,
100
+ children: (ref = (ref1 = layout.spec.display) === null || ref1 === void 0 ? void 0 : ref1.title) !== null && ref !== void 0 ? ref : `Group ${index + 1}`
101
+ }, index);
102
+ })
103
+ })
104
+ ]
105
+ })
106
+ }),
107
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
108
+ item: true,
109
+ xs: 8,
110
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
111
+ label: "Panel Description",
112
+ value: description,
113
+ variant: "outlined",
114
+ onChange: (e)=>setDescription(e.target.value)
115
+ })
116
+ }),
117
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
118
+ item: true,
119
+ xs: 4,
120
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
121
+ children: [
122
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
123
+ id: "panel-type-label",
124
+ children: "Panel Type"
125
+ }),
126
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelTypeSelect.PanelTypeSelect, {
127
+ required: true,
128
+ labelId: "panel-type-label",
129
+ label: "Panel Type",
130
+ value: kind,
131
+ onChange: (e)=>setKind(e.target.value)
132
+ })
133
+ ]
134
+ })
135
+ }),
136
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
137
+ item: true,
138
+ xs: 12,
139
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
140
+ FallbackComponent: _components.ErrorAlert,
141
+ children: spec !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelSpecEditor.PanelSpecEditor, {
142
+ panelPluginKind: kind,
143
+ value: spec,
144
+ onChange: onSpecChange
145
+ })
146
+ })
147
+ })
148
+ ]
149
+ })
150
+ });
151
+ }
152
+ const panelEditorFormId = 'panel-editor-form';
@@ -0,0 +1,40 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "PanelSpecEditor", {
18
+ enumerable: true,
19
+ get: ()=>PanelSpecEditor
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _pluginSystem = require("@perses-dev/plugin-system");
23
+ function PanelSpecEditor(props) {
24
+ const { panelPluginKind , ...others } = props;
25
+ const { data: plugin , isLoading } = (0, _pluginSystem.usePlugin)('Panel', panelPluginKind, {
26
+ useErrorBoundary: true,
27
+ enabled: panelPluginKind !== ''
28
+ });
29
+ // TODO: Proper loading indicator
30
+ if (isLoading) {
31
+ return null;
32
+ }
33
+ if (plugin === undefined) {
34
+ throw new Error(`Missing OptionsEditorComponent for Panel plugin with kind '${panelPluginKind}'`);
35
+ }
36
+ const { OptionsEditorComponent } = plugin;
37
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(OptionsEditorComponent, {
38
+ ...others
39
+ });
40
+ }
@@ -0,0 +1,38 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "PanelTypeSelect", {
18
+ enumerable: true,
19
+ get: ()=>PanelTypeSelect
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _pluginSystem = require("@perses-dev/plugin-system");
24
+ function PanelTypeSelect(props) {
25
+ const { value: propValue , ...others } = props;
26
+ const { data , isLoading } = (0, _pluginSystem.useListPluginMetadata)('Panel');
27
+ // Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
28
+ const value = propValue !== '' && isLoading ? '' : propValue;
29
+ // TODO: Does this need a loading indicator of some kind?
30
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Select, {
31
+ ...others,
32
+ value: value,
33
+ children: data === null || data === void 0 ? void 0 : data.map((metadata)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
34
+ value: metadata.kind,
35
+ children: metadata.display.name
36
+ }, metadata.kind))
37
+ });
38
+ }