@perses-dev/dashboards 0.5.2 → 0.7.1
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/AddPanel/AddPanel.js +75 -0
- package/dist/cjs/components/DashboardToolbar.js +52 -0
- package/dist/cjs/components/GridLayout/GridLayout.js +13 -28
- package/dist/cjs/components/Panel/Panel.js +15 -1
- package/dist/cjs/components/Panel/Panel.test.js +20 -3
- package/dist/cjs/components/TimeRangeControls.js +77 -0
- package/dist/cjs/components/VariableAutocomplete.js +3 -3
- package/dist/cjs/components/{VariableOptionsDrawer/VariableOptionsDrawer.js → VariableList/VariableList.js} +10 -14
- package/dist/cjs/components/{VariableOptionsDrawer/VariableOptionsDrawer.test.js → VariableList/VariableList.test.js} +13 -8
- package/dist/cjs/components/VariableList/index.js +29 -0
- package/dist/cjs/components/index.js +3 -2
- package/dist/cjs/context/DashboardProvider.js +80 -0
- package/dist/cjs/context/TimeRangeStateProvider.js +23 -9
- package/dist/cjs/context/index.js +1 -0
- package/dist/cjs/css/styles.js +184 -0
- package/dist/cjs/test/testDashboard.js +219 -0
- package/dist/cjs/utils/functions.js +19 -0
- package/dist/cjs/views/DashboardApp.js +46 -0
- package/dist/cjs/views/ViewDashboard.js +4 -28
- package/dist/components/AddPanel/AddPanel.d.ts +8 -0
- package/dist/components/AddPanel/AddPanel.d.ts.map +1 -0
- package/dist/components/AddPanel/AddPanel.js +1 -0
- package/dist/components/DashboardToolbar.d.ts +7 -0
- package/dist/components/DashboardToolbar.d.ts.map +1 -0
- package/dist/components/DashboardToolbar.js +1 -0
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +1 -1
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +1 -1
- package/dist/components/Panel/Panel.test.js +1 -1
- package/dist/components/TimeRangeControls.d.ts +5 -0
- package/dist/components/TimeRangeControls.d.ts.map +1 -0
- package/dist/components/TimeRangeControls.js +1 -0
- package/dist/components/VariableAutocomplete.d.ts +5 -1
- package/dist/components/VariableAutocomplete.d.ts.map +1 -1
- package/dist/components/VariableAutocomplete.js +1 -1
- package/dist/components/VariableList/VariableList.d.ts +11 -0
- package/dist/components/VariableList/VariableList.d.ts.map +1 -0
- package/dist/components/VariableList/VariableList.js +1 -0
- package/dist/components/VariableList/VariableList.test.d.ts +2 -0
- package/dist/components/VariableList/VariableList.test.d.ts.map +1 -0
- package/dist/components/VariableList/VariableList.test.js +1 -0
- package/dist/components/VariableList/index.d.ts +2 -0
- package/dist/components/VariableList/index.d.ts.map +1 -0
- package/dist/components/VariableList/index.js +1 -0
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -1
- package/dist/context/DashboardProvider.d.ts +45 -0
- package/dist/context/DashboardProvider.d.ts.map +1 -0
- package/dist/context/DashboardProvider.js +1 -0
- package/dist/context/TimeRangeStateProvider.d.ts +13 -2
- package/dist/context/TimeRangeStateProvider.d.ts.map +1 -1
- package/dist/context/TimeRangeStateProvider.js +1 -1
- package/dist/context/index.d.ts +1 -0
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +1 -1
- package/dist/css/styles.d.ts +172 -0
- package/dist/css/styles.d.ts.map +1 -0
- package/dist/css/styles.js +1 -0
- package/dist/test/testDashboard.d.ts +4 -0
- package/dist/test/testDashboard.d.ts.map +1 -0
- package/dist/test/testDashboard.js +1 -0
- package/dist/utils/functions.d.ts +2 -0
- package/dist/utils/functions.d.ts.map +1 -0
- package/dist/utils/functions.js +1 -0
- package/dist/views/DashboardApp.d.ts +4 -0
- package/dist/views/DashboardApp.d.ts.map +1 -0
- package/dist/views/DashboardApp.js +1 -0
- package/dist/views/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard.js +1 -1
- package/package.json +13 -7
- package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.d.ts +0 -11
- package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.d.ts.map +0 -1
- package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.js +0 -1
- package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.test.d.ts +0 -2
- package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.test.d.ts.map +0 -1
- package/dist/components/VariableOptionsDrawer/VariableOptionsDrawer.test.js +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TimeRangeStateProvider = void 0;
|
|
3
|
+
exports.useTimeRangeSetter = exports.TimeRangeSetterContext = exports.TimeRangeStateProvider = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
5
|
// Copyright 2021 The Perses Authors
|
|
6
6
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -22,14 +22,28 @@ const plugin_system_1 = require("@perses-dev/plugin-system");
|
|
|
22
22
|
*/
|
|
23
23
|
function TimeRangeStateProvider(props) {
|
|
24
24
|
const { initialValue, children } = props;
|
|
25
|
-
|
|
26
|
-
const [timeRange] = (0, react_1.useState)(
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
const defaultTimeRange = (0, core_1.toAbsoluteTimeRange)(initialValue);
|
|
26
|
+
const [timeRange, setActiveTimeRange] = (0, react_1.useState)(defaultTimeRange);
|
|
27
|
+
// TODO: add support for passing relative time ranges in setTimeRange, ex: { from: 'now-1h', to: 'now' }
|
|
28
|
+
const setTimeRange = (0, react_1.useCallback)((value) => {
|
|
29
|
+
if (!(0, core_1.isRelativeValue)(value)) {
|
|
30
|
+
setActiveTimeRange(value);
|
|
29
31
|
}
|
|
30
|
-
|
|
31
|
-
});
|
|
32
|
-
const
|
|
33
|
-
return (0, jsx_runtime_1.jsx)(plugin_system_1.TimeRangeContext.Provider, { value: ctx, children: children });
|
|
32
|
+
}, []);
|
|
33
|
+
const ctx = (0, react_1.useMemo)(() => ({ timeRange, defaultDuration: initialValue.pastDuration }), [timeRange, initialValue]);
|
|
34
|
+
const setters = (0, react_1.useMemo)(() => ({ setTimeRange }), [setTimeRange]);
|
|
35
|
+
return ((0, jsx_runtime_1.jsx)(exports.TimeRangeSetterContext.Provider, { value: setters, children: (0, jsx_runtime_1.jsx)(plugin_system_1.TimeRangeContext.Provider, { value: ctx, children: children }) }));
|
|
34
36
|
}
|
|
35
37
|
exports.TimeRangeStateProvider = TimeRangeStateProvider;
|
|
38
|
+
exports.TimeRangeSetterContext = (0, react_1.createContext)(undefined);
|
|
39
|
+
/**
|
|
40
|
+
* Gets the setters for time range selection provided by the TimeRangeStateProvider at runtime.
|
|
41
|
+
*/
|
|
42
|
+
function useTimeRangeSetter() {
|
|
43
|
+
const ctx = (0, react_1.useContext)(exports.TimeRangeSetterContext);
|
|
44
|
+
if (ctx === undefined) {
|
|
45
|
+
throw new Error('No TimeRangeSetterContext found. Did you forget a Provider?');
|
|
46
|
+
}
|
|
47
|
+
return ctx;
|
|
48
|
+
}
|
|
49
|
+
exports.useTimeRangeSetter = useTimeRangeSetter;
|
|
@@ -28,3 +28,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
__exportStar(require("./TemplateVariablesProvider"), exports);
|
|
30
30
|
__exportStar(require("./TimeRangeStateProvider"), exports);
|
|
31
|
+
__exportStar(require("./DashboardProvider"), exports);
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.default = {
|
|
16
|
+
'&.react-grid-layout': {
|
|
17
|
+
position: 'relative',
|
|
18
|
+
transition: 'height 200ms ease',
|
|
19
|
+
},
|
|
20
|
+
'&.react-grid-item': {
|
|
21
|
+
transition: 'all 200ms ease',
|
|
22
|
+
transitionProperty: 'left, top',
|
|
23
|
+
},
|
|
24
|
+
'&.react-grid-item img': {
|
|
25
|
+
pointerEvents: 'none',
|
|
26
|
+
userSelect: 'none',
|
|
27
|
+
},
|
|
28
|
+
'&.react-grid-item.cssTransforms': {
|
|
29
|
+
transitionProperty: 'transform',
|
|
30
|
+
},
|
|
31
|
+
'&.react-grid-item.resizing': {
|
|
32
|
+
zIndex: 1,
|
|
33
|
+
willChange: 'width, height',
|
|
34
|
+
},
|
|
35
|
+
'&.react-grid-item.react-draggable-dragging': {
|
|
36
|
+
transition: 'none',
|
|
37
|
+
zIndex: 3,
|
|
38
|
+
willChange: 'transform',
|
|
39
|
+
},
|
|
40
|
+
'&.react-grid-item.dropping': {
|
|
41
|
+
visibility: 'hidden',
|
|
42
|
+
},
|
|
43
|
+
'&.react-grid-item.react-grid-placeholder': {
|
|
44
|
+
background: 'red',
|
|
45
|
+
opacity: 0.2,
|
|
46
|
+
transitionDuration: '100ms',
|
|
47
|
+
zIndex: 2,
|
|
48
|
+
userSelect: 'none',
|
|
49
|
+
'-webkit-user-select': 'none',
|
|
50
|
+
'-moz-user-select': 'none',
|
|
51
|
+
'-ms-user-select': 'none',
|
|
52
|
+
'-o-user-select': 'none',
|
|
53
|
+
},
|
|
54
|
+
'&.react-grid-item > .react-resizable-handle': {
|
|
55
|
+
position: 'absolute',
|
|
56
|
+
width: '20px',
|
|
57
|
+
height: '20px',
|
|
58
|
+
},
|
|
59
|
+
'&.react-grid-item > .react-resizable-handle::after': {
|
|
60
|
+
content: '""',
|
|
61
|
+
position: 'absolute',
|
|
62
|
+
right: '3px',
|
|
63
|
+
bottom: '3px',
|
|
64
|
+
width: '5px',
|
|
65
|
+
height: '5px',
|
|
66
|
+
borderRight: '2px solid rgba(0, 0, 0, 0.4)',
|
|
67
|
+
borderBottom: '2px solid rgba(0, 0, 0, 0.4)',
|
|
68
|
+
},
|
|
69
|
+
'&.react-resizable-hide > .react-resizable-handle': {
|
|
70
|
+
display: 'none',
|
|
71
|
+
},
|
|
72
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-sw': {
|
|
73
|
+
bottom: '0',
|
|
74
|
+
left: '0',
|
|
75
|
+
cursor: 'sw-resize',
|
|
76
|
+
transform: 'rotate(90deg)',
|
|
77
|
+
},
|
|
78
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-se': {
|
|
79
|
+
bottom: '0',
|
|
80
|
+
right: '0',
|
|
81
|
+
cursor: 'se-resize',
|
|
82
|
+
},
|
|
83
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-nw': {
|
|
84
|
+
top: '0',
|
|
85
|
+
left: '0',
|
|
86
|
+
cursor: 'nw-resize',
|
|
87
|
+
transform: 'rotate(180deg)',
|
|
88
|
+
},
|
|
89
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-ne': {
|
|
90
|
+
top: '0',
|
|
91
|
+
right: '0',
|
|
92
|
+
cursor: 'ne-resize',
|
|
93
|
+
transform: 'rotate(270deg)',
|
|
94
|
+
},
|
|
95
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-w, &.react-grid-item > .react-resizable-handle.react-resizable-handle-e': {
|
|
96
|
+
top: '50%',
|
|
97
|
+
marginTop: '-10px',
|
|
98
|
+
cursor: 'ew-resize',
|
|
99
|
+
},
|
|
100
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-w': {
|
|
101
|
+
left: '0',
|
|
102
|
+
transform: 'rotate(135deg)',
|
|
103
|
+
},
|
|
104
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-e': {
|
|
105
|
+
right: '0',
|
|
106
|
+
transform: 'rotate(315deg)',
|
|
107
|
+
},
|
|
108
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-n, &.react-grid-item > .react-resizable-handle.react-resizable-handle-s': {
|
|
109
|
+
left: '50%',
|
|
110
|
+
marginLeft: '-10px',
|
|
111
|
+
cursor: 'ns-resize',
|
|
112
|
+
},
|
|
113
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-n': {
|
|
114
|
+
top: '0',
|
|
115
|
+
transform: 'rotate(225deg)',
|
|
116
|
+
},
|
|
117
|
+
'&.react-grid-item > .react-resizable-handle.react-resizable-handle-s': {
|
|
118
|
+
bottom: '0',
|
|
119
|
+
transform: 'rotate(45deg)',
|
|
120
|
+
},
|
|
121
|
+
'&.react-resizable': {
|
|
122
|
+
position: 'relative',
|
|
123
|
+
},
|
|
124
|
+
'&.react-resizable-handle': {
|
|
125
|
+
position: 'absolute',
|
|
126
|
+
width: '20px',
|
|
127
|
+
height: '20px',
|
|
128
|
+
backgroundRepeat: 'no-repeat',
|
|
129
|
+
backgroundOrigin: 'content-box',
|
|
130
|
+
boxSizing: 'border-box',
|
|
131
|
+
backgroundImage: `url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA2IDYiIHN0eWxlPSJiYWNrZ3JvdW5kLWNvbG9yOiNmZmZmZmYwMCIgeD0iMHB4IiB5PSIwcHgiIHdpZHRoPSI2cHgiIGhlaWdodD0iNnB4Ij48ZyBvcGFjaXR5PSIwLjMwMiI+PHBhdGggZD0iTSA2IDYgTCAwIDYgTCAwIDQuMiBMIDQgNC4yIEwgNC4yIDQuMiBMIDQuMiAwIEwgNiAwIEwgNiA2IEwgNiA2IFoiIGZpbGw9IiMwMDAwMDAiLz48L2c+PC9zdmc+')`,
|
|
132
|
+
backgroundPosition: 'bottom right',
|
|
133
|
+
padding: '0 3px 3px 0',
|
|
134
|
+
},
|
|
135
|
+
'&.react-resizable-handle-sw': {
|
|
136
|
+
bottom: '0',
|
|
137
|
+
left: '0',
|
|
138
|
+
cursor: 'sw-resize',
|
|
139
|
+
transform: 'rotate(90deg)',
|
|
140
|
+
},
|
|
141
|
+
'&.react-resizable-handle-se': {
|
|
142
|
+
bottom: '0',
|
|
143
|
+
right: '0',
|
|
144
|
+
cursor: 'se-resize',
|
|
145
|
+
},
|
|
146
|
+
'&.react-resizable-handle-nw': {
|
|
147
|
+
top: '0',
|
|
148
|
+
left: '0',
|
|
149
|
+
cursor: 'nw-resize',
|
|
150
|
+
transform: 'rotate(180deg)',
|
|
151
|
+
},
|
|
152
|
+
'&.react-resizable-handle-ne': {
|
|
153
|
+
top: '0',
|
|
154
|
+
right: '0',
|
|
155
|
+
cursor: 'ne-resize',
|
|
156
|
+
transform: 'rotate(270deg)',
|
|
157
|
+
},
|
|
158
|
+
'&.react-resizable-handle-w, .react-resizable-handle-e': {
|
|
159
|
+
top: '50%',
|
|
160
|
+
marginTop: '-10px',
|
|
161
|
+
cursor: 'ew-resize',
|
|
162
|
+
},
|
|
163
|
+
'&.react-resizable-handle-w': {
|
|
164
|
+
left: '0',
|
|
165
|
+
transform: 'rotate(135deg)',
|
|
166
|
+
},
|
|
167
|
+
'&.react-resizable-handle-e': {
|
|
168
|
+
right: '0',
|
|
169
|
+
transform: 'rotate(315deg)',
|
|
170
|
+
},
|
|
171
|
+
'&.react-resizable-handle-n, .react-resizable-handle-s': {
|
|
172
|
+
left: '50%',
|
|
173
|
+
marginLeft: '-10px',
|
|
174
|
+
cursor: 'ns-resize',
|
|
175
|
+
},
|
|
176
|
+
'&.react-resizable-handle-n': {
|
|
177
|
+
top: '0',
|
|
178
|
+
transform: 'rotate(225deg)',
|
|
179
|
+
},
|
|
180
|
+
'&.react-resizable-handle-s': {
|
|
181
|
+
bottom: '0',
|
|
182
|
+
transform: 'rotate(45deg)',
|
|
183
|
+
},
|
|
184
|
+
};
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2021 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const testDashboard = {
|
|
16
|
+
kind: 'Dashboard',
|
|
17
|
+
metadata: {
|
|
18
|
+
name: 'Node Stats',
|
|
19
|
+
project: 'perses',
|
|
20
|
+
created_at: '2021-11-09',
|
|
21
|
+
updated_at: '2021-11-09',
|
|
22
|
+
version: 0,
|
|
23
|
+
},
|
|
24
|
+
spec: {
|
|
25
|
+
datasource: { kind: 'Prometheus', global: true, name: 'Public Prometheus Demo Server' },
|
|
26
|
+
// TODO: Should duration actually be a time range?
|
|
27
|
+
duration: '24h',
|
|
28
|
+
variables: {
|
|
29
|
+
job: {
|
|
30
|
+
kind: 'PrometheusLabelValues',
|
|
31
|
+
options: {
|
|
32
|
+
label_name: 'job',
|
|
33
|
+
match: ['node_uname_info'],
|
|
34
|
+
},
|
|
35
|
+
display: {
|
|
36
|
+
label: 'Job',
|
|
37
|
+
},
|
|
38
|
+
selection: {
|
|
39
|
+
default_value: 'node',
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
instance: {
|
|
43
|
+
kind: 'PrometheusLabelValues',
|
|
44
|
+
options: {
|
|
45
|
+
label_name: 'instance',
|
|
46
|
+
match: ['node_uname_info{job="node"}'],
|
|
47
|
+
},
|
|
48
|
+
display: {
|
|
49
|
+
label: 'Node',
|
|
50
|
+
},
|
|
51
|
+
selection: {
|
|
52
|
+
default_value: ['demo.do.prometheus.io:9100'],
|
|
53
|
+
all_value: '$__all',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
interval: {
|
|
57
|
+
kind: 'Interval',
|
|
58
|
+
options: {
|
|
59
|
+
values: ['1m', '5m', '10m', '1h'],
|
|
60
|
+
auto: {
|
|
61
|
+
step_count: 50,
|
|
62
|
+
min_interval: '1m',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
display: {
|
|
66
|
+
label: 'Interval',
|
|
67
|
+
},
|
|
68
|
+
selection: {
|
|
69
|
+
default_value: '1m',
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
panels: {
|
|
74
|
+
cpu: {
|
|
75
|
+
kind: 'LineChart',
|
|
76
|
+
display: { name: 'CPU' },
|
|
77
|
+
options: {
|
|
78
|
+
queries: [
|
|
79
|
+
{
|
|
80
|
+
kind: 'PrometheusGraphQuery',
|
|
81
|
+
options: {
|
|
82
|
+
query: 'avg without (cpu)(rate(node_cpu_seconds_total{job="node",instance="$instance",mode!="idle"}[$interval]))',
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
],
|
|
86
|
+
unit: { kind: '%' },
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
memory: {
|
|
90
|
+
kind: 'LineChart',
|
|
91
|
+
display: { name: 'Memory' },
|
|
92
|
+
options: {
|
|
93
|
+
queries: [
|
|
94
|
+
{
|
|
95
|
+
kind: 'PrometheusGraphQuery',
|
|
96
|
+
options: {
|
|
97
|
+
query: 'node_memory_MemTotal_bytes{job="node",instance="$instance"} - node_memory_MemFree_bytes{job="node",instance="$instance"} - node_memory_Buffers_bytes{job="node",instance="$instance"} - node_memory_Cached_bytes{job="node",instance="$instance"}',
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
kind: 'PrometheusGraphQuery',
|
|
102
|
+
options: {
|
|
103
|
+
query: 'node_memory_Buffers_bytes{job="node",instance="$instance"}',
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
kind: 'PrometheusGraphQuery',
|
|
108
|
+
options: {
|
|
109
|
+
query: 'node_memory_Cached_bytes{job="node",instance="$instance"}',
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
kind: 'PrometheusGraphQuery',
|
|
114
|
+
options: {
|
|
115
|
+
query: 'node_memory_MemFree_bytes{job="node",instance="$instance"}',
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
unit: { kind: 'Bytes' },
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
diskIO: {
|
|
123
|
+
kind: 'LineChart',
|
|
124
|
+
display: { name: 'Disk I/O Utilization' },
|
|
125
|
+
options: {
|
|
126
|
+
queries: [
|
|
127
|
+
{
|
|
128
|
+
kind: 'PrometheusGraphQuery',
|
|
129
|
+
options: {
|
|
130
|
+
query: 'rate(node_disk_io_time_seconds_total{job="node",instance="$instance",device!~"^(md\\\\d+$|dm-)"}[$interval])',
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
unit: { kind: 'Percent' },
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
filesystemFullness: {
|
|
138
|
+
kind: 'LineChart',
|
|
139
|
+
display: { name: 'Filesystem Fullness' },
|
|
140
|
+
options: {
|
|
141
|
+
queries: [
|
|
142
|
+
{
|
|
143
|
+
kind: 'PrometheusGraphQuery',
|
|
144
|
+
options: {
|
|
145
|
+
query: '1 - node_filesystem_free_bytes{job="node",instance="$instance",fstype!="rootfs",mountpoint!~"/(run|var).*",mountpoint!=""} / node_filesystem_size_bytes{job="node",instance="$instance"}',
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
],
|
|
149
|
+
unit: { kind: 'Percent' },
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
layouts: [
|
|
154
|
+
// Regular Title, no collapse enabled
|
|
155
|
+
{
|
|
156
|
+
kind: 'Grid',
|
|
157
|
+
spec: {
|
|
158
|
+
display: {
|
|
159
|
+
title: 'CPU Stats',
|
|
160
|
+
},
|
|
161
|
+
items: [
|
|
162
|
+
// First Row
|
|
163
|
+
{
|
|
164
|
+
x: 0,
|
|
165
|
+
y: 0,
|
|
166
|
+
width: 12,
|
|
167
|
+
height: 4,
|
|
168
|
+
content: { $ref: '#/spec/panels/cpu' },
|
|
169
|
+
},
|
|
170
|
+
],
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
// No title,
|
|
174
|
+
{
|
|
175
|
+
kind: 'Grid',
|
|
176
|
+
spec: {
|
|
177
|
+
items: [
|
|
178
|
+
{
|
|
179
|
+
x: 8,
|
|
180
|
+
y: 0,
|
|
181
|
+
width: 8,
|
|
182
|
+
height: 3,
|
|
183
|
+
content: { $ref: '#/spec/panels/memory' },
|
|
184
|
+
},
|
|
185
|
+
],
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
// Collapsed
|
|
189
|
+
{
|
|
190
|
+
kind: 'Grid',
|
|
191
|
+
spec: {
|
|
192
|
+
display: {
|
|
193
|
+
title: 'Disk Stats',
|
|
194
|
+
collapse: {
|
|
195
|
+
open: false,
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
items: [
|
|
199
|
+
{
|
|
200
|
+
x: 0,
|
|
201
|
+
y: 0,
|
|
202
|
+
width: 6,
|
|
203
|
+
height: 2,
|
|
204
|
+
content: { $ref: '#/spec/panels/diskIO' },
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
x: 18,
|
|
208
|
+
y: 0,
|
|
209
|
+
width: 6,
|
|
210
|
+
height: 2,
|
|
211
|
+
content: { $ref: '#/spec/panels/filesystemFullness' },
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
exports.default = testDashboard;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright 2022 The Perses Authors
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
//
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
//
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.removeWhiteSpacesAndSpecialCharacters = void 0;
|
|
16
|
+
const removeWhiteSpacesAndSpecialCharacters = (str) => {
|
|
17
|
+
return str.replace(/\s+/g, '');
|
|
18
|
+
};
|
|
19
|
+
exports.removeWhiteSpacesAndSpecialCharacters = removeWhiteSpacesAndSpecialCharacters;
|
|
@@ -0,0 +1,46 @@
|
|
|
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
|
+
exports.DashboardApp = void 0;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
// Copyright 2022 The Perses Authors
|
|
9
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
+
// you may not use this file except in compliance with the License.
|
|
11
|
+
// You may obtain a copy of the License at
|
|
12
|
+
//
|
|
13
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
+
//
|
|
15
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
+
// See the License for the specific language governing permissions and
|
|
19
|
+
// limitations under the License.
|
|
20
|
+
const material_1 = require("@mui/material");
|
|
21
|
+
const components_1 = require("@perses-dev/components");
|
|
22
|
+
const react_1 = require("react");
|
|
23
|
+
const components_2 = require("../components");
|
|
24
|
+
const AddPanel_1 = __importDefault(require("../components/AddPanel/AddPanel"));
|
|
25
|
+
const DashboardToolbar_1 = require("../components/DashboardToolbar");
|
|
26
|
+
const context_1 = require("../context");
|
|
27
|
+
const DashboardApp = (props) => {
|
|
28
|
+
const { dashboardResource, sx, children, ...others } = props;
|
|
29
|
+
const [showAddPanel, setShowAddPanel] = (0, react_1.useState)(false);
|
|
30
|
+
const { dashboard } = (0, context_1.useDashboard)();
|
|
31
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: (0, components_1.combineSx)({
|
|
32
|
+
display: 'flex',
|
|
33
|
+
width: '100%',
|
|
34
|
+
height: '100%',
|
|
35
|
+
position: 'relative',
|
|
36
|
+
overflow: 'hidden',
|
|
37
|
+
}, sx), ...others, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
38
|
+
padding: (theme) => theme.spacing(1, 2),
|
|
39
|
+
flexGrow: 1,
|
|
40
|
+
overflowX: 'hidden',
|
|
41
|
+
overflowY: 'auto',
|
|
42
|
+
display: 'flex',
|
|
43
|
+
flexDirection: 'column',
|
|
44
|
+
}, children: [(0, jsx_runtime_1.jsx)(DashboardToolbar_1.DashboardToolbar, { dashboardName: dashboardResource.metadata.name, onAddPanel: () => setShowAddPanel(true) }), (0, jsx_runtime_1.jsx)(components_2.VariableList, { variables: dashboardResource.spec.variables, sx: { margin: (theme) => theme.spacing(1, 0, 2) } }), (0, jsx_runtime_1.jsx)(components_2.Dashboard, { spec: dashboard }), (0, jsx_runtime_1.jsx)(AddPanel_1.default, { isOpen: showAddPanel, onClose: () => setShowAddPanel(false) }), children] }) }));
|
|
45
|
+
};
|
|
46
|
+
exports.DashboardApp = DashboardApp;
|
|
@@ -2,38 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ViewDashboard = void 0;
|
|
4
4
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
-
// Copyright 2021 The Perses Authors
|
|
6
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
// you may not use this file except in compliance with the License.
|
|
8
|
-
// You may obtain a copy of the License at
|
|
9
|
-
//
|
|
10
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
//
|
|
12
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
// See the License for the specific language governing permissions and
|
|
16
|
-
// limitations under the License.
|
|
17
|
-
const material_1 = require("@mui/material");
|
|
18
|
-
const components_1 = require("@perses-dev/components");
|
|
19
5
|
const context_1 = require("../context");
|
|
20
|
-
const
|
|
6
|
+
const DashboardApp_1 = require("./DashboardApp");
|
|
21
7
|
/**
|
|
22
8
|
* The View for displaying a Dashboard, along with the UI for selecting variable values.
|
|
23
9
|
*/
|
|
24
10
|
function ViewDashboard(props) {
|
|
25
|
-
const { dashboardResource
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
width: '100%',
|
|
29
|
-
height: '100%',
|
|
30
|
-
position: 'relative',
|
|
31
|
-
overflow: 'hidden',
|
|
32
|
-
}, sx), ...others, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
33
|
-
padding: (theme) => theme.spacing(1, 2),
|
|
34
|
-
flexGrow: 1,
|
|
35
|
-
overflowX: 'hidden',
|
|
36
|
-
overflowY: 'auto',
|
|
37
|
-
}, children: [(0, jsx_runtime_1.jsx)(components_2.Dashboard, { spec: dashboardResource.spec }), children] }), (0, jsx_runtime_1.jsx)(components_2.VariableOptionsDrawer, { variables: dashboardResource.spec.variables })] }) }) }));
|
|
11
|
+
const { dashboardResource: { spec }, children, } = props;
|
|
12
|
+
const pastDuration = spec.duration;
|
|
13
|
+
return ((0, jsx_runtime_1.jsx)(context_1.DashboardProvider, { initialState: { dashboardSpec: spec }, children: (0, jsx_runtime_1.jsx)(context_1.TimeRangeStateProvider, { initialValue: { pastDuration }, children: (0, jsx_runtime_1.jsx)(context_1.TemplateVariablesProvider, { variableDefinitions: spec.variables, children: (0, jsx_runtime_1.jsx)(DashboardApp_1.DashboardApp, { ...props, children: children }) }) }) }));
|
|
38
14
|
}
|
|
39
15
|
exports.ViewDashboard = ViewDashboard;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AddPanel.d.ts","sourceRoot":"","sources":["../../../src/components/AddPanel/AddPanel.tsx"],"names":[],"mappings":";AA+BA,UAAU,aAAa;IACrB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED,QAAA,MAAM,QAAQ,wBAAyB,aAAa,gBA6EnD,CAAC;AA0BF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{MenuItem,Stack,Select,TextField,InputLabel,FormControl,Grid,Box,Button,Typography}from"@mui/material";import{Drawer}from"@perses-dev/components";import{useState}from"react";import{useLayouts,usePanels}from"../../context";import{removeWhiteSpacesAndSpecialCharacters}from"../../utils/functions";const AddPanel=({isOpen:e,onClose:t})=>{const{layouts:r,addItemToLayout:n}=useLayouts(),{addPanel:a}=usePanels(),[s,o]=useState(0),[i,l]=useState(""),[d,c]=useState("");return _jsx(Drawer,{isOpen:e,onClose:t,children:_jsxs("form",{onSubmit:e=>{var o;e.preventDefault();const l=removeWhiteSpacesAndSpecialCharacters(i);a(l,{kind:"EmptyChart",display:{name:i,description:d},options:{}});let c=0;null===(o=r[s])||void 0===o||o.spec.items.forEach((e=>{e.y>c&&(c=e.y)})),n(s,{x:0,y:c+1,width:12,height:6,content:{$ref:`#/spec/panels/${l}`}}),t()},children:[_jsx(AddPanelHeader,{onClose:t}),_jsxs(Grid,{container:!0,spacing:2,children:[_jsx(Grid,{item:!0,xs:4,children:_jsxs(FormControl,{children:[_jsx(InputLabel,{id:"select-group",children:"Group"}),_jsx(Select,{required:!0,labelId:"select-group",label:"Group",value:s,onChange:e=>{o(e.target.value)},children:r.map(((e,t)=>{var r;return _jsx(MenuItem,{value:t,children:(null===(r=e.spec.display)||void 0===r?void 0:r.title)||`Group ${t+1}`},t)}))})]})}),_jsx(Grid,{item:!0,xs:8,children:_jsxs(Stack,{spacing:2,sx:{flexGrow:"1"},children:[_jsx(FormControl,{children:_jsx(TextField,{required:!0,label:"Panel Name",variant:"outlined",onChange:e=>{l(e.target.value)}})}),_jsx(FormControl,{children:_jsx(TextField,{label:"Description",variant:"outlined",onChange:e=>{c(e.target.value)}})})]})})]})]})})},AddPanelHeader=({onClose:e})=>_jsxs(Box,{sx:{display:"flex",alignItems:"center",marginBottom:e=>e.spacing(2),paddingBottom:e=>e.spacing(2),borderBottom:e=>`1px solid ${e.palette.grey[100]}`},children:[_jsx(Typography,{variant:"h5",children:"Add Panel"}),_jsxs(Stack,{direction:"row",spacing:1,sx:{marginLeft:"auto"},children:[_jsx(Button,{type:"submit",variant:"contained",children:"Add Panel"}),_jsx(Button,{variant:"outlined",onClick:e,children:"Cancel"})]})]});export default AddPanel;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DashboardToolbar.d.ts","sourceRoot":"","sources":["../../src/components/DashboardToolbar.tsx"],"names":[],"mappings":";AAoBA,MAAM,WAAW,qBAAqB;IACpC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB;AAED,eAAO,MAAM,gBAAgB,UAAW,qBAAqB,gBA4E5D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsxs as _jsxs,jsx as _jsx,Fragment as _Fragment}from"react/jsx-runtime";import{Toolbar,Typography,Stack,Button,Box}from"@mui/material";import PencilIcon from"mdi-material-ui/PencilOutline";import AddIcon from"mdi-material-ui/Plus";import{useEditMode,useLayouts}from"../context";import{TimeRangeControls}from"../components";export const DashboardToolbar=i=>{const{dashboardName:t,onAddPanel:n}=i,{isEditMode:o,setEditMode:s}=useEditMode(),{addLayout:a}=useLayouts();return _jsx(Toolbar,{disableGutters:!0,sx:{display:"block",padding:i=>i.spacing(2,0)},children:o?_jsxs(_Fragment,{children:[_jsxs(Box,{sx:{display:"flex",width:"100%"},children:[_jsxs(Typography,{variant:"h2",children:["Edit ",t]}),_jsxs(Stack,{direction:"row",spacing:1,sx:{marginLeft:"auto"},children:[_jsx(TimeRangeControls,{}),_jsx(Button,{variant:"outlined",onClick:()=>{s(!1)},children:"Cancel"}),_jsx(Button,{variant:"contained",children:"Save"})]})]}),_jsxs(Stack,{direction:"row",spacing:1,sx:{display:"flex",justifyContent:"flex-end",width:"100%",padding:i=>i.spacing(2,0)},children:[_jsx(Button,{startIcon:_jsx(AddIcon,{}),onClick:()=>{a({kind:"Grid",spec:{display:{title:"New Group",collapse:{open:!0}},items:[]}})},children:"Add Group"}),_jsx(Button,{startIcon:_jsx(AddIcon,{}),onClick:n,children:"Add Panel"})]})]}):_jsxs(Box,{sx:{display:"flex",width:"100%"},children:[_jsx(Typography,{variant:"h2",children:t}),_jsxs(Stack,{direction:"row",spacing:2,sx:{marginLeft:"auto"},children:[_jsx(TimeRangeControls,{}),_jsx(Button,{variant:"contained",startIcon:_jsx(PencilIcon,{}),onClick:()=>{s(!0)},sx:{marginLeft:"auto"},children:"Edit"})]})]})})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAO,QAAQ,
|
|
1
|
+
{"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAO,QAAQ,EAA0B,MAAM,eAAe,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAOtE,MAAM,WAAW,eAAgB,SAAQ,QAAQ;IAC/C,UAAU,EAAE,cAAc,CAAC;IAC3B,qBAAqB,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,KAAK,CAAC,SAAS,CAAC;CAC5E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,eAsDhD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState}from"react";import{Box,Collapse}from"@mui/material";import{GridTitle}from"./GridTitle";const
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{useState}from"react";import{Responsive,WidthProvider}from"react-grid-layout";import{Box,Collapse,GlobalStyles}from"@mui/material";import styles from"../../css/styles";import{useEditMode}from"../../context";import{GridTitle}from"./GridTitle";const ResponsiveGridLayout=WidthProvider(Responsive);export function GridLayout(s){var e,i,o;const{definition:{spec:t},renderGridItemContent:l,...r}=s,[d,a]=useState(null===(o=null===(i=null===(e=t.display)||void 0===e?void 0:e.collapse)||void 0===i?void 0:i.open)||void 0===o||o),{isEditMode:n}=useEditMode(),m=[];return t.items.forEach(((s,e)=>{const{x:i,y:o,width:t,height:r}=s;m.push(_jsx("div",{"data-grid":{x:i,y:o,w:t,h:r},children:l(s)},e))})),_jsxs(_Fragment,{children:[_jsx(GlobalStyles,{styles}),_jsxs(Box,{...r,component:"section",sx:{"& + &":{marginTop:s=>s.spacing(1)}},children:[void 0!==t.display&&_jsx(GridTitle,{title:t.display.title,collapse:void 0===t.display.collapse?void 0:{isOpen:d,onToggleOpen:()=>a((s=>!s))}}),_jsx(Collapse,{in:d,unmountOnExit:!0,children:_jsx(ResponsiveGridLayout,{className:"layout",breakpoints:{lg:1200,md:996,sm:768,xs:480,xxs:0},cols:{lg:24,md:24,sm:24,xs:24,xxs:2},rowHeight:30,draggableHandle:".drag-handle",resizeHandles:["se"],isDraggable:n,isResizable:n,children:m})})]})]})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.tsx"],"names":[],"mappings":";AAkBA,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAGL,SAAS,EAOV,MAAM,eAAe,CAAC;AAOvB,MAAM,WAAW,UAAW,SAAQ,SAAS;IAC3C,UAAU,EAAE,eAAe,CAAC;CAC7B;AAED;;GAEG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,eAoHtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState,useMemo}from"react";import useResizeObserver from"use-resize-observer";import{useInView}from"react-intersection-observer";import{PluginBoundary,PanelComponent}from"@perses-dev/plugin-system";import{ErrorAlert,InfoTooltip,TooltipPlacement}from"@perses-dev/components";import{Box,Card,CardHeader,CardContent,Typography}from"@mui/material";import InformationOutlineIcon from"mdi-material-ui/InformationOutline";export function Panel(e){const{definition:i,...o}=e,[r
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useState,useMemo}from"react";import useResizeObserver from"use-resize-observer";import{useInView}from"react-intersection-observer";import{PluginBoundary,PanelComponent}from"@perses-dev/plugin-system";import{ErrorAlert,InfoTooltip,TooltipPlacement}from"@perses-dev/components";import{Box,Card,CardHeader,CardContent,Typography,IconButton as MuiIconButton,Stack,styled}from"@mui/material";import InformationOutlineIcon from"mdi-material-ui/InformationOutline";import PencilIcon from"mdi-material-ui/Pencil";import MenuIcon from"mdi-material-ui/DotsVertical";import DragIcon from"mdi-material-ui/Drag";import{useEditMode}from"../../context";export function Panel(e){const{definition:i,...o}=e,[n,r]=useState(null),{width:t,height:a}=useResizeObserver({ref:n}),s=useMemo((()=>{if(void 0!==t&&void 0!==a)return{width:t,height:a}}),[t,a]),{ref:l,inView:d}=useInView({threshold:.3,initialInView:!1,triggerOnce:!0}),{isEditMode:c}=useEditMode();return _jsxs(Card,{ref:l,sx:{...o.sx,width:"100%",height:"100%",display:"flex",flexFlow:"column nowrap"},variant:"outlined",...o,children:[_jsx(CardHeader,{title:_jsxs(Box,{sx:{display:"flex",alignItems:"center",minHeight:"24px"},children:[_jsx(Typography,{component:"h2",variant:"body2",fontWeight:e=>e.typography.fontWeightMedium,whiteSpace:"nowrap",overflow:"hidden",textOverflow:"ellipsis",children:i.display.name}),_jsxs(Box,{sx:{display:"flex",alignItems:"center",marginLeft:"auto"},children:[!c&&i.display.description&&_jsx(InfoTooltip,{id:"info-tooltip",description:i.display.description,placement:TooltipPlacement.Bottom,children:_jsx(InformationOutlineIcon,{"aria-describedby":"info-tooltip","aria-hidden":!1,fontSize:"small",sx:{cursor:"pointer"}})}),c&&_jsxs(Stack,{direction:"row",alignItems:"center",spacing:.5,children:[_jsx(IconButton,{"aria-label":"drag handle",size:"small",children:_jsx(DragIcon,{className:"drag-handle",sx:{cursor:"grab"}})}),_jsx(IconButton,{"aria-label":"edit panel",size:"small",children:_jsx(PencilIcon,{})}),_jsx(IconButton,{"aria-label":"more",size:"small",children:_jsx(MenuIcon,{})})]})]})]}),sx:{display:"block",padding:e=>e.spacing(1,1.5),borderBottom:e=>`solid 1px ${e.palette.divider}`}}),_jsx(CardContent,{sx:{position:"relative",overflow:"hidden",flexGrow:1,padding:e=>e.spacing(1.5),":last-child":{padding:e=>e.spacing(1.5)}},ref:r,children:_jsx(PluginBoundary,{loadingFallback:"Loading...",ErrorFallbackComponent:ErrorAlert,children:!0===d&&_jsx(PanelComponent,{definition:i,contentDimensions:s})})})]})}const IconButton=styled(MuiIconButton)((({theme:e})=>({borderRadius:e.shape.borderRadius,padding:"4px"})));
|