@perses-dev/dashboards 0.9.0 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (201) hide show
  1. package/dist/cjs/components/Dashboard.js +7 -11
  2. package/dist/cjs/components/DashboardToolbar.js +4 -4
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +13 -13
  4. package/dist/cjs/components/GridLayout/GridLayout.js +24 -21
  5. package/dist/cjs/components/GridLayout/GridTitle.js +27 -5
  6. package/dist/cjs/components/Panel/DeletePanelDialog.js +91 -0
  7. package/dist/cjs/components/Panel/Panel.js +16 -5
  8. package/dist/cjs/components/Panel/Panel.test.js +12 -4
  9. package/dist/cjs/components/Panel/PanelContent.js +3 -2
  10. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +13 -12
  11. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +8 -12
  12. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +77 -35
  13. package/dist/cjs/components/PanelDrawer/PanelPreview.js +48 -0
  14. package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +86 -0
  15. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +12 -19
  16. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +10 -31
  17. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +2 -2
  18. package/dist/cjs/components/Variables/Variable.js +19 -11
  19. package/dist/cjs/components/Variables/VariableEditor.js +207 -0
  20. package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +236 -0
  21. package/dist/cjs/components/Variables/VariableEditorForm/index.js +28 -0
  22. package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +88 -0
  23. package/dist/cjs/components/Variables/VariableList.js +50 -69
  24. package/dist/cjs/components/Variables/index.js +1 -0
  25. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +70 -0
  26. package/dist/cjs/context/DashboardProvider/common.js +18 -0
  27. package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +71 -0
  28. package/dist/cjs/context/DashboardProvider/index.js +29 -0
  29. package/dist/cjs/context/DashboardProvider/layout-slice.js +200 -0
  30. package/dist/cjs/context/DashboardProvider/panel-editing-slice.js +156 -0
  31. package/dist/{context/DashboardAppSlice.js → cjs/context/DashboardProvider/panel-group-slice.js} +18 -25
  32. package/dist/cjs/context/DatasourceStoreProvider.js +109 -7
  33. package/dist/cjs/context/TemplateVariableProvider.js +8 -1
  34. package/dist/cjs/context/index.js +0 -2
  35. package/dist/cjs/test/testDashboard.js +13 -1
  36. package/dist/cjs/views/ViewDashboard/DashboardApp.js +6 -7
  37. package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +165 -0
  38. package/dist/components/Dashboard.d.ts +1 -4
  39. package/dist/components/Dashboard.d.ts.map +1 -1
  40. package/dist/components/Dashboard.js +8 -12
  41. package/dist/components/Dashboard.js.map +1 -1
  42. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  43. package/dist/components/DashboardToolbar.js +5 -5
  44. package/dist/components/DashboardToolbar.js.map +1 -1
  45. package/dist/components/GridLayout/GridItemContent.d.ts +3 -3
  46. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  47. package/dist/components/GridLayout/GridItemContent.js +14 -14
  48. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  49. package/dist/components/GridLayout/GridLayout.d.ts +2 -3
  50. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  51. package/dist/components/GridLayout/GridLayout.js +24 -21
  52. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  53. package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
  54. package/dist/components/GridLayout/GridTitle.js +28 -6
  55. package/dist/components/GridLayout/GridTitle.js.map +1 -1
  56. package/dist/components/Panel/DeletePanelDialog.d.ts +5 -0
  57. package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -0
  58. package/dist/components/Panel/DeletePanelDialog.js +80 -0
  59. package/dist/components/Panel/DeletePanelDialog.js.map +1 -0
  60. package/dist/components/Panel/Panel.d.ts +1 -1
  61. package/dist/components/Panel/Panel.d.ts.map +1 -1
  62. package/dist/components/Panel/Panel.js +17 -6
  63. package/dist/components/Panel/Panel.js.map +1 -1
  64. package/dist/components/Panel/Panel.test.js +7 -4
  65. package/dist/components/Panel/Panel.test.js.map +1 -1
  66. package/dist/components/Panel/PanelContent.d.ts +4 -1
  67. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  68. package/dist/components/Panel/PanelContent.js +3 -2
  69. package/dist/components/Panel/PanelContent.js.map +1 -1
  70. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  71. package/dist/components/PanelDrawer/PanelDrawer.js +14 -13
  72. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  73. package/dist/components/PanelDrawer/PanelDrawer.test.js +8 -12
  74. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
  75. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +3 -3
  76. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  77. package/dist/components/PanelDrawer/PanelEditorForm.js +78 -36
  78. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  79. package/dist/components/PanelDrawer/PanelPreview.d.ts +4 -0
  80. package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -0
  81. package/dist/components/PanelDrawer/PanelPreview.js +42 -0
  82. package/dist/components/PanelDrawer/PanelPreview.js.map +1 -0
  83. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +4 -0
  84. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
  85. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +75 -0
  86. package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
  87. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  88. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +13 -20
  89. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  90. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +10 -31
  91. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
  92. package/dist/components/TimeRangeControls/TimeRangeControls.js +3 -3
  93. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
  94. package/dist/components/Variables/Variable.js +21 -13
  95. package/dist/components/Variables/Variable.js.map +1 -1
  96. package/dist/components/Variables/VariableEditor.d.ts +8 -0
  97. package/dist/components/Variables/VariableEditor.d.ts.map +1 -0
  98. package/dist/components/Variables/VariableEditor.js +196 -0
  99. package/dist/components/Variables/VariableEditor.js.map +1 -0
  100. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +8 -0
  101. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
  102. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +225 -0
  103. package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
  104. package/dist/components/Variables/VariableEditorForm/index.d.ts +2 -0
  105. package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
  106. package/dist/components/Variables/VariableEditorForm/index.js +15 -0
  107. package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
  108. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +21 -0
  109. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
  110. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +76 -0
  111. package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
  112. package/dist/components/Variables/VariableList.d.ts.map +1 -1
  113. package/dist/components/Variables/VariableList.js +48 -72
  114. package/dist/components/Variables/VariableList.js.map +1 -1
  115. package/dist/components/Variables/index.d.ts +1 -0
  116. package/dist/components/Variables/index.d.ts.map +1 -1
  117. package/dist/components/Variables/index.js +1 -0
  118. package/dist/components/Variables/index.js.map +1 -1
  119. package/dist/context/DashboardProvider/DashboardProvider.d.ts +23 -0
  120. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -0
  121. package/dist/context/DashboardProvider/DashboardProvider.js +52 -0
  122. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -0
  123. package/dist/context/DashboardProvider/common.d.ts +5 -0
  124. package/dist/context/DashboardProvider/common.d.ts.map +1 -0
  125. package/dist/context/DashboardProvider/common.js +17 -0
  126. package/dist/context/DashboardProvider/common.js.map +1 -0
  127. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +32 -0
  128. package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -0
  129. package/dist/context/DashboardProvider/dashboard-provider-api.js +56 -0
  130. package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -0
  131. package/dist/context/DashboardProvider/index.d.ts +3 -0
  132. package/dist/context/DashboardProvider/index.d.ts.map +1 -0
  133. package/dist/context/DashboardProvider/index.js +16 -0
  134. package/dist/context/DashboardProvider/index.js.map +1 -0
  135. package/dist/context/DashboardProvider/layout-slice.d.ts +57 -0
  136. package/dist/context/DashboardProvider/layout-slice.d.ts.map +1 -0
  137. package/dist/context/DashboardProvider/layout-slice.js +196 -0
  138. package/dist/context/DashboardProvider/layout-slice.js.map +1 -0
  139. package/dist/context/DashboardProvider/panel-editing-slice.d.ts +70 -0
  140. package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +1 -0
  141. package/dist/context/DashboardProvider/panel-editing-slice.js +152 -0
  142. package/dist/context/DashboardProvider/panel-editing-slice.js.map +1 -0
  143. package/dist/context/DashboardProvider/panel-group-slice.d.ts +15 -0
  144. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -0
  145. package/dist/context/DashboardProvider/panel-group-slice.js +32 -0
  146. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -0
  147. package/dist/context/DatasourceStoreProvider.d.ts +10 -2
  148. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
  149. package/dist/context/DatasourceStoreProvider.js +111 -9
  150. package/dist/context/DatasourceStoreProvider.js.map +1 -1
  151. package/dist/context/TemplateVariableProvider.d.ts +2 -0
  152. package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
  153. package/dist/context/TemplateVariableProvider.js +8 -1
  154. package/dist/context/TemplateVariableProvider.js.map +1 -1
  155. package/dist/context/index.d.ts +0 -2
  156. package/dist/context/index.d.ts.map +1 -1
  157. package/dist/context/index.js +0 -2
  158. package/dist/context/index.js.map +1 -1
  159. package/dist/test/plugin-registry.d.ts +2 -2
  160. package/dist/test/plugin-registry.d.ts.map +1 -1
  161. package/dist/test/plugin-registry.js.map +1 -1
  162. package/dist/test/testDashboard.d.ts.map +1 -1
  163. package/dist/test/testDashboard.js +13 -1
  164. package/dist/test/testDashboard.js.map +1 -1
  165. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  166. package/dist/views/ViewDashboard/DashboardApp.js +6 -7
  167. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  168. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +2 -0
  169. package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +1 -0
  170. package/dist/views/ViewDashboard/tests/panelGroups.test.js +158 -0
  171. package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -0
  172. package/package.json +4 -4
  173. package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +0 -40
  174. package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +0 -38
  175. package/dist/cjs/components/PanelDrawer/panel-editor-model.js +0 -140
  176. package/dist/cjs/context/DashboardAppSlice.js +0 -57
  177. package/dist/cjs/context/DashboardProvider.js +0 -128
  178. package/dist/cjs/context/LayoutsSlice.js +0 -55
  179. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +0 -7
  180. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +0 -1
  181. package/dist/components/PanelDrawer/PanelSpecEditor.js +0 -34
  182. package/dist/components/PanelDrawer/PanelSpecEditor.js.map +0 -1
  183. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +0 -8
  184. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +0 -1
  185. package/dist/components/PanelDrawer/PanelTypeSelect.js +0 -34
  186. package/dist/components/PanelDrawer/PanelTypeSelect.js.map +0 -1
  187. package/dist/components/PanelDrawer/panel-editor-model.d.ts +0 -27
  188. package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +0 -1
  189. package/dist/components/PanelDrawer/panel-editor-model.js +0 -133
  190. package/dist/components/PanelDrawer/panel-editor-model.js.map +0 -1
  191. package/dist/context/DashboardAppSlice.d.ts +0 -26
  192. package/dist/context/DashboardAppSlice.d.ts.map +0 -1
  193. package/dist/context/DashboardAppSlice.js.map +0 -1
  194. package/dist/context/DashboardProvider.d.ts +0 -36
  195. package/dist/context/DashboardProvider.d.ts.map +0 -1
  196. package/dist/context/DashboardProvider.js +0 -107
  197. package/dist/context/DashboardProvider.js.map +0 -1
  198. package/dist/context/LayoutsSlice.d.ts +0 -12
  199. package/dist/context/LayoutsSlice.d.ts.map +0 -1
  200. package/dist/context/LayoutsSlice.js +0 -43
  201. package/dist/context/LayoutsSlice.js.map +0 -1
