@perses-dev/dashboards 0.6.0 → 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 +15 -1
- package/dist/cjs/components/Panel/Panel.test.js +20 -3
- package/dist/cjs/components/TimeRangeControls.js +77 -0
- package/dist/cjs/components/index.js +1 -0
- 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.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/index.d.ts +1 -0
- 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 +13 -10
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
// Copyright 2022 The Perses Authors
|
|
5
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
// you may not use this file except in compliance with the License.
|
|
7
|
+
// You may obtain a copy of the License at
|
|
8
|
+
//
|
|
9
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
//
|
|
11
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
// See the License for the specific language governing permissions and
|
|
15
|
+
// limitations under the License.
|
|
16
|
+
const material_1 = require("@mui/material");
|
|
17
|
+
const components_1 = require("@perses-dev/components");
|
|
18
|
+
const react_1 = require("react");
|
|
19
|
+
const context_1 = require("../../context");
|
|
20
|
+
const functions_1 = require("../../utils/functions");
|
|
21
|
+
const AddPanel = ({ isOpen, onClose }) => {
|
|
22
|
+
const { layouts, addItemToLayout } = (0, context_1.useLayouts)();
|
|
23
|
+
const { addPanel } = (0, context_1.usePanels)();
|
|
24
|
+
const [group, setGroup] = (0, react_1.useState)(0);
|
|
25
|
+
const [panelName, setPanelName] = (0, react_1.useState)('');
|
|
26
|
+
const [panelDescription, setPanelDescription] = (0, react_1.useState)('');
|
|
27
|
+
const onSelectGroupChange = (e) => {
|
|
28
|
+
setGroup(e.target.value);
|
|
29
|
+
};
|
|
30
|
+
const onPanelNameChange = (e) => {
|
|
31
|
+
setPanelName(e.target.value);
|
|
32
|
+
};
|
|
33
|
+
const onPanelDescriptionChange = (e) => {
|
|
34
|
+
setPanelDescription(e.target.value);
|
|
35
|
+
};
|
|
36
|
+
const onAddPanelClick = (e) => {
|
|
37
|
+
var _a;
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
const panelKey = (0, functions_1.removeWhiteSpacesAndSpecialCharacters)(panelName);
|
|
40
|
+
addPanel(panelKey, {
|
|
41
|
+
kind: 'EmptyChart',
|
|
42
|
+
display: { name: panelName, description: panelDescription },
|
|
43
|
+
options: {},
|
|
44
|
+
});
|
|
45
|
+
// find maximum y so new panel is added to the end of the grid
|
|
46
|
+
let maxY = 0;
|
|
47
|
+
(_a = layouts[group]) === null || _a === void 0 ? void 0 : _a.spec.items.forEach((layout) => {
|
|
48
|
+
if (layout.y > maxY) {
|
|
49
|
+
maxY = layout.y;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
addItemToLayout(group, {
|
|
53
|
+
x: 0,
|
|
54
|
+
y: maxY + 1,
|
|
55
|
+
width: 12,
|
|
56
|
+
height: 6,
|
|
57
|
+
content: { $ref: `#/spec/panels/${panelKey}` },
|
|
58
|
+
});
|
|
59
|
+
onClose();
|
|
60
|
+
};
|
|
61
|
+
return ((0, jsx_runtime_1.jsx)(components_1.Drawer, { isOpen: isOpen, onClose: onClose, children: (0, jsx_runtime_1.jsxs)("form", { onSubmit: onAddPanelClick, children: [(0, jsx_runtime_1.jsx)(AddPanelHeader, { onClose: onClose }), (0, jsx_runtime_1.jsxs)(material_1.Grid, { container: true, spacing: 2, children: [(0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 4, children: (0, jsx_runtime_1.jsxs)(material_1.FormControl, { children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { id: "select-group", children: "Group" }), (0, jsx_runtime_1.jsx)(material_1.Select, { required: true, labelId: "select-group", label: "Group", value: group, onChange: onSelectGroupChange, children: layouts.map((layout, index) => {
|
|
62
|
+
var _a;
|
|
63
|
+
return ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: index, children: ((_a = layout.spec.display) === null || _a === void 0 ? void 0 : _a.title) || `Group ${index + 1}` }, index));
|
|
64
|
+
}) })] }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 8, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { spacing: 2, sx: { flexGrow: '1' }, children: [(0, jsx_runtime_1.jsx)(material_1.FormControl, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { required: true, label: "Panel Name", variant: "outlined", onChange: onPanelNameChange }) }), (0, jsx_runtime_1.jsx)(material_1.FormControl, { children: (0, jsx_runtime_1.jsx)(material_1.TextField, { label: "Description", variant: "outlined", onChange: onPanelDescriptionChange }) })] }) })] })] }) }));
|
|
65
|
+
};
|
|
66
|
+
const AddPanelHeader = ({ onClose }) => {
|
|
67
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
68
|
+
display: 'flex',
|
|
69
|
+
alignItems: 'center',
|
|
70
|
+
marginBottom: (theme) => theme.spacing(2),
|
|
71
|
+
paddingBottom: (theme) => theme.spacing(2),
|
|
72
|
+
borderBottom: (theme) => `1px solid ${theme.palette.grey[100]}`,
|
|
73
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h5", children: "Add Panel" }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1, sx: { marginLeft: 'auto' }, children: [(0, jsx_runtime_1.jsx)(material_1.Button, { type: "submit", variant: "contained", children: "Add Panel" }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", onClick: onClose, children: "Cancel" })] })] }));
|
|
74
|
+
};
|
|
75
|
+
exports.default = AddPanel;
|
|
@@ -0,0 +1,52 @@
|
|
|
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.DashboardToolbar = 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 PencilOutline_1 = __importDefault(require("mdi-material-ui/PencilOutline"));
|
|
22
|
+
const Plus_1 = __importDefault(require("mdi-material-ui/Plus"));
|
|
23
|
+
const context_1 = require("../context");
|
|
24
|
+
const components_1 = require("../components");
|
|
25
|
+
const DashboardToolbar = (props) => {
|
|
26
|
+
const { dashboardName, onAddPanel } = props;
|
|
27
|
+
const { isEditMode, setEditMode } = (0, context_1.useEditMode)();
|
|
28
|
+
const onEditButtonClick = () => {
|
|
29
|
+
setEditMode(true);
|
|
30
|
+
};
|
|
31
|
+
const onCancelButtonClick = () => {
|
|
32
|
+
setEditMode(false);
|
|
33
|
+
};
|
|
34
|
+
const { addLayout } = (0, context_1.useLayouts)();
|
|
35
|
+
const onAddGroup = () => {
|
|
36
|
+
const newLayout = {
|
|
37
|
+
kind: 'Grid',
|
|
38
|
+
spec: {
|
|
39
|
+
display: {
|
|
40
|
+
title: 'New Group',
|
|
41
|
+
collapse: {
|
|
42
|
+
open: true,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
items: [],
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
addLayout(newLayout);
|
|
49
|
+
};
|
|
50
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Toolbar, { disableGutters: true, sx: { display: 'block', padding: (theme) => theme.spacing(2, 0) }, children: isEditMode ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: 'flex', width: '100%' }, children: [(0, jsx_runtime_1.jsxs)(material_1.Typography, { variant: "h2", children: ["Edit ", dashboardName] }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1, sx: { marginLeft: 'auto' }, children: [(0, jsx_runtime_1.jsx)(components_1.TimeRangeControls, {}), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined", onClick: onCancelButtonClick, children: "Cancel" }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", children: "Save" })] })] }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: 'row', spacing: 1, sx: { display: 'flex', justifyContent: 'flex-end', width: '100%', padding: (theme) => theme.spacing(2, 0) }, children: [(0, jsx_runtime_1.jsx)(material_1.Button, { startIcon: (0, jsx_runtime_1.jsx)(Plus_1.default, {}), onClick: onAddGroup, children: "Add Group" }), (0, jsx_runtime_1.jsx)(material_1.Button, { startIcon: (0, jsx_runtime_1.jsx)(Plus_1.default, {}), onClick: onAddPanel, children: "Add Panel" })] })] })) : ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: 'flex', width: '100%' }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "h2", children: dashboardName }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 2, sx: { marginLeft: 'auto' }, children: [(0, jsx_runtime_1.jsx)(components_1.TimeRangeControls, {}), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", startIcon: (0, jsx_runtime_1.jsx)(PencilOutline_1.default, {}), onClick: onEditButtonClick, sx: { marginLeft: 'auto' }, children: "Edit" })] })] })) }));
|
|
51
|
+
};
|
|
52
|
+
exports.DashboardToolbar = DashboardToolbar;
|
|
@@ -14,10 +14,14 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
14
14
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
15
|
// See the License for the specific language governing permissions and
|
|
16
16
|
// limitations under the License.
|
|
17
|
+
require("react-grid-layout/css/styles.css");
|
|
18
|
+
require("react-resizable/css/styles.css");
|
|
17
19
|
const react_1 = require("react");
|
|
20
|
+
const react_grid_layout_1 = require("react-grid-layout");
|
|
18
21
|
const material_1 = require("@mui/material");
|
|
22
|
+
const context_1 = require("../../context");
|
|
19
23
|
const GridTitle_1 = require("./GridTitle");
|
|
20
|
-
const
|
|
24
|
+
const ResponsiveGridLayout = (0, react_grid_layout_1.WidthProvider)(react_grid_layout_1.Responsive);
|
|
21
25
|
/**
|
|
22
26
|
* Layout component that arranges children in a Grid based on the definition.
|
|
23
27
|
*/
|
|
@@ -25,35 +29,14 @@ function GridLayout(props) {
|
|
|
25
29
|
var _a, _b, _c;
|
|
26
30
|
const { definition: { spec }, renderGridItemContent, ...others } = props;
|
|
27
31
|
const [isOpen, setIsOpen] = (0, react_1.useState)((_c = (_b = (_a = spec.display) === null || _a === void 0 ? void 0 : _a.collapse) === null || _b === void 0 ? void 0 : _b.open) !== null && _c !== void 0 ? _c : true);
|
|
32
|
+
const { isEditMode } = (0, context_1.useEditMode)();
|
|
28
33
|
const gridItems = [];
|
|
29
|
-
let mobileRowStart = 1;
|
|
30
34
|
spec.items.forEach((item, idx) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const mobileRows = Math.floor(item.height * widthScale);
|
|
34
|
-
gridItems.push((0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
|
|
35
|
-
gridColumn: {
|
|
36
|
-
xs: `1 / span ${COLUMNS}`,
|
|
37
|
-
sm: `${item.x + 1} / span ${item.width}`,
|
|
38
|
-
},
|
|
39
|
-
gridRow: {
|
|
40
|
-
xs: `${mobileRowStart} / span ${mobileRows}`,
|
|
41
|
-
sm: `${item.y + 1} / span ${item.height}`,
|
|
42
|
-
},
|
|
43
|
-
}, children: renderGridItemContent(item) }, idx));
|
|
44
|
-
mobileRowStart += mobileRows;
|
|
35
|
+
const { x, y, width: w, height: h } = item;
|
|
36
|
+
gridItems.push((0, jsx_runtime_1.jsx)("div", { "data-grid": { x, y, w, h }, children: renderGridItemContent(item) }, idx));
|
|
45
37
|
});
|
|
46
38
|
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { ...others, component: "section", sx: { '& + &': { marginTop: (theme) => theme.spacing(1) } }, children: [spec.display !== undefined && ((0, jsx_runtime_1.jsx)(GridTitle_1.GridTitle, { title: spec.display.title, collapse: spec.display.collapse === undefined
|
|
47
39
|
? undefined
|
|
48
|
-
: { isOpen, onToggleOpen: () => setIsOpen((current) => !current) } })), (0, jsx_runtime_1.jsx)(material_1.Collapse, { in: isOpen, unmountOnExit: true, children: (0, jsx_runtime_1.jsx)(
|
|
49
|
-
display: 'grid',
|
|
50
|
-
gridTemplateColumns: `repeat(${COLUMNS}, 1fr)`,
|
|
51
|
-
gridAutoRows: {
|
|
52
|
-
xs: 24,
|
|
53
|
-
sm: 36,
|
|
54
|
-
},
|
|
55
|
-
columnGap: (theme) => theme.spacing(1),
|
|
56
|
-
rowGap: (theme) => theme.spacing(1),
|
|
57
|
-
}, children: gridItems }) })] }));
|
|
40
|
+
: { isOpen, onToggleOpen: () => setIsOpen((current) => !current) } })), (0, jsx_runtime_1.jsx)(material_1.Collapse, { in: isOpen, unmountOnExit: true, children: (0, jsx_runtime_1.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: isEditMode, isResizable: isEditMode, children: gridItems }) })] }));
|
|
58
41
|
}
|
|
59
42
|
exports.GridLayout = GridLayout;
|
|
@@ -24,6 +24,10 @@ const plugin_system_1 = require("@perses-dev/plugin-system");
|
|
|
24
24
|
const components_1 = require("@perses-dev/components");
|
|
25
25
|
const material_1 = require("@mui/material");
|
|
26
26
|
const InformationOutline_1 = __importDefault(require("mdi-material-ui/InformationOutline"));
|
|
27
|
+
const Pencil_1 = __importDefault(require("mdi-material-ui/Pencil"));
|
|
28
|
+
const DotsVertical_1 = __importDefault(require("mdi-material-ui/DotsVertical"));
|
|
29
|
+
const Drag_1 = __importDefault(require("mdi-material-ui/Drag"));
|
|
30
|
+
const context_1 = require("../../context");
|
|
27
31
|
/**
|
|
28
32
|
* Renders a PanelDefinition's content inside of a Card.
|
|
29
33
|
*/
|
|
@@ -43,6 +47,7 @@ function Panel(props) {
|
|
|
43
47
|
});
|
|
44
48
|
// TODO: adjust padding for small panels, consistent way to determine isLargePanel here and in StatChart
|
|
45
49
|
const panelPadding = 1.5;
|
|
50
|
+
const { isEditMode } = (0, context_1.useEditMode)();
|
|
46
51
|
return ((0, jsx_runtime_1.jsxs)(material_1.Card, { ref: ref, sx: {
|
|
47
52
|
...others.sx,
|
|
48
53
|
width: '100%',
|
|
@@ -52,7 +57,12 @@ function Panel(props) {
|
|
|
52
57
|
}, variant: "outlined", ...others, children: [(0, jsx_runtime_1.jsx)(material_1.CardHeader, { title: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
53
58
|
display: 'flex',
|
|
54
59
|
alignItems: 'center',
|
|
55
|
-
|
|
60
|
+
minHeight: '24px',
|
|
61
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h2", variant: "body2", fontWeight: (theme) => theme.typography.fontWeightMedium, whiteSpace: "nowrap", overflow: "hidden", textOverflow: "ellipsis", children: definition.display.name }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
62
|
+
display: 'flex',
|
|
63
|
+
alignItems: 'center',
|
|
64
|
+
marginLeft: 'auto',
|
|
65
|
+
}, children: [!isEditMode && definition.display.description && ((0, jsx_runtime_1.jsx)(components_1.InfoTooltip, { id: "info-tooltip", description: definition.display.description, placement: components_1.TooltipPlacement.Bottom, children: (0, jsx_runtime_1.jsx)(InformationOutline_1.default, { "aria-describedby": "info-tooltip", "aria-hidden": false, fontSize: "small", sx: { cursor: 'pointer' } }) })), isEditMode && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", alignItems: "center", spacing: 0.5, children: [(0, jsx_runtime_1.jsx)(IconButton, { "aria-label": "drag handle", size: "small", children: (0, jsx_runtime_1.jsx)(Drag_1.default, { className: "drag-handle", sx: { cursor: 'grab' } }) }), (0, jsx_runtime_1.jsx)(IconButton, { "aria-label": "edit panel", size: "small", children: (0, jsx_runtime_1.jsx)(Pencil_1.default, {}) }), (0, jsx_runtime_1.jsx)(IconButton, { "aria-label": "more", size: "small", children: (0, jsx_runtime_1.jsx)(DotsVertical_1.default, {}) })] }))] })] }), sx: {
|
|
56
66
|
display: 'block',
|
|
57
67
|
padding: (theme) => theme.spacing(1, panelPadding),
|
|
58
68
|
borderBottom: (theme) => `solid 1px ${theme.palette.divider}`,
|
|
@@ -68,3 +78,7 @@ function Panel(props) {
|
|
|
68
78
|
}, ref: setContentElement, children: (0, jsx_runtime_1.jsx)(plugin_system_1.PluginBoundary, { loadingFallback: "Loading...", ErrorFallbackComponent: components_1.ErrorAlert, children: inView === true && (0, jsx_runtime_1.jsx)(plugin_system_1.PanelComponent, { definition: definition, contentDimensions: contentDimensions }) }) })] }));
|
|
69
79
|
}
|
|
70
80
|
exports.Panel = Panel;
|
|
81
|
+
const IconButton = (0, material_1.styled)(material_1.IconButton)(({ theme }) => ({
|
|
82
|
+
borderRadius: theme.shape.borderRadius,
|
|
83
|
+
padding: '4px',
|
|
84
|
+
}));
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
7
|
const plugin_system_1 = require("@perses-dev/plugin-system");
|
|
5
8
|
require("intersection-observer");
|
|
6
9
|
const react_1 = require("@testing-library/react");
|
|
7
10
|
const test_1 = require("../../test");
|
|
11
|
+
const testDashboard_1 = __importDefault(require("../../test/testDashboard"));
|
|
12
|
+
const context_1 = require("../../context");
|
|
8
13
|
const Panel_1 = require("./Panel");
|
|
9
14
|
const FAKE_PANEL_PLUGIN = {
|
|
10
15
|
pluginType: 'Panel',
|
|
@@ -17,6 +22,7 @@ const FAKE_PANEL_PLUGIN = {
|
|
|
17
22
|
};
|
|
18
23
|
describe('Panel', () => {
|
|
19
24
|
let props;
|
|
25
|
+
let initialState;
|
|
20
26
|
beforeEach(() => {
|
|
21
27
|
props = {
|
|
22
28
|
definition: {
|
|
@@ -28,16 +34,27 @@ describe('Panel', () => {
|
|
|
28
34
|
options: {},
|
|
29
35
|
},
|
|
30
36
|
};
|
|
37
|
+
initialState = {
|
|
38
|
+
isEditMode: false,
|
|
39
|
+
dashboardSpec: testDashboard_1.default.spec,
|
|
40
|
+
};
|
|
31
41
|
});
|
|
32
42
|
// Helper to render the panel with some context set
|
|
33
|
-
const renderPanel = () => {
|
|
43
|
+
const renderPanel = (initialState) => {
|
|
34
44
|
const { addMockPlugin, pluginRegistryProps } = (0, test_1.mockPluginRegistryProps)();
|
|
35
45
|
addMockPlugin(FAKE_PANEL_PLUGIN);
|
|
36
|
-
(0, test_1.renderWithContext)((0, jsx_runtime_1.jsx)(plugin_system_1.PluginRegistry, { ...pluginRegistryProps, children: (0, jsx_runtime_1.jsx)(Panel_1.Panel, { ...props }) }));
|
|
46
|
+
(0, test_1.renderWithContext)((0, jsx_runtime_1.jsx)(context_1.DashboardProvider, { initialState: initialState, children: (0, jsx_runtime_1.jsx)(plugin_system_1.PluginRegistry, { ...pluginRegistryProps, children: (0, jsx_runtime_1.jsx)(Panel_1.Panel, { ...props }) }) }));
|
|
37
47
|
};
|
|
38
48
|
it('should render name and info icon', async () => {
|
|
39
|
-
renderPanel();
|
|
49
|
+
renderPanel(initialState);
|
|
40
50
|
await react_1.screen.findByText('Fake Panel');
|
|
41
51
|
react_1.screen.queryByLabelText('info-tooltip');
|
|
42
52
|
});
|
|
53
|
+
it('should render edit icons when in edit mode', async () => {
|
|
54
|
+
initialState.isEditMode = true;
|
|
55
|
+
renderPanel(initialState);
|
|
56
|
+
await react_1.screen.queryByLabelText('drag handle');
|
|
57
|
+
react_1.screen.queryByLabelText('edit panel');
|
|
58
|
+
react_1.screen.queryByLabelText('more');
|
|
59
|
+
});
|
|
43
60
|
});
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TimeRangeControls = exports.TIME_OPTIONS = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
// Copyright 2022 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 react_1 = require("react");
|
|
18
|
+
const material_1 = require("@mui/material");
|
|
19
|
+
const date_fns_1 = require("date-fns");
|
|
20
|
+
const components_1 = require("@perses-dev/components");
|
|
21
|
+
const core_1 = require("@perses-dev/core");
|
|
22
|
+
const plugin_system_1 = require("@perses-dev/plugin-system");
|
|
23
|
+
const TimeRangeStateProvider_1 = require("../context/TimeRangeStateProvider");
|
|
24
|
+
// TODO: add time shortcut if one does not match duration
|
|
25
|
+
exports.TIME_OPTIONS = [
|
|
26
|
+
{ value: { pastDuration: '5m' }, display: 'Last 5 minutes' },
|
|
27
|
+
{ value: { pastDuration: '15m' }, display: 'Last 15 minutes' },
|
|
28
|
+
{ value: { pastDuration: '30m' }, display: 'Last 30 minutes' },
|
|
29
|
+
{ value: { pastDuration: '1h' }, display: 'Last 1 hour' },
|
|
30
|
+
{ value: { pastDuration: '6h' }, display: 'Last 6 hours' },
|
|
31
|
+
{ value: { pastDuration: '12h' }, display: 'Last 12 hours' },
|
|
32
|
+
{ value: { pastDuration: '24h' }, display: 'Last 1 day' },
|
|
33
|
+
{ value: { pastDuration: '7d' }, display: 'Last 7 days' },
|
|
34
|
+
{ value: { pastDuration: '14d' }, display: 'Last 14 days' },
|
|
35
|
+
];
|
|
36
|
+
const FORM_CONTROL_LABEL = 'Time Range';
|
|
37
|
+
function TimeRangeControls() {
|
|
38
|
+
const { setTimeRange } = (0, TimeRangeStateProvider_1.useTimeRangeSetter)();
|
|
39
|
+
const { defaultDuration } = (0, plugin_system_1.useTimeRange)();
|
|
40
|
+
const defaultStart = (0, core_1.parseDurationString)(defaultDuration);
|
|
41
|
+
// TODO: default to URL param if populated
|
|
42
|
+
const [selectedTimeRange, setSelectedTimeRange] = (0, react_1.useState)({ pastDuration: defaultDuration });
|
|
43
|
+
const [absoluteTimeRange, setAbsoluteTime] = (0, react_1.useState)({
|
|
44
|
+
start: (0, date_fns_1.sub)(new Date(), { ...defaultStart }),
|
|
45
|
+
end: new Date(),
|
|
46
|
+
});
|
|
47
|
+
const [showCustomDateSelector, setShowCustomDateSelector] = (0, react_1.useState)(false);
|
|
48
|
+
const anchorEl = (0, react_1.useRef)();
|
|
49
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", spacing: 1, children: [(0, jsx_runtime_1.jsx)(material_1.Popover, { anchorEl: anchorEl.current, anchorOrigin: {
|
|
50
|
+
vertical: 'bottom',
|
|
51
|
+
horizontal: 'center',
|
|
52
|
+
}, open: showCustomDateSelector, onClose: () => setShowCustomDateSelector(false), sx: (theme) => ({
|
|
53
|
+
padding: theme.spacing(2),
|
|
54
|
+
}), children: (0, jsx_runtime_1.jsx)(components_1.AbsoluteTimePicker, { initialTimeRange: absoluteTimeRange, onChange: (timeRange) => {
|
|
55
|
+
setTimeRange(timeRange);
|
|
56
|
+
if (!(0, core_1.isRelativeValue)(timeRange)) {
|
|
57
|
+
setAbsoluteTime({ start: timeRange.start, end: timeRange.end });
|
|
58
|
+
}
|
|
59
|
+
setSelectedTimeRange(timeRange);
|
|
60
|
+
setShowCustomDateSelector(false);
|
|
61
|
+
} }) }), (0, jsx_runtime_1.jsxs)(material_1.FormControl, { fullWidth: true, children: [(0, jsx_runtime_1.jsx)(material_1.InputLabel, { children: FORM_CONTROL_LABEL }), (0, jsx_runtime_1.jsx)(material_1.Box, { ref: anchorEl, children: (0, jsx_runtime_1.jsx)(components_1.TimeRangeSelector, { inputLabel: FORM_CONTROL_LABEL, timeOptions: exports.TIME_OPTIONS, value: selectedTimeRange, onSelectChange: (event) => {
|
|
62
|
+
const duration = event.target.value;
|
|
63
|
+
const relativeTimeInput = {
|
|
64
|
+
pastDuration: duration,
|
|
65
|
+
end: new Date(),
|
|
66
|
+
};
|
|
67
|
+
// TODO: consolidate unnecessary state
|
|
68
|
+
setSelectedTimeRange(relativeTimeInput);
|
|
69
|
+
const convertedAbsoluteTime = (0, core_1.toAbsoluteTimeRange)(relativeTimeInput);
|
|
70
|
+
setTimeRange(convertedAbsoluteTime);
|
|
71
|
+
setAbsoluteTime(convertedAbsoluteTime);
|
|
72
|
+
setShowCustomDateSelector(false);
|
|
73
|
+
}, onCustomClick: () => {
|
|
74
|
+
setShowCustomDateSelector(true);
|
|
75
|
+
} }) })] })] }));
|
|
76
|
+
}
|
|
77
|
+
exports.TimeRangeControls = TimeRangeControls;
|
|
@@ -29,5 +29,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
__exportStar(require("./Dashboard"), exports);
|
|
30
30
|
__exportStar(require("./GridLayout"), exports);
|
|
31
31
|
__exportStar(require("./Panel/Panel"), exports);
|
|
32
|
+
__exportStar(require("./TimeRangeControls"), exports);
|
|
32
33
|
__exportStar(require("./VariableAutocomplete"), exports);
|
|
33
34
|
__exportStar(require("./VariableList"), exports);
|
|
@@ -0,0 +1,80 @@
|
|
|
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.DashboardProvider = exports.useDashboard = exports.useEditMode = exports.useLayouts = exports.usePanels = 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 zustand_1 = __importDefault(require("zustand"));
|
|
21
|
+
const context_1 = __importDefault(require("zustand/context"));
|
|
22
|
+
const immer_1 = __importDefault(require("immer"));
|
|
23
|
+
const { Provider, useStore } = (0, context_1.default)();
|
|
24
|
+
function usePanels() {
|
|
25
|
+
const { panels, addPanel } = useStore(({ panels, addPanel }) => ({ panels, addPanel }));
|
|
26
|
+
return { panels, addPanel };
|
|
27
|
+
}
|
|
28
|
+
exports.usePanels = usePanels;
|
|
29
|
+
function useLayouts() {
|
|
30
|
+
const { layouts, setLayouts, addLayout, addItemToLayout } = useStore(({ layouts, setLayouts, addLayout, addItemToLayout }) => ({
|
|
31
|
+
layouts,
|
|
32
|
+
setLayouts,
|
|
33
|
+
addLayout,
|
|
34
|
+
addItemToLayout,
|
|
35
|
+
}));
|
|
36
|
+
return { layouts, setLayouts, addLayout, addItemToLayout };
|
|
37
|
+
}
|
|
38
|
+
exports.useLayouts = useLayouts;
|
|
39
|
+
function useEditMode() {
|
|
40
|
+
const { isEditMode, setEditMode } = useStore(({ isEditMode, setEditMode }) => ({ isEditMode, setEditMode }));
|
|
41
|
+
return { isEditMode, setEditMode };
|
|
42
|
+
}
|
|
43
|
+
exports.useEditMode = useEditMode;
|
|
44
|
+
function useDashboard() {
|
|
45
|
+
const selectDashboardSpec = (state) => {
|
|
46
|
+
return (0, immer_1.default)(state.dashboard, (draftState) => {
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
48
|
+
draftState.panels = state.panels;
|
|
49
|
+
draftState.layouts = state.layouts;
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const dashboard = useStore(selectDashboardSpec);
|
|
53
|
+
return { dashboard };
|
|
54
|
+
}
|
|
55
|
+
exports.useDashboard = useDashboard;
|
|
56
|
+
function DashboardProvider(props) {
|
|
57
|
+
const { children, initialState: { dashboardSpec, isEditMode }, } = props;
|
|
58
|
+
const { layouts, panels } = dashboardSpec;
|
|
59
|
+
return ((0, jsx_runtime_1.jsx)(Provider, { createStore: () => (0, zustand_1.default)((set) => ({
|
|
60
|
+
layouts,
|
|
61
|
+
panels,
|
|
62
|
+
dashboard: dashboardSpec,
|
|
63
|
+
isEditMode: !!isEditMode,
|
|
64
|
+
setEditMode: (isEditMode) => set({ isEditMode }),
|
|
65
|
+
setLayouts: (layouts) => set({ layouts }),
|
|
66
|
+
addLayout: (layout) => set((0, immer_1.default)((state) => {
|
|
67
|
+
state.layouts.push(layout);
|
|
68
|
+
})),
|
|
69
|
+
addItemToLayout: (index, item) => set((0, immer_1.default)((state) => {
|
|
70
|
+
state.layouts[index].spec.items.push(item);
|
|
71
|
+
})),
|
|
72
|
+
setPanels: (panels) => set({ panels }),
|
|
73
|
+
addPanel: (name, panel) => {
|
|
74
|
+
set((0, immer_1.default)((state) => {
|
|
75
|
+
state.panels[name] = panel;
|
|
76
|
+
}, {}));
|
|
77
|
+
},
|
|
78
|
+
})), children: children }));
|
|
79
|
+
}
|
|
80
|
+
exports.DashboardProvider = DashboardProvider;
|
|
@@ -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);
|