@perses-dev/dashboards 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Dashboard.js +29 -14
- package/dist/cjs/components/DashboardToolbar.js +148 -20
- package/dist/cjs/components/GridLayout/GridItemContent.js +24 -18
- package/dist/cjs/components/GridLayout/GridLayout.js +88 -26
- package/dist/cjs/components/GridLayout/GridTitle.js +69 -31
- package/dist/cjs/components/GridLayout/index.js +18 -19
- package/dist/cjs/components/Panel/Panel.js +145 -55
- package/dist/cjs/components/Panel/Panel.test.js +50 -41
- package/dist/cjs/components/Panel/PanelContent.js +40 -12
- package/dist/cjs/components/Panel/index.js +16 -17
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +82 -107
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +91 -92
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +152 -0
- package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +40 -0
- package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +38 -0
- package/dist/cjs/components/PanelDrawer/index.js +28 -0
- package/dist/cjs/components/PanelDrawer/panel-editor-model.js +140 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +120 -31
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +90 -83
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +120 -38
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +42 -27
- package/dist/cjs/components/TimeRangeControls/index.js +16 -17
- package/dist/cjs/components/Variables/Variable.js +186 -35
- package/dist/cjs/components/Variables/VariableList.js +100 -13
- package/dist/cjs/components/Variables/index.js +17 -18
- package/dist/cjs/components/index.js +21 -21
- package/dist/cjs/context/DashboardAppSlice.js +43 -31
- package/dist/cjs/context/DashboardProvider.js +88 -58
- package/dist/cjs/context/DatasourceStoreProvider.js +68 -0
- package/dist/cjs/context/LayoutsSlice.js +40 -27
- package/dist/cjs/context/QueryStringProvider.js +69 -15
- package/dist/cjs/context/TemplateVariableProvider.js +128 -136
- package/dist/cjs/context/TimeRangeProvider.js +79 -30
- package/dist/cjs/context/index.js +22 -22
- package/dist/cjs/css/styles.js +43 -39
- package/dist/cjs/index.js +19 -20
- package/dist/cjs/test/dashboard-provider.js +51 -0
- package/dist/cjs/test/index.js +18 -18
- package/dist/cjs/test/plugin-registry.js +52 -25
- package/dist/cjs/test/render.js +25 -22
- package/dist/cjs/test/setup-tests.js +4 -2
- package/dist/cjs/test/testDashboard.js +193 -109
- package/dist/cjs/utils/functions.js +9 -5
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +67 -0
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +83 -0
- package/dist/cjs/views/ViewDashboard/index.js +28 -0
- package/dist/cjs/views/index.js +16 -17
- package/dist/components/Dashboard.js +38 -1
- package/dist/components/Dashboard.js.map +1 -0
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +154 -1
- package/dist/components/DashboardToolbar.js.map +1 -0
- package/dist/components/GridLayout/GridItemContent.js +35 -1
- package/dist/components/GridLayout/GridItemContent.js.map +1 -0
- package/dist/components/GridLayout/GridLayout.js +99 -1
- package/dist/components/GridLayout/GridLayout.js.map +1 -0
- package/dist/components/GridLayout/GridTitle.js +77 -1
- package/dist/components/GridLayout/GridTitle.js.map +1 -0
- package/dist/components/GridLayout/index.js +16 -1
- package/dist/components/GridLayout/index.js.map +1 -0
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +170 -1
- package/dist/components/Panel/Panel.js.map +1 -0
- package/dist/components/Panel/Panel.test.js +71 -1
- package/dist/components/Panel/Panel.test.js.map +1 -0
- package/dist/components/Panel/PanelContent.d.ts +2 -4
- package/dist/components/Panel/PanelContent.d.ts.map +1 -1
- package/dist/components/Panel/PanelContent.js +40 -1
- package/dist/components/Panel/PanelContent.js.map +1 -0
- package/dist/components/Panel/index.js +15 -1
- package/dist/components/Panel/index.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +95 -1
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.js +103 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelEditorForm.js +142 -0
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +7 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.js +34 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.js.map +1 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +8 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.js +34 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.js.map +1 -0
- package/dist/components/PanelDrawer/index.d.ts +2 -0
- package/dist/components/PanelDrawer/index.d.ts.map +1 -0
- package/dist/components/PanelDrawer/index.js +15 -0
- package/dist/components/PanelDrawer/index.js.map +1 -0
- package/dist/components/PanelDrawer/panel-editor-model.d.ts +27 -0
- package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +1 -0
- package/dist/components/PanelDrawer/panel-editor-model.js +133 -0
- package/dist/components/PanelDrawer/panel-editor-model.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +138 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
- package/dist/components/TimeRangeControls/index.js +15 -1
- package/dist/components/TimeRangeControls/index.js.map +1 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -1
- package/dist/components/Variables/Variable.js +202 -1
- package/dist/components/Variables/Variable.js.map +1 -0
- package/dist/components/Variables/VariableList.js +108 -1
- package/dist/components/Variables/VariableList.js.map +1 -0
- package/dist/components/Variables/index.js +16 -1
- package/dist/components/Variables/index.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +20 -1
- package/dist/components/index.js.map +1 -0
- package/dist/context/DashboardAppSlice.js +45 -1
- package/dist/context/DashboardAppSlice.js.map +1 -0
- package/dist/context/DashboardProvider.d.ts +4 -2
- package/dist/context/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider.js +107 -1
- package/dist/context/DashboardProvider.js.map +1 -0
- package/dist/context/DatasourceStoreProvider.d.ts +16 -0
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
- package/dist/context/DatasourceStoreProvider.js +64 -0
- package/dist/context/DatasourceStoreProvider.js.map +1 -0
- package/dist/context/LayoutsSlice.js +43 -1
- package/dist/context/LayoutsSlice.js.map +1 -0
- package/dist/context/QueryStringProvider.js +40 -1
- package/dist/context/QueryStringProvider.js.map +1 -0
- package/dist/context/TemplateVariableProvider.d.ts +6 -3
- package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider.js +192 -1
- package/dist/context/TemplateVariableProvider.js.map +1 -0
- package/dist/context/TimeRangeProvider.js +72 -1
- package/dist/context/TimeRangeProvider.js.map +1 -0
- package/dist/context/index.d.ts +3 -2
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +21 -1
- package/dist/context/index.js.map +1 -0
- package/dist/css/styles.js +186 -1
- package/dist/css/styles.js.map +1 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -0
- package/dist/test/dashboard-provider.d.ts +19 -0
- package/dist/test/dashboard-provider.d.ts.map +1 -0
- package/dist/test/dashboard-provider.js +40 -0
- package/dist/test/dashboard-provider.js.map +1 -0
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +17 -1
- package/dist/test/index.js.map +1 -0
- package/dist/test/plugin-registry.d.ts +2 -3
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +74 -1
- package/dist/test/plugin-registry.js.map +1 -0
- package/dist/test/render.d.ts +1 -2
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +34 -1
- package/dist/test/render.js.map +1 -0
- package/dist/test/setup-tests.js +18 -1
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +274 -1
- package/dist/test/testDashboard.js.map +1 -0
- package/dist/utils/functions.js +17 -1
- package/dist/utils/functions.js.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.js +56 -0
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
- package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +3 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
- package/dist/views/ViewDashboard/ViewDashboard.js +79 -0
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
- package/dist/views/ViewDashboard/index.d.ts +2 -0
- package/dist/views/ViewDashboard/index.d.ts.map +1 -0
- package/dist/views/ViewDashboard/index.js +15 -0
- package/dist/views/ViewDashboard/index.js.map +1 -0
- package/dist/views/index.js +15 -1
- package/dist/views/index.js.map +1 -0
- package/package.json +13 -7
- package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
- package/dist/cjs/views/DashboardApp.js +0 -46
- package/dist/cjs/views/ViewDashboard.js +0 -43
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
- package/dist/views/DashboardApp.d.ts +0 -4
- package/dist/views/DashboardApp.d.ts.map +0 -1
- package/dist/views/DashboardApp.js +0 -1
- package/dist/views/ViewDashboard.d.ts.map +0 -1
- package/dist/views/ViewDashboard.js +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
_exportStar(require("./PanelDrawer"), exports);
|
|
18
|
+
function _exportStar(from, to) {
|
|
19
|
+
Object.keys(from).forEach(function(k) {
|
|
20
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function() {
|
|
23
|
+
return from[k];
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
return from;
|
|
28
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
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,9 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
1
|
// Copyright 2022 The Perses Authors
|
|
8
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
9
3
|
// you may not use this file except in compliance with the License.
|
|
@@ -16,45 +10,140 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
16
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
17
11
|
// See the License for the specific language governing permissions and
|
|
18
12
|
// limitations under the License.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 _react = require("react");
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _close = /*#__PURE__*/ _interopRequireDefault(require("mdi-material-ui/Close"));
|
|
25
|
+
const _context = require("../../context");
|
|
26
|
+
function _interopRequireDefault(obj) {
|
|
27
|
+
return obj && obj.__esModule ? obj : {
|
|
28
|
+
default: obj
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const PanelGroupDialog = ()=>{
|
|
32
|
+
var ref, ref1, ref2, ref3, ref4;
|
|
33
|
+
const { layouts , updateLayout } = (0, _context.useLayouts)();
|
|
34
|
+
const { panelGroupDialog , closePanelGroupDialog } = (0, _context.useDashboardApp)();
|
|
35
|
+
const groupIndex = panelGroupDialog === null || panelGroupDialog === void 0 ? void 0 : panelGroupDialog.groupIndex;
|
|
29
36
|
const isEditingPanelGroup = groupIndex !== undefined;
|
|
30
|
-
const [isCollapsed, setIsCollapsed] = (0,
|
|
31
|
-
const [name, setName] = (0,
|
|
32
|
-
const handleSubmit = (e)
|
|
33
|
-
var
|
|
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 : '');
|
|
39
|
+
const handleSubmit = (e)=>{
|
|
40
|
+
var ref;
|
|
34
41
|
e.preventDefault();
|
|
42
|
+
var _items;
|
|
35
43
|
const newLayout = {
|
|
36
44
|
kind: 'Grid',
|
|
37
45
|
spec: {
|
|
38
46
|
display: {
|
|
39
47
|
title: name !== null && name !== void 0 ? name : '',
|
|
40
48
|
collapse: {
|
|
41
|
-
open: !isCollapsed
|
|
42
|
-
}
|
|
49
|
+
open: !isCollapsed
|
|
50
|
+
}
|
|
43
51
|
},
|
|
44
|
-
items: groupIndex === undefined ? [] : (
|
|
45
|
-
}
|
|
52
|
+
items: groupIndex === undefined ? [] : (_items = (ref = layouts[groupIndex]) === null || ref === void 0 ? void 0 : ref.spec.items) !== null && _items !== void 0 ? _items : []
|
|
53
|
+
}
|
|
46
54
|
};
|
|
47
55
|
updateLayout(newLayout, groupIndex);
|
|
48
56
|
closePanelGroupDialog();
|
|
49
57
|
};
|
|
50
|
-
const handleSelectCollapsedStateChange = (e)
|
|
58
|
+
const handleSelectCollapsedStateChange = (e)=>{
|
|
51
59
|
const isCollapsed = e.target.value === 'Close';
|
|
52
60
|
setIsCollapsed(isCollapsed);
|
|
53
61
|
};
|
|
54
|
-
return (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
62
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Dialog, {
|
|
63
|
+
open: true,
|
|
64
|
+
children: [
|
|
65
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogTitle, {
|
|
66
|
+
children: "Panel Group"
|
|
67
|
+
}),
|
|
68
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.IconButton, {
|
|
69
|
+
"aria-label": "Close",
|
|
70
|
+
onClick: ()=>closePanelGroupDialog(),
|
|
71
|
+
sx: (theme)=>({
|
|
72
|
+
position: 'absolute',
|
|
73
|
+
top: theme.spacing(0.5),
|
|
74
|
+
right: theme.spacing(0.5)
|
|
75
|
+
}),
|
|
76
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_close.default, {})
|
|
77
|
+
}),
|
|
78
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsxs)("form", {
|
|
79
|
+
onSubmit: handleSubmit,
|
|
80
|
+
children: [
|
|
81
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.DialogContent, {
|
|
82
|
+
sx: {
|
|
83
|
+
width: '500px'
|
|
84
|
+
},
|
|
85
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Stack, {
|
|
86
|
+
spacing: 2,
|
|
87
|
+
children: [
|
|
88
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.FormControl, {
|
|
89
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TextField, {
|
|
90
|
+
required: true,
|
|
91
|
+
label: "Name",
|
|
92
|
+
variant: "outlined",
|
|
93
|
+
value: name,
|
|
94
|
+
onChange: (e)=>setName(e.target.value)
|
|
95
|
+
})
|
|
96
|
+
}),
|
|
97
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
|
|
98
|
+
sx: {
|
|
99
|
+
display: 'flex',
|
|
100
|
+
alignItems: 'center',
|
|
101
|
+
width: '100%',
|
|
102
|
+
justifyContent: 'space-between'
|
|
103
|
+
},
|
|
104
|
+
children: [
|
|
105
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.InputLabel, {
|
|
106
|
+
children: "Collapse State"
|
|
107
|
+
}),
|
|
108
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Select, {
|
|
109
|
+
required: true,
|
|
110
|
+
displayEmpty: true,
|
|
111
|
+
labelId: "select-collapse-state",
|
|
112
|
+
size: "small",
|
|
113
|
+
value: isCollapsed ? 'Close' : 'Open',
|
|
114
|
+
onChange: handleSelectCollapsedStateChange,
|
|
115
|
+
children: [
|
|
116
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
|
|
117
|
+
value: 'Open',
|
|
118
|
+
children: "Open"
|
|
119
|
+
}, 'open'),
|
|
120
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.MenuItem, {
|
|
121
|
+
value: 'Close',
|
|
122
|
+
children: "Close"
|
|
123
|
+
}, 'close')
|
|
124
|
+
]
|
|
125
|
+
})
|
|
126
|
+
]
|
|
127
|
+
})
|
|
128
|
+
]
|
|
129
|
+
})
|
|
130
|
+
}),
|
|
131
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.DialogActions, {
|
|
132
|
+
children: [
|
|
133
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
|
|
134
|
+
variant: "contained",
|
|
135
|
+
type: "submit",
|
|
136
|
+
children: isEditingPanelGroup ? 'Apply' : 'Add'
|
|
137
|
+
}),
|
|
138
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Button, {
|
|
139
|
+
onClick: ()=>closePanelGroupDialog(),
|
|
140
|
+
children: "Cancel"
|
|
141
|
+
})
|
|
142
|
+
]
|
|
143
|
+
})
|
|
144
|
+
]
|
|
145
|
+
})
|
|
146
|
+
]
|
|
147
|
+
});
|
|
59
148
|
};
|
|
60
|
-
|
|
149
|
+
const _default = PanelGroupDialog;
|
|
@@ -1,95 +1,102 @@
|
|
|
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.
|
|
1
13
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
17
16
|
});
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
jest.spyOn(dashboardAppSlice, 'useDashboardApp').mockReturnValue(dashboardApp);
|
|
60
|
-
(0, test_1.renderWithContext)((0, jsx_runtime_1.jsx)(PanelGroupDialog_1.default, {}));
|
|
61
|
-
const nameInput = react_1.screen.getByLabelText(/Name/);
|
|
62
|
-
user_event_1.default.type(nameInput, 'New Panel Group');
|
|
63
|
-
user_event_1.default.click(react_1.screen.getByText('Add'));
|
|
64
|
-
expect(updateLayout).toHaveBeenCalledWith({
|
|
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 _testUtils = require("react-dom/test-utils");
|
|
21
|
+
const _context = require("../../context");
|
|
22
|
+
const _test = require("../../test");
|
|
23
|
+
const _panelGroupDialog = /*#__PURE__*/ _interopRequireDefault(require("./PanelGroupDialog"));
|
|
24
|
+
function _interopRequireDefault(obj) {
|
|
25
|
+
return obj && obj.__esModule ? obj : {
|
|
26
|
+
default: obj
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
describe('Add Panel Group', ()=>{
|
|
30
|
+
const renderDialog = ()=>{
|
|
31
|
+
const { store , DashboardProviderSpy } = (0, _test.createDashboardProviderSpy)();
|
|
32
|
+
(0, _test.renderWithContext)(/*#__PURE__*/ (0, _jsxRuntime.jsxs)(_context.DashboardProvider, {
|
|
33
|
+
initialState: {
|
|
34
|
+
dashboardSpec: (0, _test.getTestDashboard)().spec,
|
|
35
|
+
isEditMode: true
|
|
36
|
+
},
|
|
37
|
+
children: [
|
|
38
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(DashboardProviderSpy, {}),
|
|
39
|
+
/*#__PURE__*/ (0, _jsxRuntime.jsx)(_panelGroupDialog.default, {})
|
|
40
|
+
]
|
|
41
|
+
}));
|
|
42
|
+
const { value: storeApi } = store;
|
|
43
|
+
if (storeApi === undefined) {
|
|
44
|
+
throw new Error('Expected dashboard store to be set after initial render');
|
|
45
|
+
}
|
|
46
|
+
return storeApi;
|
|
47
|
+
};
|
|
48
|
+
it('should add new panel group', async ()=>{
|
|
49
|
+
// jest.spyOn(dashboardAppSlice, 'useDashboardApp').mockReturnValue(dashboardApp);
|
|
50
|
+
const storeApi = renderDialog();
|
|
51
|
+
// Open the dialog for a new panel group
|
|
52
|
+
(0, _testUtils.act)(()=>storeApi.getState().openPanelGroupDialog());
|
|
53
|
+
const nameInput = await _react.screen.findByLabelText(/Name/);
|
|
54
|
+
_userEvent.default.type(nameInput, 'New Panel Group');
|
|
55
|
+
_userEvent.default.click(_react.screen.getByText('Add'));
|
|
56
|
+
const layouts = storeApi.getState().layouts;
|
|
57
|
+
expect(layouts).toContainEqual({
|
|
65
58
|
kind: 'Grid',
|
|
66
59
|
spec: {
|
|
67
60
|
display: {
|
|
68
61
|
title: 'New Panel Group',
|
|
69
62
|
collapse: {
|
|
70
|
-
open: true
|
|
71
|
-
}
|
|
63
|
+
open: true
|
|
64
|
+
}
|
|
72
65
|
},
|
|
73
|
-
items: []
|
|
74
|
-
}
|
|
75
|
-
}
|
|
66
|
+
items: []
|
|
67
|
+
}
|
|
68
|
+
});
|
|
76
69
|
});
|
|
77
|
-
it('should edit existing panel group', ()
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
70
|
+
it('should edit existing panel group', async ()=>{
|
|
71
|
+
const storeApi = renderDialog();
|
|
72
|
+
// Open the dialog for an existing panel group
|
|
73
|
+
(0, _testUtils.act)(()=>storeApi.getState().openPanelGroupDialog(0));
|
|
74
|
+
const nameInput = await _react.screen.findByLabelText(/Name/);
|
|
75
|
+
_userEvent.default.clear(nameInput);
|
|
76
|
+
_userEvent.default.type(nameInput, 'New Name');
|
|
77
|
+
_userEvent.default.click(_react.screen.getByText('Apply'));
|
|
78
|
+
const layouts = storeApi.getState().layouts;
|
|
79
|
+
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
|
+
}
|
|
83
100
|
});
|
|
84
|
-
(0, test_1.renderWithContext)((0, jsx_runtime_1.jsx)(PanelGroupDialog_1.default, {}));
|
|
85
|
-
const nameInput = react_1.screen.getByLabelText(/Name/);
|
|
86
|
-
user_event_1.default.type(nameInput, 'New Name');
|
|
87
|
-
user_event_1.default.click(react_1.screen.getByText('Apply'));
|
|
88
|
-
expect(updateLayout).toHaveBeenCalledWith((0, immer_1.default)(testDashboard_1.default.spec.layouts[0], (draftState) => {
|
|
89
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
90
|
-
draftState.spec.display.title += 'New Name';
|
|
91
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
92
|
-
draftState.spec.display.collapse = { open: false };
|
|
93
|
-
}), 0);
|
|
94
101
|
});
|
|
95
102
|
});
|