@@ -28,38 +28,53 @@ const _jsxRuntime = require("react/jsx-runtime");
28
28
  const _react = require("react");
29
29
  const _material = require("@mui/material");
30
30
  const _components = require("@perses-dev/components");
31
+ const _pluginSystem = require("@perses-dev/plugin-system");
31
32
  const _context = require("../../context");
32
- const _panelEditorModel = require("./panel-editor-model");
33
- const _panelTypeSelect = require("./PanelTypeSelect");
34
- const _panelSpecEditor = require("./PanelSpecEditor");
33
+ const _panelPreview = require("./PanelPreview");
35
34
  function PanelEditorForm(props) {
35
+ var ref;
36
36
  const { initialValues , onSubmit } = props;
37
37
  const { layouts } = (0, _context.useLayouts)();
38
38
  const [name, setName] = (0, _react.useState)(initialValues.name);
39
39
  const [description, setDescription] = (0, _react.useState)(initialValues.description);
40
- const [group, setGroup] = (0, _react.useState)(initialValues.group);
40
+ const [groupIndex, setGroupIndex] = (0, _react.useState)(initialValues.groupIndex);
41
41
  const [kind, setKind] = (0, _react.useState)(initialValues.kind);
42
- const { spec , onSpecChange } = (0, _panelEditorModel.usePanelSpecState)(kind, initialValues.spec);
42
+ const [spec, setSpec] = (0, _react.useState)(initialValues.spec);
43
+ // Use common plugin editor logic even though we've split the inputs up in this form
44
+ const pluginEditor = (0, _pluginSystem.usePluginEditor)({
45
+ pluginType: 'Panel',
46
+ value: {
47
+ kind,
48
+ spec
49
+ },
50
+ onChange: (plugin)=>{
51
+ setKind(plugin.kind);
52
+ setSpec(plugin.spec);
53
+ }
54
+ });
43
55
  // Ignore string values (which would be an "empty" value from the Select) since we don't allow them to unset it
44
56
  const handleGroupChange = (e)=>{
45
57
  const { value } = e.target;
46
58
  if (typeof value === 'string') {
47
59
  return;
48
60
  }
49
- setGroup(value);
61
+ setGroupIndex(value);
50
62
  };
51
63
  const handleSubmit = (e)=>{
52
64
  e.preventDefault();
65
+ if (spec === undefined) {
66
+ throw new Error('Cannot submit without a plugin spec');
67
+ }
53
68
  const values = {
54
69
  name,
55
70
  description,
56
- group,
71
+ groupIndex,
57
72
  kind,
58
73
  spec
59
74
  };
60
75
  onSubmit(values);
61
76
  };
62
- var ref;
77
+ var _title, ref1;
63
78
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)("form", {
64
79
  id: panelEditorFormId,
65
80
  onSubmit: handleSubmit,
@@ -72,7 +87,7 @@ function PanelEditorForm(props) {
72
87
  xs: 8,
73
88
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
74
89
  required: true,
75
- label: "Panel Name",
90
+ label: "Name",
76
91
  value: name,
77
92
  variant: "outlined",
78
93
  onChange: (e)=>setName(e.target.value)
@@ -91,15 +106,12 @@ function PanelEditorForm(props) {
91
106
  required: true,
92
107
  labelId: "select-group",
93
108
  label: "Group",
94
- value: group !== null && group !== void 0 ? group : 0,
109
+ value: groupIndex !== null && groupIndex !== void 0 ? groupIndex : 0,
95
110
  onChange: handleGroupChange,
96
- children: layouts.map((layout, index)=>{
97
- var ref1;
98
- /*#__PURE__*/ return (0, _jsxRuntime.jsx)(_material.MenuItem, {
111
+ children: layouts.map((layout, index)=>/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
99
112
  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
- })
113
+ children: (_title = layout.title) !== null && _title !== void 0 ? _title : `Group ${index + 1}`
114
+ }, index))
103
115
  })
104
116
  ]
105
117
  })
