@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
@@ -1,140 +0,0 @@
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
- usePanelDrawerModel: ()=>usePanelDrawerModel,
25
- usePanelSpecState: ()=>usePanelSpecState
26
- });
27
- const _react = require("react");
28
- const _pluginSystem = require("@perses-dev/plugin-system");
29
- const _useImmer = require("use-immer");
30
- const _context = require("../../context");
31
- const _functions = require("../../utils/functions");
32
- function usePanelDrawerModel() {
33
- const { panelDrawer } = (0, _context.useDashboardApp)();
34
- const { panels , updatePanel } = (0, _context.usePanels)();
35
- // If we're closed, no model to return
36
- if (panelDrawer === undefined) {
37
- return undefined;
38
- }
39
- // If we don't have a panel key, we're adding a new panel
40
- const { panelKey , groupIndex } = panelDrawer;
41
- if (panelKey === undefined) {
42
- return {
43
- drawerTitle: 'Add Panel',
44
- submitButtonText: 'Add',
45
- initialValues: {
46
- name: '',
47
- description: '',
48
- group: groupIndex !== null && groupIndex !== void 0 ? groupIndex : 0,
49
- kind: '',
50
- spec: {}
51
- },
52
- applyChanges: (values)=>{
53
- const { name , description , group , kind , spec } = values;
54
- const panelKey = (0, _functions.removeWhiteSpacesAndSpecialCharacters)(name);
55
- updatePanel(panelKey, {
56
- kind: 'Panel',
57
- spec: {
58
- display: {
59
- name,
60
- description
61
- },
62
- plugin: {
63
- kind,
64
- spec
65
- }
66
- }
67
- }, group);
68
- }
69
- };
70
- }
71
- // Otherwise we have a panel key, so we're trying to edit an existing panel
72
- const existingPanel = panels[panelKey];
73
- // TODO: Can we better express this via the type system on the dashboard store to avoid these states?
74
- if (existingPanel === undefined) {
75
- throw new Error(`Cannot find existing panel '${panelKey}' to edit`);
76
- }
77
- if (groupIndex === undefined) {
78
- throw new Error(`Cannot edit existing panel '${panelKey}' without its group index`);
79
- }
80
- var _description;
81
- return {
82
- drawerTitle: 'Edit Panel',
83
- submitButtonText: 'Apply',
84
- initialValues: {
85
- name: existingPanel.spec.display.name,
86
- description: (_description = existingPanel.spec.display.description) !== null && _description !== void 0 ? _description : '',
87
- group: groupIndex,
88
- kind: existingPanel.spec.plugin.kind,
89
- spec: existingPanel.spec.plugin.spec
90
- },
91
- applyChanges: (values)=>{
92
- const { name , description , group , kind , spec } = values;
93
- updatePanel(panelKey, {
94
- kind: 'Panel',
95
- spec: {
96
- display: {
97
- name,
98
- description
99
- },
100
- plugin: {
101
- kind,
102
- spec
103
- }
104
- }
105
- });
106
- if (group !== groupIndex) {
107
- // TO DO: need to move panel if panel group changes
108
- }
109
- }
110
- };
111
- }
112
- function usePanelSpecState(panelPluginKind, initialState) {
113
- // Keeping track of spec values by kind allows users to switch between panel types and come back with their old
114
- // values intact from before the switch
115
- const [specByKind, setSpecByKind] = (0, _useImmer.useImmer)({
116
- [panelPluginKind]: initialState
117
- });
118
- const { data: plugin } = (0, _pluginSystem.usePlugin)('Panel', panelPluginKind, {
119
- enabled: panelPluginKind !== ''
120
- });
121
- const pluginInitialSpec = (0, _react.useMemo)(()=>{
122
- return plugin === null || plugin === void 0 ? void 0 : plugin.createInitialOptions();
123
- }, [
124
- plugin
125
- ]);
126
- var _panelPluginKind;
127
- // Use the value in specByKind or if unset, use the initial values from the plugin (which could still be undefined)
128
- const spec = (_panelPluginKind = specByKind[panelPluginKind]) !== null && _panelPluginKind !== void 0 ? _panelPluginKind : pluginInitialSpec;
129
- // TODO: Do we want to expose more of a immer style API to plugin authors for managing their state, rather than the
130
- // current "onChange" API?
131
- const onSpecChange = (next)=>{
132
- setSpecByKind((draft)=>{
133
- draft[panelPluginKind] = next;
134
- });
135
- };
136
- return {
137
- spec,
138
- onSpecChange
139
- };
140
- }
@@ -1,57 +0,0 @@
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
- createDashboardAppSlice: ()=>createDashboardAppSlice,
25
- useDashboardApp: ()=>useDashboardApp
26
- });
27
- const _immer = require("zustand/middleware/immer");
28
- const _dashboardProvider = require("./DashboardProvider");
29
- const createDashboardAppSlice = (0, _immer.immer)((set)=>({
30
- openPanelDrawer: ({ groupIndex , panelKey })=>set((state)=>{
31
- state.panelDrawer = {
32
- groupIndex,
33
- panelKey
34
- };
35
- }),
36
- closePanelDrawer: ()=>set((state)=>{
37
- state.panelDrawer = undefined;
38
- }),
39
- openPanelGroupDialog: (groupIndex)=>set((state)=>{
40
- state.panelGroupDialog = {
41
- groupIndex
42
- };
43
- }),
44
- closePanelGroupDialog: ()=>set((state)=>{
45
- state.panelGroupDialog = undefined;
46
- })
47
- }));
48
- function useDashboardApp() {
49
- return (0, _dashboardProvider.useDashboardStore)(({ panelDrawer , openPanelDrawer , closePanelDrawer , panelGroupDialog , openPanelGroupDialog , closePanelGroupDialog , })=>({
50
- panelDrawer,
51
- openPanelDrawer,
52
- closePanelDrawer,
53
- panelGroupDialog,
54
- openPanelGroupDialog,
55
- closePanelGroupDialog
56
- }));
57
- }
@@ -1,128 +0,0 @@
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
- usePanels: ()=>usePanels,
25
- useEditMode: ()=>useEditMode,
26
- useDashboard: ()=>useDashboard,
27
- DashboardContext: ()=>DashboardContext,
28
- useDashboardStore: ()=>useDashboardStore,
29
- DashboardProvider: ()=>DashboardProvider
30
- });
31
- const _jsxRuntime = require("react/jsx-runtime");
32
- const _zustand = require("zustand");
33
- const _immer = require("zustand/middleware/immer");
34
- const _shallow = /*#__PURE__*/ _interopRequireDefault(require("zustand/shallow"));
35
- const _react = require("react");
36
- const _immer1 = /*#__PURE__*/ _interopRequireDefault(require("immer"));
37
- const _dashboardAppSlice = require("./DashboardAppSlice");
38
- const _layoutsSlice = require("./LayoutsSlice");
39
- function _interopRequireDefault(obj) {
40
- return obj && obj.__esModule ? obj : {
41
- default: obj
42
- };
43
- }
44
- function usePanels() {
45
- return useDashboardStore(({ panels , updatePanel })=>({
46
- panels,
47
- updatePanel
48
- }));
49
- }
50
- function useEditMode() {
51
- return useDashboardStore(({ isEditMode , setEditMode })=>({
52
- isEditMode,
53
- setEditMode
54
- }));
55
- }
56
- function useDashboard() {
57
- const selectDashboardSpec = (state)=>{
58
- return (0, _immer1.default)(state.dashboard, (draftState)=>{
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
- draftState.panels = state.panels;
61
- draftState.layouts = state.layouts;
62
- });
63
- };
64
- const dashboard = useDashboardStore(selectDashboardSpec);
65
- return {
66
- dashboard
67
- };
68
- }
69
- const DashboardContext = /*#__PURE__*/ (0, _react.createContext)(undefined);
70
- function useDashboardStore(selector) {
71
- const store = (0, _react.useContext)(DashboardContext);
72
- if (store === undefined) {
73
- throw new Error('No DashboardContext found. Did you forget a Provider?');
74
- }
75
- return (0, _zustand.useStore)(store, selector, _shallow.default);
76
- }
77
- function DashboardProvider(props) {
78
- const { children , initialState: { dashboardSpec , isEditMode } , } = props;
79
- const { layouts , panels } = dashboardSpec;
80
- const dashboardStore = (0, _zustand.createStore)()((0, _immer.immer)((set, get, api)=>{
81
- return {
82
- ...(0, _dashboardAppSlice.createDashboardAppSlice)(set, get, api, []),
83
- ...(0, _layoutsSlice.createLayoutsSlice)(set, get, api, []),
84
- layouts,
85
- panels,
86
- dashboard: dashboardSpec,
87
- updatePanel: (name, panel, groupIndex = 0)=>{
88
- return set((state)=>{
89
- // add new panel to layouts if panels[name] is undefined
90
- if (state.panels[name] === undefined) {
91
- var ref;
92
- // find maximum y so new panel is added to the end of the grid
93
- let maxY = 0;
94
- (ref = state.layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.spec.items.forEach((layout)=>{
95
- if (layout.y > maxY) {
96
- maxY = layout.y;
97
- }
98
- });
99
- const panelLayout = {
100
- x: 0,
101
- y: maxY + 1,
102
- width: 12,
103
- height: 6,
104
- content: {
105
- $ref: `#/spec/panels/${name}`
106
- }
107
- };
108
- const layouts = state.layouts;
109
- if (layouts && layouts[groupIndex]) {
110
- var ref1;
111
- (ref1 = layouts[groupIndex]) === null || ref1 === void 0 ? void 0 : ref1.spec.items.push(panelLayout);
112
- }
113
- }
114
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
115
- state.panels[name] = panel;
116
- });
117
- },
118
- isEditMode: !!isEditMode,
119
- setEditMode: (isEditMode)=>set({
120
- isEditMode
121
- })
122
- };
123
- }));
124
- return /*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardContext.Provider, {
125
- value: dashboardStore,
126
- children: children
127
- });
128
- }
@@ -1,55 +0,0 @@
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
- createLayoutsSlice: ()=>createLayoutsSlice,
25
- useLayouts: ()=>useLayouts
26
- });
27
- const _immer = require("zustand/middleware/immer");
28
- const _dashboardProvider = require("./DashboardProvider");
29
- const createLayoutsSlice = (0, _immer.immer)((set)=>{
30
- return {
31
- updateLayout: (layout, index)=>set((state)=>{
32
- if (index === undefined) {
33
- state.layouts.unshift(layout);
34
- } else {
35
- state.layouts[index] = layout;
36
- }
37
- }),
38
- addItemToLayout: (index, item)=>{
39
- return set((state)=>{
40
- const layouts = state.layouts;
41
- if (layouts && layouts[index]) {
42
- var ref;
43
- (ref = layouts[index]) === null || ref === void 0 ? void 0 : ref.spec.items.push(item);
44
- }
45
- });
46
- }
47
- };
48
- });
49
- function useLayouts() {
50
- return (0, _dashboardProvider.useDashboardStore)(({ layouts , updateLayout , addItemToLayout })=>({
51
- layouts,
52
- updateLayout,
53
- addItemToLayout
54
- }));
55
- }
@@ -1,7 +0,0 @@
1
- /// <reference types="react" />
2
- import { OptionsEditorProps } from '@perses-dev/plugin-system';
3
- export interface PanelSpecEditorProps extends OptionsEditorProps<unknown> {
4
- panelPluginKind: string;
5
- }
6
- export declare function PanelSpecEditor(props: PanelSpecEditorProps): JSX.Element | null;
7
- //# sourceMappingURL=PanelSpecEditor.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PanelSpecEditor.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelSpecEditor.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAE,kBAAkB,EAAa,MAAM,2BAA2B,CAAC;AAE1E,MAAM,WAAW,oBAAqB,SAAQ,kBAAkB,CAAC,OAAO,CAAC;IACvE,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,sBAkB1D"}
@@ -1,34 +0,0 @@
1
- // Copyright 2022 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
- import { usePlugin } from '@perses-dev/plugin-system';
15
- export function PanelSpecEditor(props) {
16
- const { panelPluginKind , ...others } = props;
17
- const { data: plugin , isLoading } = usePlugin('Panel', panelPluginKind, {
18
- useErrorBoundary: true,
19
- enabled: panelPluginKind !== ''
20
- });
21
- // TODO: Proper loading indicator
22
- if (isLoading) {
23
- return null;
24
- }
25
- if (plugin === undefined) {
26
- throw new Error(`Missing OptionsEditorComponent for Panel plugin with kind '${panelPluginKind}'`);
27
- }
28
- const { OptionsEditorComponent } = plugin;
29
- return /*#__PURE__*/ _jsx(OptionsEditorComponent, {
30
- ...others
31
- });
32
- }
33
-
34
- //# sourceMappingURL=PanelSpecEditor.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/components/PanelDrawer/PanelSpecEditor.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 { OptionsEditorProps, usePlugin } from '@perses-dev/plugin-system';\n\nexport interface PanelSpecEditorProps extends OptionsEditorProps<unknown> {\n panelPluginKind: string;\n}\n\nexport function PanelSpecEditor(props: PanelSpecEditorProps) {\n const { panelPluginKind, ...others } = props;\n const { data: plugin, isLoading } = usePlugin('Panel', panelPluginKind, {\n useErrorBoundary: true,\n enabled: panelPluginKind !== '',\n });\n\n // TODO: Proper loading indicator\n if (isLoading) {\n return null;\n }\n\n if (plugin === undefined) {\n throw new Error(`Missing OptionsEditorComponent for Panel plugin with kind '${panelPluginKind}'`);\n }\n\n const { OptionsEditorComponent } = plugin;\n return <OptionsEditorComponent {...others} />;\n}\n"],"names":["usePlugin","PanelSpecEditor","props","panelPluginKind","others","data","plugin","isLoading","useErrorBoundary","enabled","undefined","Error","OptionsEditorComponent"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAA6BA,SAAS,QAAQ,2BAA2B,CAAC;AAM1E,OAAO,SAASC,eAAe,CAACC,KAA2B,EAAE;IAC3D,MAAM,EAAEC,eAAe,CAAA,EAAE,GAAGC,MAAM,EAAE,GAAGF,KAAK,AAAC;IAC7C,MAAM,EAAEG,IAAI,EAAEC,MAAM,CAAA,EAAEC,SAAS,CAAA,EAAE,GAAGP,SAAS,CAAC,OAAO,EAAEG,eAAe,EAAE;QACtEK,gBAAgB,EAAE,IAAI;QACtBC,OAAO,EAAEN,eAAe,KAAK,EAAE;KAChC,CAAC,AAAC;IAEH,iCAAiC;IACjC,IAAII,SAAS,EAAE;QACb,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAID,MAAM,KAAKI,SAAS,EAAE;QACxB,MAAM,IAAIC,KAAK,CAAC,CAAC,2DAA2D,EAAER,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IACpG,CAAC;IAED,MAAM,EAAES,sBAAsB,CAAA,EAAE,GAAGN,MAAM,AAAC;IAC1C,qBAAO,KAACM,sBAAsB;QAAE,GAAGR,MAAM;MAAI,CAAC;AAChD,CAAC"}
@@ -1,8 +0,0 @@
1
- /// <reference types="react" />
2
- import { SelectProps } from '@mui/material';
3
- export declare type PanelTypeSelectProps = Omit<SelectProps<string>, 'children'>;
4
- /**
5
- * Displays a MUI Select input for selecing a Panel type. Queries the plugin system to get the list of all panel types.
6
- */
7
- export declare function PanelTypeSelect(props: PanelTypeSelectProps): JSX.Element;
8
- //# sourceMappingURL=PanelTypeSelect.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PanelTypeSelect.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelTypeSelect.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAU,WAAW,EAAY,MAAM,eAAe,CAAC;AAG9D,oBAAY,oBAAoB,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;AAEzE;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,eAiB1D"}
@@ -1,34 +0,0 @@
1
- // Copyright 2022 The Perses Authors
2
- // Licensed under the Apache License, Version 2.0 (the "License");
3
- // you may not use this file except in compliance with the License.
4
- // You may obtain a copy of the License at
5
- //
6
- // http://www.apache.org/licenses/LICENSE-2.0
7
- //
8
- // Unless required by applicable law or agreed to in writing, software
9
- // distributed under the License is distributed on an "AS IS" BASIS,
10
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
- // See the License for the specific language governing permissions and
12
- // limitations under the License.
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
- import { Select, MenuItem } from '@mui/material';
15
- import { useListPluginMetadata } from '@perses-dev/plugin-system';
16
- /**
17
- * Displays a MUI Select input for selecing a Panel type. Queries the plugin system to get the list of all panel types.
18
- */ export function PanelTypeSelect(props) {
19
- const { value: propValue , ...others } = props;
20
- const { data , isLoading } = useListPluginMetadata('Panel');
21
- // Pass an empty value while options are still loading so MUI doesn't complain about us using an "out of range" value
22
- const value = propValue !== '' && isLoading ? '' : propValue;
23
- // TODO: Does this need a loading indicator of some kind?
24
- return /*#__PURE__*/ _jsx(Select, {
25
- ...others,
26
- value: value,
27
- children: data === null || data === void 0 ? void 0 : data.map((metadata)=>/*#__PURE__*/ _jsx(MenuItem, {
28
- value: metadata.kind,
29
- children: metadata.display.name
30
- }, metadata.kind))
31
- });
32
- }
33
-
34
- //# sourceMappingURL=PanelTypeSelect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/components/PanelDrawer/PanelTypeSelect.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 { Select, SelectProps, MenuItem } from '@mui/material';\nimport { useListPluginMetadata } from '@perses-dev/plugin-system';\n\nexport type PanelTypeSelectProps = Omit<SelectProps<string>, 'children'>;\n\n/**\n * Displays a MUI Select input for selecing a Panel type. Queries the plugin system to get the list of all panel types.\n */\nexport function PanelTypeSelect(props: PanelTypeSelectProps) {\n const { value: propValue, ...others } = props;\n const { data, isLoading } = useListPluginMetadata('Panel');\n\n // Pass an empty value while options are still loading so MUI doesn't complain about us using an \"out of range\" value\n const value = propValue !== '' && isLoading ? '' : propValue;\n\n // TODO: Does this need a loading indicator of some kind?\n return (\n <Select {...others} value={value}>\n {data?.map((metadata) => (\n <MenuItem key={metadata.kind} value={metadata.kind}>\n {metadata.display.name}\n </MenuItem>\n ))}\n </Select>\n );\n}\n"],"names":["Select","MenuItem","useListPluginMetadata","PanelTypeSelect","props","value","propValue","others","data","isLoading","map","metadata","kind","display","name"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,MAAM,EAAeC,QAAQ,QAAQ,eAAe,CAAC;AAC9D,SAASC,qBAAqB,QAAQ,2BAA2B,CAAC;AAIlE;;CAEC,GACD,OAAO,SAASC,eAAe,CAACC,KAA2B,EAAE;IAC3D,MAAM,EAAEC,KAAK,EAAEC,SAAS,CAAA,EAAE,GAAGC,MAAM,EAAE,GAAGH,KAAK,AAAC;IAC9C,MAAM,EAAEI,IAAI,CAAA,EAAEC,SAAS,CAAA,EAAE,GAAGP,qBAAqB,CAAC,OAAO,CAAC,AAAC;IAE3D,qHAAqH;IACrH,MAAMG,KAAK,GAAGC,SAAS,KAAK,EAAE,IAAIG,SAAS,GAAG,EAAE,GAAGH,SAAS,AAAC;IAE7D,yDAAyD;IACzD,qBACE,KAACN,MAAM;QAAE,GAAGO,MAAM;QAAEF,KAAK,EAAEA,KAAK;kBAC7BG,IAAI,aAAJA,IAAI,WAAK,GAATA,KAAAA,CAAS,GAATA,IAAI,CAAEE,GAAG,CAAC,CAACC,QAAQ,iBAClB,KAACV,QAAQ;gBAAqBI,KAAK,EAAEM,QAAQ,CAACC,IAAI;0BAC/CD,QAAQ,CAACE,OAAO,CAACC,IAAI;eADTH,QAAQ,CAACC,IAAI,CAEjB,AACZ,CAAC;MACK,CACT;AACJ,CAAC"}
@@ -1,27 +0,0 @@
1
- export interface PanelEditorFormValues {
2
- name: string;
3
- description: string;
4
- group: number;
5
- kind: string;
6
- spec: unknown;
7
- }
8
- interface PanelDrawerModel {
9
- drawerTitle: string;
10
- submitButtonText: string;
11
- initialValues: PanelEditorFormValues;
12
- applyChanges: (values: PanelEditorFormValues) => void;
13
- }
14
- /**
15
- * Returns props that are different depending on whether the PanelDrawer has been opened in add or edit mode. If the
16
- * drawer isn't open at all, returns undefined.
17
- */
18
- export declare function usePanelDrawerModel(): PanelDrawerModel | undefined;
19
- /**
20
- * Manages panel plugin spec state. The spec will be undefined while a plugin is being loaded.
21
- */
22
- export declare function usePanelSpecState(panelPluginKind: string, initialState: unknown): {
23
- spec: unknown;
24
- onSpecChange: (next: unknown) => void;
25
- };
26
- export {};
27
- //# sourceMappingURL=panel-editor-model.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"panel-editor-model.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/panel-editor-model.ts"],"names":[],"mappings":"AAmBA,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;CACf;AAGD,UAAU,gBAAgB;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;IACzB,aAAa,EAAE,qBAAqB,CAAC;IACrC,YAAY,EAAE,CAAC,MAAM,EAAE,qBAAqB,KAAK,IAAI,CAAC;CACvD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,GAAG,SAAS,CAkFlE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO;;yBAYlD,OAAO;EAUpC"}
@@ -1,133 +0,0 @@
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 { useMemo } from 'react';
14
- import { usePlugin } from '@perses-dev/plugin-system';
15
- import { useImmer } from 'use-immer';
16
- import { useDashboardApp, usePanels } from '../../context';
17
- import { removeWhiteSpacesAndSpecialCharacters } from '../../utils/functions';
18
- /**
19
- * Returns props that are different depending on whether the PanelDrawer has been opened in add or edit mode. If the
20
- * drawer isn't open at all, returns undefined.
21
- */ export function usePanelDrawerModel() {
22
- const { panelDrawer } = useDashboardApp();
23
- const { panels , updatePanel } = usePanels();
24
- // If we're closed, no model to return
25
- if (panelDrawer === undefined) {
26
- return undefined;
27
- }
28
- // If we don't have a panel key, we're adding a new panel
29
- const { panelKey , groupIndex } = panelDrawer;
30
- if (panelKey === undefined) {
31
- return {
32
- drawerTitle: 'Add Panel',
33
- submitButtonText: 'Add',
34
- initialValues: {
35
- name: '',
36
- description: '',
37
- group: groupIndex !== null && groupIndex !== void 0 ? groupIndex : 0,
38
- kind: '',
39
- spec: {}
40
- },
41
- applyChanges: (values)=>{
42
- const { name , description , group , kind , spec } = values;
43
- const panelKey = removeWhiteSpacesAndSpecialCharacters(name);
44
- updatePanel(panelKey, {
45
- kind: 'Panel',
46
- spec: {
47
- display: {
48
- name,
49
- description
50
- },
51
- plugin: {
52
- kind,
53
- spec
54
- }
55
- }
56
- }, group);
57
- }
58
- };
59
- }
60
- // Otherwise we have a panel key, so we're trying to edit an existing panel
61
- const existingPanel = panels[panelKey];
62
- // TODO: Can we better express this via the type system on the dashboard store to avoid these states?
63
- if (existingPanel === undefined) {
64
- throw new Error(`Cannot find existing panel '${panelKey}' to edit`);
65
- }
66
- if (groupIndex === undefined) {
67
- throw new Error(`Cannot edit existing panel '${panelKey}' without its group index`);
68
- }
69
- var _description;
70
- return {
71
- drawerTitle: 'Edit Panel',
72
- submitButtonText: 'Apply',
73
- initialValues: {
74
- name: existingPanel.spec.display.name,
75
- description: (_description = existingPanel.spec.display.description) !== null && _description !== void 0 ? _description : '',
76
- group: groupIndex,
77
- kind: existingPanel.spec.plugin.kind,
78
- spec: existingPanel.spec.plugin.spec
79
- },
80
- applyChanges: (values)=>{
81
- const { name , description , group , kind , spec } = values;
82
- updatePanel(panelKey, {
83
- kind: 'Panel',
84
- spec: {
85
- display: {
86
- name,
87
- description
88
- },
89
- plugin: {
90
- kind,
91
- spec
92
- }
93
- }
94
- });
95
- if (group !== groupIndex) {
96
- // TO DO: need to move panel if panel group changes
97
- }
98
- }
99
- };
100
- }
101
- /**
102
- * Manages panel plugin spec state. The spec will be undefined while a plugin is being loaded.
103
- */ export function usePanelSpecState(panelPluginKind, initialState) {
104
- // Keeping track of spec values by kind allows users to switch between panel types and come back with their old
105
- // values intact from before the switch
106
- const [specByKind, setSpecByKind] = useImmer({
107
- [panelPluginKind]: initialState
108
- });
109
- const { data: plugin } = usePlugin('Panel', panelPluginKind, {
110
- enabled: panelPluginKind !== ''
111
- });
112
- const pluginInitialSpec = useMemo(()=>{
113
- return plugin === null || plugin === void 0 ? void 0 : plugin.createInitialOptions();
114
- }, [
115
- plugin
116
- ]);
117
- var _panelPluginKind;
118
- // Use the value in specByKind or if unset, use the initial values from the plugin (which could still be undefined)
119
- const spec = (_panelPluginKind = specByKind[panelPluginKind]) !== null && _panelPluginKind !== void 0 ? _panelPluginKind : pluginInitialSpec;
120
- // TODO: Do we want to expose more of a immer style API to plugin authors for managing their state, rather than the
121
- // current "onChange" API?
122
- const onSpecChange = (next)=>{
123
- setSpecByKind((draft)=>{
124
- draft[panelPluginKind] = next;
125
- });
126
- };
127
- return {
128
- spec,
129
- onSpecChange
130
- };
131
- }
132
-
133
- //# sourceMappingURL=panel-editor-model.js.map