@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.
- package/dist/cjs/components/Dashboard.js +7 -11
- package/dist/cjs/components/DashboardToolbar.js +4 -4
- package/dist/cjs/components/GridLayout/GridItemContent.js +13 -13
- package/dist/cjs/components/GridLayout/GridLayout.js +24 -21
- package/dist/cjs/components/GridLayout/GridTitle.js +27 -5
- package/dist/cjs/components/Panel/DeletePanelDialog.js +91 -0
- package/dist/cjs/components/Panel/Panel.js +16 -5
- package/dist/cjs/components/Panel/Panel.test.js +12 -4
- package/dist/cjs/components/Panel/PanelContent.js +3 -2
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +13 -12
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +8 -12
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +77 -35
- package/dist/cjs/components/PanelDrawer/PanelPreview.js +48 -0
- package/dist/cjs/components/PanelGroupDialog/DeletePanelGroupDialog.js +86 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +12 -19
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +10 -31
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +2 -2
- package/dist/cjs/components/Variables/Variable.js +19 -11
- package/dist/cjs/components/Variables/VariableEditor.js +207 -0
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +236 -0
- package/dist/cjs/components/Variables/VariableEditorForm/index.js +28 -0
- package/dist/cjs/components/Variables/VariableEditorForm/variable-editor-form-model.js +88 -0
- package/dist/cjs/components/Variables/VariableList.js +50 -69
- package/dist/cjs/components/Variables/index.js +1 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +70 -0
- package/dist/cjs/context/DashboardProvider/common.js +18 -0
- package/dist/cjs/context/DashboardProvider/dashboard-provider-api.js +71 -0
- package/dist/cjs/context/DashboardProvider/index.js +29 -0
- package/dist/cjs/context/DashboardProvider/layout-slice.js +200 -0
- package/dist/cjs/context/DashboardProvider/panel-editing-slice.js +156 -0
- package/dist/{context/DashboardAppSlice.js → cjs/context/DashboardProvider/panel-group-slice.js} +18 -25
- package/dist/cjs/context/DatasourceStoreProvider.js +109 -7
- package/dist/cjs/context/TemplateVariableProvider.js +8 -1
- package/dist/cjs/context/index.js +0 -2
- package/dist/cjs/test/testDashboard.js +13 -1
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +6 -7
- package/dist/cjs/views/ViewDashboard/tests/panelGroups.test.js +165 -0
- package/dist/components/Dashboard.d.ts +1 -4
- package/dist/components/Dashboard.d.ts.map +1 -1
- package/dist/components/Dashboard.js +8 -12
- package/dist/components/Dashboard.js.map +1 -1
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +5 -5
- package/dist/components/DashboardToolbar.js.map +1 -1
- package/dist/components/GridLayout/GridItemContent.d.ts +3 -3
- package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
- package/dist/components/GridLayout/GridItemContent.js +14 -14
- package/dist/components/GridLayout/GridItemContent.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +2 -3
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +24 -21
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/GridTitle.d.ts.map +1 -1
- package/dist/components/GridLayout/GridTitle.js +28 -6
- package/dist/components/GridLayout/GridTitle.js.map +1 -1
- package/dist/components/Panel/DeletePanelDialog.d.ts +5 -0
- package/dist/components/Panel/DeletePanelDialog.d.ts.map +1 -0
- package/dist/components/Panel/DeletePanelDialog.js +80 -0
- package/dist/components/Panel/DeletePanelDialog.js.map +1 -0
- package/dist/components/Panel/Panel.d.ts +1 -1
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +17 -6
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/Panel.test.js +7 -4
- package/dist/components/Panel/Panel.test.js.map +1 -1
- package/dist/components/Panel/PanelContent.d.ts +4 -1
- package/dist/components/Panel/PanelContent.d.ts.map +1 -1
- package/dist/components/Panel/PanelContent.js +3 -2
- package/dist/components/Panel/PanelContent.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +14 -13
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js +8 -12
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +3 -3
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelEditorForm.js +78 -36
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
- package/dist/components/PanelDrawer/PanelPreview.d.ts +4 -0
- package/dist/components/PanelDrawer/PanelPreview.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelPreview.js +42 -0
- package/dist/components/PanelDrawer/PanelPreview.js.map +1 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts +4 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.d.ts.map +1 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js +75 -0
- package/dist/components/PanelGroupDialog/DeletePanelGroupDialog.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +13 -20
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +10 -31
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +3 -3
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/Variable.js +21 -13
- package/dist/components/Variables/Variable.js.map +1 -1
- package/dist/components/Variables/VariableEditor.d.ts +8 -0
- package/dist/components/Variables/VariableEditor.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditor.js +196 -0
- package/dist/components/Variables/VariableEditor.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts +8 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +225 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts +2 -0
- package/dist/components/Variables/VariableEditorForm/index.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/index.js +15 -0
- package/dist/components/Variables/VariableEditorForm/index.js.map +1 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts +21 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.d.ts.map +1 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js +76 -0
- package/dist/components/Variables/VariableEditorForm/variable-editor-form-model.js.map +1 -0
- package/dist/components/Variables/VariableList.d.ts.map +1 -1
- package/dist/components/Variables/VariableList.js +48 -72
- package/dist/components/Variables/VariableList.js.map +1 -1
- package/dist/components/Variables/index.d.ts +1 -0
- package/dist/components/Variables/index.d.ts.map +1 -1
- package/dist/components/Variables/index.js +1 -0
- package/dist/components/Variables/index.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +23 -0
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -0
- package/dist/context/DashboardProvider/DashboardProvider.js +52 -0
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -0
- package/dist/context/DashboardProvider/common.d.ts +5 -0
- package/dist/context/DashboardProvider/common.d.ts.map +1 -0
- package/dist/context/DashboardProvider/common.js +17 -0
- package/dist/context/DashboardProvider/common.js.map +1 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts +32 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.d.ts.map +1 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.js +56 -0
- package/dist/context/DashboardProvider/dashboard-provider-api.js.map +1 -0
- package/dist/context/DashboardProvider/index.d.ts +3 -0
- package/dist/context/DashboardProvider/index.d.ts.map +1 -0
- package/dist/context/DashboardProvider/index.js +16 -0
- package/dist/context/DashboardProvider/index.js.map +1 -0
- package/dist/context/DashboardProvider/layout-slice.d.ts +57 -0
- package/dist/context/DashboardProvider/layout-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/layout-slice.js +196 -0
- package/dist/context/DashboardProvider/layout-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-editing-slice.d.ts +70 -0
- package/dist/context/DashboardProvider/panel-editing-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-editing-slice.js +152 -0
- package/dist/context/DashboardProvider/panel-editing-slice.js.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +15 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.js +32 -0
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -0
- package/dist/context/DatasourceStoreProvider.d.ts +10 -2
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -1
- package/dist/context/DatasourceStoreProvider.js +111 -9
- package/dist/context/DatasourceStoreProvider.js.map +1 -1
- package/dist/context/TemplateVariableProvider.d.ts +2 -0
- package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider.js +8 -1
- package/dist/context/TemplateVariableProvider.js.map +1 -1
- package/dist/context/index.d.ts +0 -2
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +0 -2
- package/dist/context/index.js.map +1 -1
- package/dist/test/plugin-registry.d.ts +2 -2
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js.map +1 -1
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +13 -1
- package/dist/test/testDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +6 -7
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts +2 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.d.ts.map +1 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.js +158 -0
- package/dist/views/ViewDashboard/tests/panelGroups.test.js.map +1 -0
- package/package.json +4 -4
- package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +0 -40
- package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +0 -38
- package/dist/cjs/components/PanelDrawer/panel-editor-model.js +0 -140
- package/dist/cjs/context/DashboardAppSlice.js +0 -57
- package/dist/cjs/context/DashboardProvider.js +0 -128
- package/dist/cjs/context/LayoutsSlice.js +0 -55
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +0 -7
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelSpecEditor.js +0 -34
- package/dist/components/PanelDrawer/PanelSpecEditor.js.map +0 -1
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +0 -8
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelTypeSelect.js +0 -34
- package/dist/components/PanelDrawer/PanelTypeSelect.js.map +0 -1
- package/dist/components/PanelDrawer/panel-editor-model.d.ts +0 -27
- package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +0 -1
- package/dist/components/PanelDrawer/panel-editor-model.js +0 -133
- package/dist/components/PanelDrawer/panel-editor-model.js.map +0 -1
- package/dist/context/DashboardAppSlice.d.ts +0 -26
- package/dist/context/DashboardAppSlice.d.ts.map +0 -1
- package/dist/context/DashboardAppSlice.js.map +0 -1
- package/dist/context/DashboardProvider.d.ts +0 -36
- package/dist/context/DashboardProvider.d.ts.map +0 -1
- package/dist/context/DashboardProvider.js +0 -107
- package/dist/context/DashboardProvider.js.map +0 -1
- package/dist/context/LayoutsSlice.d.ts +0 -12
- package/dist/context/LayoutsSlice.d.ts.map +0 -1
- package/dist/context/LayoutsSlice.js +0 -43
- package/dist/context/LayoutsSlice.js.map +0 -1
|
@@ -0,0 +1,156 @@
|
|
|
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, "createPanelEditorSlice", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>createPanelEditorSlice
|
|
20
|
+
});
|
|
21
|
+
const _functions = require("../../utils/functions");
|
|
22
|
+
function createPanelEditorSlice(panels) {
|
|
23
|
+
// Return the state creator function for Zustand that uses the panels provided as intitial state
|
|
24
|
+
return (set, get)=>{
|
|
25
|
+
return {
|
|
26
|
+
panels,
|
|
27
|
+
panelEditor: undefined,
|
|
28
|
+
editPanel (item) {
|
|
29
|
+
const { panels , getPanelKey } = get();
|
|
30
|
+
// Ask the layout store for the panel key at that location
|
|
31
|
+
const panelKey = getPanelKey(item);
|
|
32
|
+
// Find the panel to edit
|
|
33
|
+
const panelToEdit = panels[panelKey];
|
|
34
|
+
if (panelToEdit === undefined) {
|
|
35
|
+
throw new Error(`Cannot find Panel with key '${panelKey}'`);
|
|
36
|
+
}
|
|
37
|
+
var _description;
|
|
38
|
+
const editorState = {
|
|
39
|
+
mode: 'Edit',
|
|
40
|
+
initialValues: {
|
|
41
|
+
name: panelToEdit.spec.display.name,
|
|
42
|
+
description: (_description = panelToEdit.spec.display.description) !== null && _description !== void 0 ? _description : '',
|
|
43
|
+
groupIndex: item.groupIndex,
|
|
44
|
+
kind: panelToEdit.spec.plugin.kind,
|
|
45
|
+
spec: panelToEdit.spec.plugin.spec
|
|
46
|
+
},
|
|
47
|
+
applyChanges: (next)=>{
|
|
48
|
+
const panelDefinititon = createPanelDefinitionFromEditorValues(next);
|
|
49
|
+
set((state)=>{
|
|
50
|
+
state.panels[panelKey] = panelDefinititon;
|
|
51
|
+
});
|
|
52
|
+
// Move the panel to another group if it changed
|
|
53
|
+
if (next.groupIndex !== item.groupIndex) {
|
|
54
|
+
get().movePanelToGroup(item, next.groupIndex);
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
close: ()=>{
|
|
58
|
+
set((state)=>{
|
|
59
|
+
state.panelEditor = undefined;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
// Open the editor with the new state
|
|
64
|
+
set((state)=>{
|
|
65
|
+
state.panelEditor = editorState;
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
addPanel (initialGroup) {
|
|
69
|
+
const editorState = {
|
|
70
|
+
mode: 'Add',
|
|
71
|
+
initialValues: {
|
|
72
|
+
name: '',
|
|
73
|
+
description: '',
|
|
74
|
+
groupIndex: initialGroup,
|
|
75
|
+
// TODO: If we knew what plugins were available (and how to create the initial spec), we might be able to
|
|
76
|
+
// set a smarter default here?
|
|
77
|
+
kind: '',
|
|
78
|
+
spec: {}
|
|
79
|
+
},
|
|
80
|
+
applyChanges: (next)=>{
|
|
81
|
+
const panelDef = createPanelDefinitionFromEditorValues(next);
|
|
82
|
+
const panelKey = (0, _functions.removeWhiteSpacesAndSpecialCharacters)(next.name);
|
|
83
|
+
set((state)=>{
|
|
84
|
+
state.panels[panelKey] = panelDef;
|
|
85
|
+
});
|
|
86
|
+
get().addPanelToGroup(panelKey, next.groupIndex);
|
|
87
|
+
},
|
|
88
|
+
close: ()=>{
|
|
89
|
+
set((state)=>{
|
|
90
|
+
state.panelEditor = undefined;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
// Open the editor with the new state
|
|
95
|
+
set((state)=>{
|
|
96
|
+
state.panelEditor = editorState;
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
deletePanels (items) {
|
|
100
|
+
const { mapPanelToPanelGroups , deletePanelInPanelGroup , getPanelKey } = get();
|
|
101
|
+
const map = mapPanelToPanelGroups();
|
|
102
|
+
// get panel key first before deleting panel from panel group since getPanelKey relies on index
|
|
103
|
+
const panels = items.map((panel)=>{
|
|
104
|
+
return {
|
|
105
|
+
...panel,
|
|
106
|
+
panelKey: getPanelKey(panel)
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
panels.forEach(({ panelKey , ...panel })=>{
|
|
110
|
+
var ref;
|
|
111
|
+
deletePanelInPanelGroup(panel);
|
|
112
|
+
// make sure panel is only referenced in one panel group before deleting it from state.panels
|
|
113
|
+
if (map[panelKey] && ((ref = map[panelKey]) === null || ref === void 0 ? void 0 : ref.length) === 1) {
|
|
114
|
+
set((state)=>{
|
|
115
|
+
delete state.panels[panelKey];
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
openDeletePanelDialog (item) {
|
|
121
|
+
set((state)=>{
|
|
122
|
+
var ref;
|
|
123
|
+
const { panels , getPanelKey } = get();
|
|
124
|
+
const panelKey = getPanelKey(item);
|
|
125
|
+
var _name;
|
|
126
|
+
state.deletePanelDialog = {
|
|
127
|
+
panelKey,
|
|
128
|
+
panelName: (_name = (ref = panels[panelKey]) === null || ref === void 0 ? void 0 : ref.spec.display.name) !== null && _name !== void 0 ? _name : '',
|
|
129
|
+
layoutItem: item
|
|
130
|
+
};
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
closeDeletePanelDialog () {
|
|
134
|
+
set((state)=>{
|
|
135
|
+
state.deletePanelDialog = undefined;
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
// Helper to create PanelDefinitions when saving
|
|
142
|
+
function createPanelDefinitionFromEditorValues(editorValues) {
|
|
143
|
+
return {
|
|
144
|
+
kind: 'Panel',
|
|
145
|
+
spec: {
|
|
146
|
+
display: {
|
|
147
|
+
name: editorValues.name,
|
|
148
|
+
description: editorValues.description !== '' ? editorValues.description : undefined
|
|
149
|
+
},
|
|
150
|
+
plugin: {
|
|
151
|
+
kind: editorValues.kind,
|
|
152
|
+
spec: editorValues.spec
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
package/dist/{context/DashboardAppSlice.js → cjs/context/DashboardProvider/panel-group-slice.js}
RENAMED
|
@@ -10,18 +10,15 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
closePanelDrawer: ()=>set((state)=>{
|
|
23
|
-
state.panelDrawer = undefined;
|
|
24
|
-
}),
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "createPanelGroupSlice", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>createPanelGroupSlice
|
|
20
|
+
});
|
|
21
|
+
const createPanelGroupSlice = (set)=>({
|
|
25
22
|
openPanelGroupDialog: (groupIndex)=>set((state)=>{
|
|
26
23
|
state.panelGroupDialog = {
|
|
27
24
|
groupIndex
|
|
@@ -29,17 +26,13 @@ export const createDashboardAppSlice = immer((set)=>({
|
|
|
29
26
|
}),
|
|
30
27
|
closePanelGroupDialog: ()=>set((state)=>{
|
|
31
28
|
state.panelGroupDialog = undefined;
|
|
29
|
+
}),
|
|
30
|
+
openDeletePanelGroupDialog: (groupIndex)=>set((state)=>{
|
|
31
|
+
state.deletePanelGroupDialog = {
|
|
32
|
+
groupIndex
|
|
33
|
+
};
|
|
34
|
+
}),
|
|
35
|
+
closeDeletePanelGroupDialog: ()=>set((state)=>{
|
|
36
|
+
state.deletePanelGroupDialog = undefined;
|
|
32
37
|
})
|
|
33
|
-
})
|
|
34
|
-
export function useDashboardApp() {
|
|
35
|
-
return useDashboardStore(({ panelDrawer , openPanelDrawer , closePanelDrawer , panelGroupDialog , openPanelGroupDialog , closePanelGroupDialog , })=>({
|
|
36
|
-
panelDrawer,
|
|
37
|
-
openPanelDrawer,
|
|
38
|
-
closePanelDrawer,
|
|
39
|
-
panelGroupDialog,
|
|
40
|
-
openPanelGroupDialog,
|
|
41
|
-
closePanelGroupDialog
|
|
42
|
-
}));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
//# sourceMappingURL=DashboardAppSlice.js.map
|
|
38
|
+
});
|
|
@@ -24,30 +24,98 @@ const _core = require("@perses-dev/core");
|
|
|
24
24
|
const _pluginSystem = require("@perses-dev/plugin-system");
|
|
25
25
|
function DatasourceStoreProvider(props) {
|
|
26
26
|
const { dashboardResource , datasourceApi , children } = props;
|
|
27
|
-
const
|
|
27
|
+
const { project } = dashboardResource.metadata;
|
|
28
|
+
const { getPlugin , listPluginMetadata } = (0, _pluginSystem.usePluginRegistry)();
|
|
29
|
+
const findDatasource = (0, _core.useEvent)(async (selector)=>{
|
|
28
30
|
// Try to find it in dashboard spec
|
|
29
31
|
const { datasources } = dashboardResource.spec;
|
|
30
32
|
const dashboardDatasource = findDashboardDatasource(datasources, selector);
|
|
31
33
|
if (dashboardDatasource !== undefined) {
|
|
32
|
-
return
|
|
34
|
+
return {
|
|
35
|
+
spec: dashboardDatasource,
|
|
36
|
+
proxyUrl: undefined
|
|
37
|
+
};
|
|
33
38
|
}
|
|
34
39
|
// Try to find it at the project level as a Datasource resource
|
|
35
|
-
const { project } = dashboardResource.metadata;
|
|
36
40
|
const datasource = await datasourceApi.getDatasource(project, selector);
|
|
37
41
|
if (datasource !== undefined) {
|
|
38
|
-
return
|
|
42
|
+
return {
|
|
43
|
+
spec: datasource.resource.spec,
|
|
44
|
+
proxyUrl: datasource.proxyUrl
|
|
45
|
+
};
|
|
39
46
|
}
|
|
40
47
|
// Try to find it at the global level as a GlobalDatasource resource
|
|
41
48
|
const globalDatasource = await datasourceApi.getGlobalDatasource(selector);
|
|
42
49
|
if (globalDatasource !== undefined) {
|
|
43
|
-
return
|
|
50
|
+
return {
|
|
51
|
+
spec: globalDatasource.resource.spec,
|
|
52
|
+
proxyUrl: globalDatasource.proxyUrl
|
|
53
|
+
};
|
|
44
54
|
}
|
|
45
55
|
throw new Error(`No datasource found for kind '${selector.kind}' and name '${selector.name}'`);
|
|
46
56
|
});
|
|
57
|
+
// Gets a datasource spec for a given selector
|
|
58
|
+
const getDatasource = (0, _react.useCallback)(async (selector)=>{
|
|
59
|
+
const { spec } = await findDatasource(selector);
|
|
60
|
+
return spec;
|
|
61
|
+
}, [
|
|
62
|
+
findDatasource
|
|
63
|
+
]);
|
|
64
|
+
// Given a Datasource selector, finds the spec for it and then uses its corresponding plugin the create a client
|
|
65
|
+
const getDatasourceClient = (0, _react.useCallback)(async function getClient(selector) {
|
|
66
|
+
const { kind } = selector;
|
|
67
|
+
const [{ spec , proxyUrl }, plugin] = await Promise.all([
|
|
68
|
+
findDatasource(selector),
|
|
69
|
+
getPlugin('Datasource', kind)
|
|
70
|
+
]);
|
|
71
|
+
return plugin.createClient(spec.plugin.spec, {
|
|
72
|
+
proxyUrl
|
|
73
|
+
});
|
|
74
|
+
}, [
|
|
75
|
+
findDatasource,
|
|
76
|
+
getPlugin
|
|
77
|
+
]);
|
|
78
|
+
const listDatasourceMetadata = (0, _core.useEvent)(async (datasourcePluginKind)=>{
|
|
79
|
+
const [pluginMetadata, datasources, globalDatasources] = await Promise.all([
|
|
80
|
+
listPluginMetadata('Datasource'),
|
|
81
|
+
datasourceApi.listDatasources(project, datasourcePluginKind),
|
|
82
|
+
datasourceApi.listGlobalDatasources(datasourcePluginKind)
|
|
83
|
+
]);
|
|
84
|
+
// Find the metadata for the plugin type they asked for so we can use it for the name of the default datasource
|
|
85
|
+
const datasourcePluginMetadata = pluginMetadata.find((metadata)=>metadata.kind === datasourcePluginKind);
|
|
86
|
+
if (datasourcePluginMetadata === undefined) {
|
|
87
|
+
throw new Error(`Could not find a Datasource plugin with kind '${datasourcePluginKind}'`);
|
|
88
|
+
}
|
|
89
|
+
// Get helper for de-duping results properly
|
|
90
|
+
const { results , addResult } = buildListDatasourceMetadataResults(datasourcePluginMetadata.display.name);
|
|
91
|
+
// Start with dashboard datasources that have highest precedence
|
|
92
|
+
if (dashboardResource.spec.datasources !== undefined) {
|
|
93
|
+
for(const selectorName in dashboardResource.spec.datasources){
|
|
94
|
+
const spec = dashboardResource.spec.datasources[selectorName];
|
|
95
|
+
if (spec === undefined || spec.plugin.kind !== datasourcePluginKind) continue;
|
|
96
|
+
addResult(spec, selectorName);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
// Now look at project-level datasources
|
|
100
|
+
for (const datasource of datasources){
|
|
101
|
+
const selectorName1 = datasource.metadata.name;
|
|
102
|
+
addResult(datasource.spec, selectorName1);
|
|
103
|
+
}
|
|
104
|
+
// And finally global datasources
|
|
105
|
+
for (const globalDatasource of globalDatasources){
|
|
106
|
+
const selectorName2 = globalDatasource.metadata.name;
|
|
107
|
+
addResult(globalDatasource.spec, selectorName2);
|
|
108
|
+
}
|
|
109
|
+
return results;
|
|
110
|
+
});
|
|
47
111
|
const ctxValue = (0, _react.useMemo)(()=>({
|
|
48
|
-
getDatasource
|
|
112
|
+
getDatasource,
|
|
113
|
+
getDatasourceClient,
|
|
114
|
+
listDatasourceMetadata
|
|
49
115
|
}), [
|
|
50
|
-
getDatasource
|
|
116
|
+
getDatasource,
|
|
117
|
+
getDatasourceClient,
|
|
118
|
+
listDatasourceMetadata
|
|
51
119
|
]);
|
|
52
120
|
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_pluginSystem.DatasourceStoreContext.Provider, {
|
|
53
121
|
value: ctxValue,
|
|
@@ -66,3 +134,37 @@ function findDashboardDatasource(dashboardDatasources, selector) {
|
|
|
66
134
|
// If only using a kind, try to find one with that kind that is the default
|
|
67
135
|
return Object.values(dashboardDatasources).find((ds)=>ds.plugin.kind === selector.kind && ds.default === true);
|
|
68
136
|
}
|
|
137
|
+
// Helper for building a list of DatasourceMetadata results that will take care of de-duping already used selectors
|
|
138
|
+
function buildListDatasourceMetadataResults(pluginDisplayName) {
|
|
139
|
+
const results = [];
|
|
140
|
+
const usedNames = new Set();
|
|
141
|
+
let defaultAdded = false;
|
|
142
|
+
const addResult = (spec, selectorName)=>{
|
|
143
|
+
var ref;
|
|
144
|
+
// If we haven't added a default yet and this is a default, add default option to the beginning of the results
|
|
145
|
+
if (spec.default && defaultAdded === false) {
|
|
146
|
+
results.unshift({
|
|
147
|
+
name: `Default ${pluginDisplayName}`,
|
|
148
|
+
selector: {
|
|
149
|
+
kind: spec.plugin.kind
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
defaultAdded = true;
|
|
153
|
+
}
|
|
154
|
+
// If we already have a datasource with this selector name, ignore it, otherwise add to end of list
|
|
155
|
+
if (usedNames.has(selectorName)) return;
|
|
156
|
+
var ref1;
|
|
157
|
+
results.push({
|
|
158
|
+
name: (ref1 = (ref = spec.display) === null || ref === void 0 ? void 0 : ref.name) !== null && ref1 !== void 0 ? ref1 : selectorName,
|
|
159
|
+
selector: {
|
|
160
|
+
kind: spec.plugin.kind,
|
|
161
|
+
name: selectorName
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
usedNames.add(selectorName);
|
|
165
|
+
};
|
|
166
|
+
return {
|
|
167
|
+
results,
|
|
168
|
+
addResult
|
|
169
|
+
};
|
|
170
|
+
}
|
|
@@ -77,7 +77,8 @@ function useTemplateVariableActions() {
|
|
|
77
77
|
return {
|
|
78
78
|
setVariableValue: s.setVariableValue,
|
|
79
79
|
setVariableLoading: s.setVariableLoading,
|
|
80
|
-
setVariableOptions: s.setVariableOptions
|
|
80
|
+
setVariableOptions: s.setVariableOptions,
|
|
81
|
+
setVariableDefinitions: s.setVariableDefinitions
|
|
81
82
|
};
|
|
82
83
|
});
|
|
83
84
|
}
|
|
@@ -122,6 +123,12 @@ function createTemplateVariableSrvStore({ initialVariableDefinitions =[] }) {
|
|
|
122
123
|
const store = (0, _zustand.createStore)()((0, _middleware.devtools)((0, _immer.immer)((set)=>({
|
|
123
124
|
variableState: hydrateTemplateVariableStates(initialVariableDefinitions),
|
|
124
125
|
variableDefinitions: initialVariableDefinitions,
|
|
126
|
+
setVariableDefinitions (definitions) {
|
|
127
|
+
set((state)=>{
|
|
128
|
+
state.variableDefinitions = definitions;
|
|
129
|
+
state.variableState = hydrateTemplateVariableStates(definitions);
|
|
130
|
+
});
|
|
131
|
+
},
|
|
125
132
|
setVariableOptions (name, options) {
|
|
126
133
|
set((state)=>{
|
|
127
134
|
const varState = state.variableState[name];
|
|
@@ -14,10 +14,8 @@
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", {
|
|
15
15
|
value: true
|
|
16
16
|
});
|
|
17
|
-
_exportStar(require("./DashboardAppSlice"), exports);
|
|
18
17
|
_exportStar(require("./DashboardProvider"), exports);
|
|
19
18
|
_exportStar(require("./DatasourceStoreProvider"), exports);
|
|
20
|
-
_exportStar(require("./LayoutsSlice"), exports);
|
|
21
19
|
_exportStar(require("./QueryStringProvider"), exports);
|
|
22
20
|
_exportStar(require("./TemplateVariableProvider"), exports);
|
|
23
21
|
_exportStar(require("./TimeRangeProvider"), exports);
|
|
@@ -209,7 +209,10 @@ const testDashboard = {
|
|
|
209
209
|
kind: 'Grid',
|
|
210
210
|
spec: {
|
|
211
211
|
display: {
|
|
212
|
-
title: 'CPU Stats'
|
|
212
|
+
title: 'CPU Stats',
|
|
213
|
+
collapse: {
|
|
214
|
+
open: true
|
|
215
|
+
}
|
|
213
216
|
},
|
|
214
217
|
items: [
|
|
215
218
|
// First Row
|
|
@@ -221,6 +224,15 @@ const testDashboard = {
|
|
|
221
224
|
content: {
|
|
222
225
|
$ref: '#/spec/panels/cpu'
|
|
223
226
|
}
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
x: 0,
|
|
230
|
+
y: 5,
|
|
231
|
+
width: 6,
|
|
232
|
+
height: 2,
|
|
233
|
+
content: {
|
|
234
|
+
$ref: '#/spec/panels/diskIO'
|
|
235
|
+
}
|
|
224
236
|
}
|
|
225
237
|
]
|
|
226
238
|
}
|
|
@@ -24,7 +24,8 @@ const _components = require("@perses-dev/components");
|
|
|
24
24
|
const _components1 = require("../../components");
|
|
25
25
|
const _panelGroupDialog = /*#__PURE__*/ _interopRequireDefault(require("../../components/PanelGroupDialog/PanelGroupDialog"));
|
|
26
26
|
const _dashboardToolbar = require("../../components/DashboardToolbar");
|
|
27
|
-
const
|
|
27
|
+
const _deletePanelGroupDialog = /*#__PURE__*/ _interopRequireDefault(require("../../components/PanelGroupDialog/DeletePanelGroupDialog"));
|
|
28
|
+
const _deletePanelDialog = /*#__PURE__*/ _interopRequireDefault(require("../../components/Panel/DeletePanelDialog"));
|
|
28
29
|
function _interopRequireDefault(obj) {
|
|
29
30
|
return obj && obj.__esModule ? obj : {
|
|
30
31
|
default: obj
|
|
@@ -32,8 +33,6 @@ function _interopRequireDefault(obj) {
|
|
|
32
33
|
}
|
|
33
34
|
const DashboardApp = (props)=>{
|
|
34
35
|
const { dashboardResource } = props;
|
|
35
|
-
const { dashboard } = (0, _context.useDashboard)();
|
|
36
|
-
const { panelGroupDialog } = (0, _context.useDashboardApp)();
|
|
37
36
|
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
38
37
|
sx: {
|
|
39
38
|
padding: (theme)=>theme.spacing(1, 0),
|
|
@@ -54,12 +53,12 @@ const DashboardApp = (props)=>{
|
|
|
54
53
|
children: [
|
|
55
54
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components.ErrorBoundary, {
|
|
56
55
|
FallbackComponent: _components.ErrorAlert,
|
|
57
|
-
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.Dashboard, {
|
|
58
|
-
spec: dashboard
|
|
59
|
-
})
|
|
56
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.Dashboard, {})
|
|
60
57
|
}),
|
|
61
58
|
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_components1.PanelDrawer, {}),
|
|
62
|
-
|
|
59
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelGroupDialog.default, {}),
|
|
60
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_deletePanelGroupDialog.default, {}),
|
|
61
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_deletePanelDialog.default, {})
|
|
63
62
|
]
|
|
64
63
|
})
|
|
65
64
|
]
|
|
@@ -0,0 +1,165 @@
|
|
|
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
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
18
|
+
const _react = require("@testing-library/react");
|
|
19
|
+
const _userEvent = /*#__PURE__*/ _interopRequireDefault(require("@testing-library/user-event"));
|
|
20
|
+
const _context = require("../../../context");
|
|
21
|
+
const _test = require("../../../test");
|
|
22
|
+
const _testDashboard = /*#__PURE__*/ _interopRequireDefault(require("../../../test/testDashboard"));
|
|
23
|
+
const _dashboardApp = require("../DashboardApp");
|
|
24
|
+
function _interopRequireDefault(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
describe('Panel Groups', ()=>{
|
|
30
|
+
const renderDashboard = ()=>{
|
|
31
|
+
const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
|
|
32
|
+
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.QueryStringProvider, {
|
|
33
|
+
queryString: new URLSearchParams('https://localhost:3000/'),
|
|
34
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.TimeRangeProvider, {
|
|
35
|
+
initialTimeRange: {
|
|
36
|
+
pastDuration: '30m'
|
|
37
|
+
},
|
|
38
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_context.TemplateVariableProvider, {
|
|
39
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_context.DashboardProvider, {
|
|
40
|
+
initialState: {
|
|
41
|
+
dashboardSpec: (0, _test.getTestDashboard)().spec,
|
|
42
|
+
isEditMode: true
|
|
43
|
+
},
|
|
44
|
+
children: [
|
|
45
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardProviderSpy, {}),
|
|
46
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_dashboardApp.DashboardApp, {
|
|
47
|
+
dashboardResource: (0, _test.getTestDashboard)()
|
|
48
|
+
})
|
|
49
|
+
]
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
}));
|
|
54
|
+
const { value: storeApi } = store;
|
|
55
|
+
if (storeApi === undefined) {
|
|
56
|
+
throw new Error('Expected dashboard store to be set after initial render');
|
|
57
|
+
}
|
|
58
|
+
return storeApi;
|
|
59
|
+
};
|
|
60
|
+
beforeEach(()=>{
|
|
61
|
+
const mockIntersectionObserver = jest.fn();
|
|
62
|
+
mockIntersectionObserver.mockReturnValue({
|
|
63
|
+
observe: ()=>null,
|
|
64
|
+
unobserve: ()=>null,
|
|
65
|
+
disconnect: ()=>null
|
|
66
|
+
});
|
|
67
|
+
window.IntersectionObserver = mockIntersectionObserver;
|
|
68
|
+
});
|
|
69
|
+
it('should delete panel', ()=>{
|
|
70
|
+
var ref;
|
|
71
|
+
const storeApi = renderDashboard();
|
|
72
|
+
const panel = _react.screen.getByText('CPU');
|
|
73
|
+
_userEvent.default.hover(panel);
|
|
74
|
+
const deletePanelButton = _react.screen.getByLabelText('delete panel');
|
|
75
|
+
_userEvent.default.click(deletePanelButton);
|
|
76
|
+
_react.screen.getByText('Delete Panel');
|
|
77
|
+
const deleteButton = _react.screen.getByText('Delete');
|
|
78
|
+
_userEvent.default.click(deleteButton);
|
|
79
|
+
const layouts = storeApi.getState().layouts;
|
|
80
|
+
const deletedPanel = _testDashboard.default.spec.panels['cpu'];
|
|
81
|
+
expect((ref = layouts[0]) === null || ref === void 0 ? void 0 : ref.items).toEqual(expect.not.objectContaining(deletedPanel));
|
|
82
|
+
const panels = storeApi.getState().panels;
|
|
83
|
+
// should remove cpu from state.panels since it's not used anymore
|
|
84
|
+
expect(panels).toEqual(expect.not.objectContaining({
|
|
85
|
+
cpu: _testDashboard.default.spec.panels['cpu']
|
|
86
|
+
}));
|
|
87
|
+
});
|
|
88
|
+
it('should only delete panel from panel group if panel is referenced more than once', ()=>{
|
|
89
|
+
var ref;
|
|
90
|
+
const storeApi = renderDashboard();
|
|
91
|
+
const panel = _react.screen.getByText('Disk I/O Utilization');
|
|
92
|
+
_userEvent.default.hover(panel);
|
|
93
|
+
const deletePanelButton = _react.screen.getByLabelText('delete panel');
|
|
94
|
+
_userEvent.default.click(deletePanelButton);
|
|
95
|
+
_react.screen.getByText('Delete Panel');
|
|
96
|
+
const deleteButton = _react.screen.getByText('Delete');
|
|
97
|
+
_userEvent.default.click(deleteButton);
|
|
98
|
+
const layouts = storeApi.getState().layouts;
|
|
99
|
+
const deletedPanel = _testDashboard.default.spec.panels['diskIO'];
|
|
100
|
+
expect((ref = layouts[0]) === null || ref === void 0 ? void 0 : ref.items).toEqual(expect.not.objectContaining(deletedPanel));
|
|
101
|
+
const panels = storeApi.getState().panels;
|
|
102
|
+
// should NOT remove diskIO from state.panels since it's used in another panel group
|
|
103
|
+
expect(panels).toEqual(expect.objectContaining({
|
|
104
|
+
diskIO: _testDashboard.default.spec.panels['diskIO']
|
|
105
|
+
}));
|
|
106
|
+
});
|
|
107
|
+
it('should swap panels', ()=>{
|
|
108
|
+
var ref, ref1, ref2;
|
|
109
|
+
const storeApi = renderDashboard();
|
|
110
|
+
// should move panel down
|
|
111
|
+
const group1 = _react.screen.getByText('CPU Stats');
|
|
112
|
+
_userEvent.default.hover(group1);
|
|
113
|
+
const moveGroupDownBtn = _react.screen.getByLabelText('move group down');
|
|
114
|
+
_userEvent.default.click(moveGroupDownBtn);
|
|
115
|
+
_userEvent.default.unhover(moveGroupDownBtn);
|
|
116
|
+
// should move panel up
|
|
117
|
+
const group2 = _react.screen.getByText('Disk Stats');
|
|
118
|
+
_userEvent.default.hover(group2);
|
|
119
|
+
const moveGroupUpBtn = _react.screen.getByLabelText('move group up');
|
|
120
|
+
_userEvent.default.click(moveGroupUpBtn);
|
|
121
|
+
const layouts = storeApi.getState().layouts;
|
|
122
|
+
expect((ref = layouts[0]) === null || ref === void 0 ? void 0 : ref.title).toBe(undefined);
|
|
123
|
+
expect((ref1 = layouts[1]) === null || ref1 === void 0 ? void 0 : ref1.title).toBe('Disk Stats');
|
|
124
|
+
expect((ref2 = layouts[2]) === null || ref2 === void 0 ? void 0 : ref2.title).toBe('CPU Stats');
|
|
125
|
+
});
|
|
126
|
+
it('should delete a panel group', ()=>{
|
|
127
|
+
const storeApi = renderDashboard();
|
|
128
|
+
const group = _react.screen.getByText('CPU Stats');
|
|
129
|
+
_userEvent.default.hover(group);
|
|
130
|
+
const deleteGroupIcon = _react.screen.getByLabelText('delete group');
|
|
131
|
+
_userEvent.default.click(deleteGroupIcon);
|
|
132
|
+
_react.screen.getByText('Delete Panel Group');
|
|
133
|
+
const deleteButton = _react.screen.getByText('Delete');
|
|
134
|
+
_userEvent.default.click(deleteButton);
|
|
135
|
+
// should remove group from state.layouts
|
|
136
|
+
const layouts = storeApi.getState().layouts;
|
|
137
|
+
expect(layouts).toHaveLength(2);
|
|
138
|
+
const deletedLayout = {
|
|
139
|
+
id: 0,
|
|
140
|
+
title: 'CPU Stats',
|
|
141
|
+
isCollapsed: false,
|
|
142
|
+
items: [
|
|
143
|
+
{
|
|
144
|
+
x: 0,
|
|
145
|
+
y: 0,
|
|
146
|
+
width: 12,
|
|
147
|
+
height: 4,
|
|
148
|
+
content: {
|
|
149
|
+
$ref: '#/spec/panels/cpu'
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
};
|
|
154
|
+
expect(layouts).toEqual(expect.not.objectContaining(deletedLayout));
|
|
155
|
+
const panels = storeApi.getState().panels;
|
|
156
|
+
// should remove cpu from state.panels since it's not used anymore
|
|
157
|
+
expect(panels).toEqual(expect.not.objectContaining({
|
|
158
|
+
cpu: _testDashboard.default.spec.panels['cpu']
|
|
159
|
+
}));
|
|
160
|
+
// should not remove diskIO from state.panels since it's still used in another group
|
|
161
|
+
expect(panels).toEqual(expect.objectContaining({
|
|
162
|
+
diskIO: _testDashboard.default.spec.panels['diskIO']
|
|
163
|
+
}));
|
|
164
|
+
});
|
|
165
|
+
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { BoxProps } from '@mui/material';
|
|
3
|
-
|
|
4
|
-
export interface DashboardProps extends BoxProps {
|
|
5
|
-
spec: DashboardSpec;
|
|
6
|
-
}
|
|
3
|
+
export declare type DashboardProps = BoxProps;
|
|
7
4
|
/**
|
|
8
5
|
* Renders a Dashboard for the provided Dashboard spec.
|
|
9
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Dashboard.d.ts","sourceRoot":"","sources":["../../src/components/Dashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"Dashboard.d.ts","sourceRoot":"","sources":["../../src/components/Dashboard.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAO,QAAQ,EAAE,MAAM,eAAe,CAAC;AAK9C,oBAAY,cAAc,GAAG,QAAQ,CAAC;AAEtC;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,eAW9C"}
|