@@ -108,40 +120,70 @@ function PanelEditorForm(props) {
108
120
  item: true,
109
121
  xs: 8,
110
122
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
111
- label: "Panel Description",
123
+ label: "Description",
112
124
  value: description,
113
125
  variant: "outlined",
114
126
  onChange: (e)=>setDescription(e.target.value)
115
127
  })
116
128
  }),
117
- /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
129
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Grid, {
118
130
  item: true,
119
131
  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
+ children: [
133
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.FormControl, {
134
+ disabled: pluginEditor.isLoading,
135
+ error: pluginEditor.error !== null,
136
+ children: [
137
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
138
+ id: "panel-type-label",
139
+ children: "Type"
140
+ }),
141
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.PluginKindSelect, {
142
+ pluginType: "Panel",
143
+ required: true,
144
+ labelId: "panel-type-label",
145
+ label: "Type",
146
+ value: pluginEditor.pendingKind ? pluginEditor.pendingKind : kind,
147
+ onChange: pluginEditor.onKindChange
148
+ })
149
+ ]
150
+ }),
151
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormHelperText, {
152
+ children: (ref1 = (ref = pluginEditor.error) === null || ref === void 0 ? void 0 : ref.message) !== null && ref1 !== void 0 ? ref1 : ''
153
+ })
154
+ ]
155
+ }),
156
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Grid, {
157
+ item: true,
158
+ xs: 12,
159
+ children: [
160
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Typography, {
161
+ variant: "h4",
162
+ marginBottom: 1,
163
+ children: "Preview"
164
+ }),
165
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
166
+ FallbackComponent: _components.ErrorAlert,
167
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelPreview.PanelPreview, {
168
+ kind: kind,
169
+ name: name,
170
+ description: description,
171
+ spec: spec,
172
+ groupIndex: groupIndex
132
173
  })
