@perses-dev/dashboards 0.5.1 → 0.7.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/AddPanel/AddPanel.js +75 -0
- package/dist/cjs/components/DashboardToolbar.js +52 -0
- package/dist/cjs/components/GridLayout/GridLayout.js +9 -26
- package/dist/cjs/components/Panel/Panel.js +24 -4
- package/dist/cjs/components/Panel/Panel.test.js +21 -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/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 +2 -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.d.ts +1 -1
- package/dist/components/Panel/Panel.test.d.ts.map +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/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 +16 -6
- 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,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,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
import 'react-grid-layout/css/styles.css';
|
|
3
|
+
import 'react-resizable/css/styles.css';
|
|
2
4
|
import { BoxProps } from '@mui/material';
|
|
3
5
|
import { GridDefinition, GridItemDefinition } from '@perses-dev/core';
|
|
4
6
|
export interface GridLayoutProps extends BoxProps {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"GridLayout.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/GridLayout.tsx"],"names":[],"mappings":";AAYA,OAAO,kCAAkC,CAAC;AAC1C,OAAO,gCAAgC,CAAC;AAIxC,OAAO,EAAO,QAAQ,EAAY,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAMtE,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,eAmDhD"}
|
|
@@ -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}from"react/jsx-runtime";import"react-grid-layout/css/styles.css";import"react-resizable/css/styles.css";import{useState}from"react";import{Responsive,WidthProvider}from"react-grid-layout";import{Box,Collapse}from"@mui/material";import{useEditMode}from"../../context";import{GridTitle}from"./GridTitle";const ResponsiveGridLayout=WidthProvider(Responsive);export function GridLayout(s){var i,e,o;const{definition:{spec:t},renderGridItemContent:r,...d}=s,[l,a]=useState(null===(o=null===(e=null===(i=t.display)||void 0===i?void 0:i.collapse)||void 0===e?void 0:e.open)||void 0===o||o),{isEditMode:n}=useEditMode(),p=[];return t.items.forEach(((s,i)=>{const{x:e,y:o,width:t,height:d}=s;p.push(_jsx("div",{"data-grid":{x:e,y:o,w:t,h:d},children:r(s)},i))})),_jsxs(Box,{...d,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:l,onToggleOpen:()=>a((s=>!s))}}),_jsx(Collapse,{in:l,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:p})})]})}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.tsx"],"names":[],"mappings":";
|
|
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{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";import
|
|
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"})));
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import 'intersection-observer';
|
|
2
2
|
//# sourceMappingURL=Panel.test.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Panel.test.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.test.tsx"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"Panel.test.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.test.tsx"],"names":[],"mappings":"AAeA,OAAO,uBAAuB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{PluginRegistry}from"@perses-dev/plugin-system";import{screen}from"@testing-library/react";import{renderWithContext,mockPluginRegistryProps}from"../../test";import{Panel}from"./Panel";const FAKE_PANEL_PLUGIN={pluginType:"Panel",kind:"FakePanel",plugin:{PanelComponent:()=>_jsx("div",{role:"figure",children:"FakePanel chart"})}};describe("Panel",(()=>{let e;beforeEach((()=>{e={definition:{display:{name:"Fake Panel",description:"This is a fake panel"},kind:"FakePanel",options:{}}}}))
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{PluginRegistry}from"@perses-dev/plugin-system";import"intersection-observer";import{screen}from"@testing-library/react";import{renderWithContext,mockPluginRegistryProps}from"../../test";import testDashboard from"../../test/testDashboard";import{DashboardProvider}from"../../context";import{Panel}from"./Panel";const FAKE_PANEL_PLUGIN={pluginType:"Panel",kind:"FakePanel",plugin:{PanelComponent:()=>_jsx("div",{role:"figure",children:"FakePanel chart"})}};describe("Panel",(()=>{let e,r;beforeEach((()=>{e={definition:{display:{name:"Fake Panel",description:"This is a fake panel"},kind:"FakePanel",options:{}}},r={isEditMode:!1,dashboardSpec:testDashboard.spec}}));const i=r=>{const{addMockPlugin:i,pluginRegistryProps:n}=mockPluginRegistryProps();i(FAKE_PANEL_PLUGIN),renderWithContext(_jsx(DashboardProvider,{initialState:r,children:_jsx(PluginRegistry,{...n,children:_jsx(Panel,{...e})})}))};it("should render name and info icon",(async()=>{i(r),await screen.findByText("Fake Panel"),screen.queryByLabelText("info-tooltip")})),it("should render edit icons when in edit mode",(async()=>{r.isEditMode=!0,i(r),await screen.queryByLabelText("drag handle"),screen.queryByLabelText("edit panel"),screen.queryByLabelText("more")}))}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TimeRangeControls.d.ts","sourceRoot":"","sources":["../../src/components/TimeRangeControls.tsx"],"names":[],"mappings":";AAgBA,OAAO,EAAyC,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAc3F,eAAO,MAAM,YAAY,EAAE,UAAU,EAUpC,CAAC;AAIF,wBAAgB,iBAAiB,gBAsEhC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{useRef,useState}from"react";import{Box,FormControl,InputLabel,Popover,Stack}from"@mui/material";import{sub}from"date-fns";import{AbsoluteTimePicker,TimeRangeSelector}from"@perses-dev/components";import{parseDurationString,toAbsoluteTimeRange,isRelativeValue}from"@perses-dev/core";import{useTimeRange}from"@perses-dev/plugin-system";import{useTimeRangeSetter}from"../context/TimeRangeStateProvider";export const TIME_OPTIONS=[{value:{pastDuration:"5m"},display:"Last 5 minutes"},{value:{pastDuration:"15m"},display:"Last 15 minutes"},{value:{pastDuration:"30m"},display:"Last 30 minutes"},{value:{pastDuration:"1h"},display:"Last 1 hour"},{value:{pastDuration:"6h"},display:"Last 6 hours"},{value:{pastDuration:"12h"},display:"Last 12 hours"},{value:{pastDuration:"24h"},display:"Last 1 day"},{value:{pastDuration:"7d"},display:"Last 7 days"},{value:{pastDuration:"14d"},display:"Last 14 days"}];const FORM_CONTROL_LABEL="Time Range";export function TimeRangeControls(){const{setTimeRange:e}=useTimeRangeSetter(),{defaultDuration:t}=useTimeRange(),a=parseDurationString(t),[s,i]=useState({pastDuration:t}),[n,o]=useState({start:sub(new Date,{...a}),end:new Date}),[r,u]=useState(!1),l=useRef();return _jsxs(Stack,{direction:"row",spacing:1,children:[_jsx(Popover,{anchorEl:l.current,anchorOrigin:{vertical:"bottom",horizontal:"center"},open:r,onClose:()=>u(!1),sx:e=>({padding:e.spacing(2)}),children:_jsx(AbsoluteTimePicker,{initialTimeRange:n,onChange:t=>{e(t),isRelativeValue(t)||o({start:t.start,end:t.end}),i(t),u(!1)}})}),_jsxs(FormControl,{fullWidth:!0,children:[_jsx(InputLabel,{children:"Time Range"}),_jsx(Box,{ref:l,children:_jsx(TimeRangeSelector,{inputLabel:"Time Range",timeOptions:TIME_OPTIONS,value:s,onSelectChange:t=>{const a={pastDuration:t.target.value,end:new Date};i(a);const s=toAbsoluteTimeRange(a);e(s),o(s),u(!1)},onCustomClick:()=>{u(!0)}})})]})]})}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { TextFieldProps } from '@mui/material';
|
|
2
|
+
import { AutocompleteProps as MuiAutocompleteProps, TextFieldProps } from '@mui/material';
|
|
3
3
|
import { VariableDefinition } from '@perses-dev/core';
|
|
4
4
|
import { VariableState } from '@perses-dev/plugin-system';
|
|
5
|
+
declare type AutocompleteProps = MuiAutocompleteProps<string, boolean, true, false>;
|
|
5
6
|
export interface VariableAutocompleteProps {
|
|
6
7
|
definition: VariableDefinition;
|
|
7
8
|
state: VariableState;
|
|
8
9
|
onChange: (value: string | string[]) => void;
|
|
9
10
|
onOptionsChange: (options: string[]) => void;
|
|
10
11
|
TextFieldProps?: TextFieldProps;
|
|
12
|
+
className?: AutocompleteProps['className'];
|
|
13
|
+
sx?: AutocompleteProps['sx'];
|
|
11
14
|
}
|
|
12
15
|
/**
|
|
13
16
|
* A MUI Autocomplete that displays variable options, loaded from the
|
|
14
17
|
* appropriate plugin.
|
|
15
18
|
*/
|
|
16
19
|
export declare function VariableAutocomplete(props: VariableAutocompleteProps): JSX.Element;
|
|
20
|
+
export {};
|
|
17
21
|
//# sourceMappingURL=VariableAutocomplete.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VariableAutocomplete.d.ts","sourceRoot":"","sources":["../../src/components/VariableAutocomplete.tsx"],"names":[],"mappings":";AAcA,OAAO,
|
|
1
|
+
{"version":3,"file":"VariableAutocomplete.d.ts","sourceRoot":"","sources":["../../src/components/VariableAutocomplete.tsx"],"names":[],"mappings":";AAcA,OAAO,EAAgB,iBAAiB,IAAI,oBAAoB,EAAa,cAAc,EAAE,MAAM,eAAe,CAAC;AACnH,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAsB,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG9E,aAAK,iBAAiB,GAAG,oBAAoB,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;AAE5E,MAAM,WAAW,yBAAyB;IACxC,UAAU,EAAE,kBAAkB,CAAC;IAC/B,KAAK,EAAE,aAAa,CAAC;IACrB,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,IAAI,CAAC;IAC7C,eAAe,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC7C,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC,SAAS,CAAC,EAAE,iBAAiB,CAAC,WAAW,CAAC,CAAC;IAC3C,EAAE,CAAC,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC;CAC9B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,eAiEpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useMemo}from"react";import{Autocomplete,TextField}from"@mui/material";import{useVariableOptions}from"@perses-dev/plugin-system";export function VariableAutocomplete(e){const{definition:o,state:r,onChange:l,onOptionsChange:t,TextFieldProps:i}=e,{value:
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{useEffect,useMemo}from"react";import{Autocomplete,TextField}from"@mui/material";import{useVariableOptions}from"@perses-dev/plugin-system";export function VariableAutocomplete(e){const{definition:o,state:r,onChange:l,onOptionsChange:t,TextFieldProps:i,...a}=e,{value:n,options:s}=r,u="all_value"in o.selection?o.selection.all_value:void 0,p=useMemo((()=>{let e=s;return void 0===e&&(e=Array.isArray(n)?n:[n]),void 0!==u&&e[0]!==u&&(e=[u,...e]),e}),[s,n,u]),{data:m,loading:d,error:v}=useVariableOptions(o);return useEffect((()=>{d||t(m)}),[m,d]),_jsx(Autocomplete,{options:p,loading:d,value:n,multiple:Array.isArray(n),disableClearable:!0,freeSolo:!1,onChange:(e,o)=>{l(o)},renderInput:e=>{var r;return _jsx(TextField,{...e,margin:"normal",label:o.display.label,error:void 0!==v,helperText:null!==(r=null==v?void 0:v.message)&&void 0!==r?r:"",...i})},getOptionLabel:e=>e===u?"All":e,ChipProps:{color:"default",variant:"outlined"},...a})}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { StackProps } from '@mui/material';
|
|
3
|
+
import { DashboardSpec } from '@perses-dev/core';
|
|
4
|
+
export interface VariableListProps extends StackProps {
|
|
5
|
+
variables: DashboardSpec['variables'];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Displays the list of variable inputs for a dashboard.
|
|
9
|
+
*/
|
|
10
|
+
export declare function VariableList(props: VariableListProps): JSX.Element;
|
|
11
|
+
//# sourceMappingURL=VariableList.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VariableList.d.ts","sourceRoot":"","sources":["../../../src/components/VariableList/VariableList.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAS,UAAU,EAAc,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAKjD,MAAM,WAAW,iBAAkB,SAAQ,UAAU;IACnD,SAAS,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC;CACvC;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eAqCpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{Stack,Typography}from"@mui/material";import{ErrorAlert}from"@perses-dev/components";import{PluginBoundary,useTemplateVariables}from"@perses-dev/plugin-system";import{useTemplateVariablesSetters}from"../../context";import{VariableAutocomplete}from"../VariableAutocomplete";export function VariableList(e){const{variables:r,...t}=e,{variables:a}=useTemplateVariables(),{setValue:o,setOptions:s}=useTemplateVariablesSetters();return _jsxs(Stack,{direction:{xs:"column",sm:"row"},alignItems:{sm:"center"},spacing:2,...t,children:[_jsx(Typography,{variant:"body2",sx:{fontWeight:e=>e.typography.fontWeightMedium},children:"Variables"}),Object.entries(r).map((([e,r])=>{if(!0===r.display.hide)return null;const t=a[e];if(void 0===t){const r=new Error(`Variable state for '${e}' not found`);return _jsx(ErrorAlert,{error:r},e)}return _jsx(PluginBoundary,{loadingFallback:"Loading...",ErrorFallbackComponent:ErrorAlert,children:_jsx(VariableAutocomplete,{definition:r,state:t,onChange:r=>o(e,r),onOptionsChange:r=>s(e,r),TextFieldProps:{margin:"none"},sx:{minWidth:250}})},e)}))]})}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VariableList.test.d.ts","sourceRoot":"","sources":["../../../src/components/VariableList/VariableList.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as _jsx}from"react/jsx-runtime";import{screen}from"@testing-library/react";import userEvent from"@testing-library/user-event";import{PluginRegistry}from"@perses-dev/plugin-system";import{mockPluginRegistryProps,renderWithContext}from"../../test";import{TemplateVariablesProvider}from"../../context";import{VariableList}from"./VariableList";describe("VariableList",(()=>{const e={job:{display:{label:"Job"},kind:"PrometheusLabelValues",selection:{default_value:"node"},options:{label_name:"job",match:["node_uname_info"]}}},t={data:["node","all"],isLoading:!1,error:void 0},i={pluginType:"Variable",kind:"PrometheusLabelValues",plugin:{useVariableOptions:()=>t}},a=()=>{const{addMockPlugin:t,pluginRegistryProps:a}=mockPluginRegistryProps();t(i),renderWithContext(_jsx(PluginRegistry,{...a,children:_jsx(TemplateVariablesProvider,{variableDefinitions:e,children:_jsx(VariableList,{variables:e})})}))};it("should display Variables as the title",(async()=>{a();const e=await screen.findByText("Variables");expect(e).toBeInTheDocument()})),describe("VariableAutocomplete",(()=>{it("should display correct variable",(async()=>{a();const e=await screen.findByLabelText("Job");expect(e).toBeInTheDocument()})),it("should display correct default value",(async()=>{a();const e=await screen.findByDisplayValue("node");expect(e).toBeInTheDocument()})),it("should display correct options",(async()=>{a();const e=await screen.findByRole("button",{name:"Open"});userEvent.click(e);const t=await screen.findByText("all");expect(t).toBeInTheDocument();const i=screen.getByText("node");expect(i).toBeInTheDocument()}))}))}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/VariableList/index.ts"],"names":[],"mappings":"AAaA,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export*from"./VariableList";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './Dashboard';
|
|
2
2
|
export * from './GridLayout';
|
|
3
3
|
export * from './Panel/Panel';
|
|
4
|
+
export * from './TimeRangeControls';
|
|
4
5
|
export * from './VariableAutocomplete';
|
|
5
|
-
export * from './
|
|
6
|
+
export * from './VariableList';
|
|
6
7
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,wBAAwB,CAAC;AACvC,cAAc
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,gBAAgB,CAAC"}
|
package/dist/components/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export*from"./Dashboard";export*from"./GridLayout";export*from"./Panel/Panel";export*from"./VariableAutocomplete";export*from"./
|
|
1
|
+
export*from"./Dashboard";export*from"./GridLayout";export*from"./Panel/Panel";export*from"./TimeRangeControls";export*from"./VariableAutocomplete";export*from"./VariableList";
|