133
- ]
134
- })
174
+ })
175
+ ]
135
176
  }),
136
177
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Grid, {
137
178
  item: true,
138
179
  xs: 12,
139
180
  children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
140
181
  FallbackComponent: _components.ErrorAlert,
141
- children: spec !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelSpecEditor.PanelSpecEditor, {
142
- panelPluginKind: kind,
182
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.PluginSpecEditor, {
183
+ pluginType: "Panel",
184
+ pluginKind: kind,
143
185
  value: spec,
144
- onChange: onSpecChange
186
+ onChange: pluginEditor.onSpecChange
145
187
  })
146
188
  })
147
189
  })
@@ -0,0 +1,48 @@
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, "PanelPreview", {
18
+ enumerable: true,
19
+ get: ()=>PanelPreview
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _panel = require("../Panel");
24
+ function PanelPreview({ name , description , kind , spec , groupIndex }) {
25
+ const previewValues = {
26
+ definition: {
27
+ kind: 'Panel',
28
+ spec: {
29
+ display: {
30
+ name,
31
+ description
32
+ },
33
+ plugin: {
34
+ kind,
35
+ spec
36
+ }
37
+ }
38
+ },
39
+ groupIndex,
40
+ itemIndex: 0
41
+ };
42
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
43
+ height: 300,
44
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_panel.Panel, {
45
+ ...previewValues
46
+ })
47
+ });
48
+ }
@@ -0,0 +1,86 @@
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, "default", {
18
+ enumerable: true,
19
+ get: ()=>_default
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _close = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Close"));
24
+ const _context = require("../../context");
25
+ function _interopRequireDefault(obj) {
26
+ return obj && obj.__esModule ? obj : {
27
+ default: obj
28
+ };
29
+ }
30
+ const DeletePanelGroupDialog = ()=>{
31
+ var ref;
32
+ const { layouts , deletePanelGroup } = (0, _context.useLayouts)();
33
+ const { deletePanelGroupDialog , closeDeletePanelGroupDialog } = (0, _context.usePanelGroupDialog)();
34
+ const groupIndex = deletePanelGroupDialog === null || deletePanelGroupDialog === void 0 ? void 0 : deletePanelGroupDialog.groupIndex;
35
+ const handleDelete = (e)=>{
36
+ e.preventDefault();
37
+ if (groupIndex == undefined) {
38
+ throw new Error('group index is undefined');
39
+ }
40
+ deletePanelGroup(groupIndex);
41
+ closeDeletePanelGroupDialog();
42
+ };
43
+ return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Dialog, {
44
+ open: deletePanelGroupDialog !== undefined,
45
+ children: [
46
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogTitle, {
47
+ children: "Delete Panel Group"
48
+ }),
49
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
50
+ "aria-label": "Close",
51
+ onClick: ()=>closeDeletePanelGroupDialog(),
52
+ sx: (theme)=>({
53
+ position: 'absolute',
54
+ top: theme.spacing(0.5),
55
+ right: theme.spacing(0.5)
56
+ }),
57
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_close.default, {})
58
+ }),
59
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)("form", {
60
+ onSubmit: handleDelete,
61
+ children: [
62
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogContent, {
63
+ sx: {
64
+ width: '500px'
65
+ },
66
+ children: `Are you sure you want to delete ${groupIndex !== undefined && layouts[groupIndex] !== undefined ? (ref = layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.title : 'panel group'}? This will delete all the panels within the group.`
67
+ }),
68
+ /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.DialogActions, {
69
+ children: [
70
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
71
+ variant: "contained",
72
+ type: "submit",
73
+ children: "Delete"
74
+ }),
75
+ /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
76
+ onClick: ()=>closeDeletePanelGroupDialog(),
77
+ children: "Cancel"
78
+ })
79
+ ]
80
+ })
81
+ ]
82
+ })
83
+ ]
84
+ });
85
+ };
86
+ const _default = DeletePanelGroupDialog;
@@ -29,30 +29,23 @@ function _interopRequireDefault(obj) {
29
29
  };
30
30
  }
31
31
  const PanelGroupDialog = ()=>{
32
- var ref, ref1, ref2, ref3, ref4;
33
- const { layouts , updateLayout } = (0, _context.useLayouts)();
34
- const { panelGroupDialog , closePanelGroupDialog } = (0, _context.useDashboardApp)();
32
+ var ref, ref1;
33
+ const { layouts , updatePanelGroup } = (0, _context.useLayouts)();
34
+ const { panelGroupDialog , closePanelGroupDialog } = (0, _context.usePanelGroupDialog)();
35
35
  const groupIndex = panelGroupDialog === null || panelGroupDialog === void 0 ? void 0 : panelGroupDialog.groupIndex;
36
36
  const isEditingPanelGroup = groupIndex !== undefined;
37
- const [isCollapsed, setIsCollapsed] = (0, _react.useState)(isEditingPanelGroup && !((ref1 = (ref = layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.spec.display) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.collapse) === null || ref2 === void 0 ? void 0 : ref2.open));
38
- const [name, setName] = (0, _react.useState)(isEditingPanelGroup ? (ref4 = (ref3 = layouts[groupIndex]) === null || ref3 === void 0 ? void 0 : ref3.spec.display) === null || ref4 === void 0 ? void 0 : ref4.title : '');
37
+ const [isCollapsed, setIsCollapsed] = (0, _react.useState)(isEditingPanelGroup && ((ref = layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.isCollapsed));
38
+ const [name, setName] = (0, _react.useState)(isEditingPanelGroup ? (ref1 = layouts[groupIndex]) === null || ref1 === void 0 ? void 0 : ref1.title : '');
39
39
  const handleSubmit = (e)=>{
40
40
  var ref;
41
41
  e.preventDefault();
42
- var _items;
43
- const newLayout = {
44
- kind: 'Grid',
45
- spec: {
46
- display: {
47
- title: name !== null && name !== void 0 ? name : '',
48
- collapse: {
49
- open: !isCollapsed
50
- }
51
- },
52
- items: groupIndex === undefined ? [] : (_items = (ref = layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.spec.items) !== null && _items !== void 0 ? _items : []
53
- }
42
+ var ref1;
43
+ const newGroup = {
44
+ isCollapsed,
45
+ title: name !== null && name !== void 0 ? name : '',
46
+ items: groupIndex === undefined ? [] : (ref1 = (ref = layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.items) !== null && ref1 !== void 0 ? ref1 : []
54
47
  };
55
- updateLayout(newLayout, groupIndex);
48
+ updatePanelGroup(newGroup, groupIndex);
56
49
  closePanelGroupDialog();
57
50
  };
58
51
  const handleSelectCollapsedStateChange = (e)=>{
@@ -60,7 +53,7 @@ const PanelGroupDialog = ()=>{
60
53
  setIsCollapsed(isCollapsed);
61
54
  };
62
55
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Dialog, {
63
- open: true,
56
+ open: panelGroupDialog !== undefined,
64
57
  children: [
65
58
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogTitle, {
66
59
  children: "Panel Group"
@@ -20,6 +20,7 @@ const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-librar
20
20
  const _testUtils = require("react-dom/test-utils");
21
21
  const _context = require("../../context");
22
22
  const _test = require("../../test");
23
+ const _testDashboard = /*#__PURE__*/ _interopRequireDefault(require("../../test/testDashboard"));
23
24
  const _panelGroupDialog = /*#__PURE__*/ _interopRequireDefault(require("./PanelGroupDialog"));
24
25
  function _interopRequireDefault(obj) {
25
26
  return obj && obj.__esModule ? obj : {
@@ -46,7 +47,6 @@ describe('Add Panel Group', ()=>{
46
47
  return storeApi;
47
48
  };
48
49
  it('should add new panel group', async ()=>{
49
- // jest.spyOn(dashboardAppSlice, 'useDashboardApp').mockReturnValue(dashboardApp);
50
50
  const storeApi = renderDialog();
51
51
  // Open the dialog for a new panel group
52
52
  (0, _testUtils.act)(()=>storeApi.getState().openPanelGroupDialog());
@@ -55,19 +55,14 @@ describe('Add Panel Group', ()=>{
55
55
  _userEvent.default.click(_react.screen.getByText('Add'));
56
56
  const layouts = storeApi.getState().layouts;
57
57
  expect(layouts).toContainEqual({
58
- kind: 'Grid',
59
- spec: {
60
- display: {
61
- title: 'New Panel Group',
62
- collapse: {
63
- open: true
64
- }
65
- },
66
- items: []
67
- }
58
+ id: 3,
59
+ title: 'New Panel Group',
60
+ isCollapsed: false,
61
+ items: []
68
62
  });
69
63
  });
70
64
  it('should edit existing panel group', async ()=>{
65
+ var ref;
71
66
  const storeApi = renderDialog();
72
67
  // Open the dialog for an existing panel group
73
68
  (0, _testUtils.act)(()=>storeApi.getState().openPanelGroupDialog(0));
@@ -77,26 +72,10 @@ describe('Add Panel Group', ()=>{
77
72
  _userEvent.default.click(_react.screen.getByText('Apply'));
78
73
  const layouts = storeApi.getState().layouts;
79
74
  expect(layouts).toContainEqual({
80
- kind: 'Grid',
81
- spec: {
82
- display: {
83
- title: 'New Name',
84
- collapse: {
85
- open: true
86
- }
87
- },
88
- items: [
89
- {
90
- content: {
91
- $ref: '#/spec/panels/cpu'
92
- },
93
- height: 4,
94
- width: 12,
95
- x: 0,
96
- y: 0
97
- }
98
- ]
99
- }
75
+ id: 0,
76
+ title: 'New Name',
77
+ isCollapsed: false,
78
+ items: (ref = _testDashboard.default.spec.layouts[0]) === null || ref === void 0 ? void 0 : ref.spec.items
100
79
  });
101
80
  });
102
81
  });
@@ -89,9 +89,9 @@ const TIME_OPTIONS = [
89
89
  ];
90
90
  function TimeRangeControls() {
91
91
  const { timeRange , setTimeRange } = (0, _pluginSystem.useTimeRange)();
92
- const { dashboard } = (0, _context.useDashboard)();
92
+ const dashboardDefaultTimeRange = (0, _context.useDefaultTimeRange)();
93
93
  const { queryString } = (0, _pluginSystem.useQueryString)();
94
- const defaultTimeRange = (0, _core.getDefaultTimeRange)(dashboard.duration, queryString);
94
+ const defaultTimeRange = (0, _core.getDefaultTimeRange)(dashboardDefaultTimeRange, queryString);
95
95
  // selected form value can be relative or absolute, timeRange from plugin-system is only absolute
96
96
  const [selectedTimeRange, setSelectedTimeRange] = (0, _react.useState)(defaultTimeRange);
97
97
  const [showCustomDateSelector, setShowCustomDateSelector] = (0, _react.useState)(false);
@@ -51,7 +51,7 @@ function TemplateVariable({ name }) {
51
51
  return Object.values(v).map((v)=>JSON.stringify(v.value)).join(',');
52
52
  }
53
53
  function ListVariable({ name }) {
54
- var ref, ref1, ref2;
54
+ var ref, ref1, ref2, ref3;
55
55
  const ctx = (0, _context.useTemplateVariable)(name);
56
56
  const definition = ctx.definition;
57
57
  const { data: variablePlugin } = (0, _pluginSystem.usePlugin)('Variable', definition.spec.plugin.kind);
@@ -65,6 +65,8 @@ function ListVariable({ name }) {
65
65
  const variables = (0, _pluginSystem.useTemplateVariableValues)(dependsOnVariables);
66
66
  const allowMultiple = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_multiple) === true;
67
67
  const allowAllValue = (definition === null || definition === void 0 ? void 0 : definition.spec.allow_all_value) === true;
68
+ var ref4;
69
+ const label = (ref4 = (ref = definition === null || definition === void 0 ? void 0 : definition.spec.display) === null || ref === void 0 ? void 0 : ref.label) !== null && ref4 !== void 0 ? ref4 : name;
68
70
  let waitToLoad = false;
69
71
  if (dependsOnVariables) {
70
72
  waitToLoad = dependsOnVariables.some((v)=>{
@@ -98,9 +100,9 @@ function ListVariable({ name }) {
98
100
  setVariableLoading,
99
101
  setVariableOptions
100
102
  ]);
101
- let value = (ref = ctx.state) === null || ref === void 0 ? void 0 : ref.value;
102
- const options = (ref1 = ctx.state) === null || ref1 === void 0 ? void 0 : ref1.options;
103
- const loading = (ref2 = ctx.state) === null || ref2 === void 0 ? void 0 : ref2.loading;
103
+ let value = (ref1 = ctx.state) === null || ref1 === void 0 ? void 0 : ref1.value;
104
+ const options = (ref2 = ctx.state) === null || ref2 === void 0 ? void 0 : ref2.options;
105
+ const loading = (ref3 = ctx.state) === null || ref3 === void 0 ? void 0 : ref3.loading;
104
106
  // Make sure value is an array if allowMultiple is true
105
107
  if (allowMultiple && !Array.isArray(value)) {
106
108
  value = typeof value === 'string' ? [
@@ -155,7 +157,7 @@ function ListVariable({ name }) {
155
157
  children: [
156
158
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
157
159
  id: name,
158
- children: name
160
+ children: label
159
161
  }),
160
162
  /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Select, {
161
163
  sx: {
@@ -195,13 +197,19 @@ function ListVariable({ name }) {
195
197
  }
196
198
  function TextVariable({ name }) {
197
199
  const { state } = (0, _context.useTemplateVariable)(name);
198
- const s = (0, _context.useTemplateVariableStore)();
199
- const setVariableValue = s.setVariableValue;
200
- const ref = (0, _react.useRef)(null);
200
+ var ref;
201
+ const [tempValue, setTempValue] = (0, _react.useState)((ref = state === null || state === void 0 ? void 0 : state.value) !== null && ref !== void 0 ? ref : '');
202
+ const { setVariableValue } = (0, _context.useTemplateVariableActions)();
203
+ (0, _react.useEffect)(()=>{
204
+ var ref;
205
+ setTempValue((ref = state === null || state === void 0 ? void 0 : state.value) !== null && ref !== void 0 ? ref : '');
206
+ }, [
207
+ state === null || state === void 0 ? void 0 : state.value
208
+ ]);
201
209
  return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
202
- ref: ref,
203
- defaultValue: state === null || state === void 0 ? void 0 : state.value,
204
- onBlur: (e)=>setVariableValue(name, e.target.value),
210
+ value: tempValue,
211
+ onChange: (e)=>setTempValue(e.target.value),
212
+ onBlur: ()=>setVariableValue(name, tempValue),
205
213
  placeholder: name,
206
214
  label: name
207
215
  });