@perses-dev/dashboards 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Dashboard.js +29 -14
- package/dist/cjs/components/DashboardToolbar.js +148 -20
- package/dist/cjs/components/GridLayout/GridItemContent.js +24 -18
- package/dist/cjs/components/GridLayout/GridLayout.js +88 -26
- package/dist/cjs/components/GridLayout/GridTitle.js +69 -31
- package/dist/cjs/components/GridLayout/index.js +18 -19
- package/dist/cjs/components/Panel/Panel.js +145 -55
- package/dist/cjs/components/Panel/Panel.test.js +50 -41
- package/dist/cjs/components/Panel/PanelContent.js +40 -12
- package/dist/cjs/components/Panel/index.js +16 -17
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +82 -107
- package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +91 -92
- package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +152 -0
- package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +40 -0
- package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +38 -0
- package/dist/cjs/components/PanelDrawer/index.js +28 -0
- package/dist/cjs/components/PanelDrawer/panel-editor-model.js +140 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +120 -31
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +90 -83
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +120 -38
- package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +42 -27
- package/dist/cjs/components/TimeRangeControls/index.js +16 -17
- package/dist/cjs/components/Variables/Variable.js +186 -35
- package/dist/cjs/components/Variables/VariableList.js +100 -13
- package/dist/cjs/components/Variables/index.js +17 -18
- package/dist/cjs/components/index.js +21 -21
- package/dist/cjs/context/DashboardAppSlice.js +43 -31
- package/dist/cjs/context/DashboardProvider.js +88 -58
- package/dist/cjs/context/DatasourceStoreProvider.js +68 -0
- package/dist/cjs/context/LayoutsSlice.js +40 -27
- package/dist/cjs/context/QueryStringProvider.js +69 -15
- package/dist/cjs/context/TemplateVariableProvider.js +128 -136
- package/dist/cjs/context/TimeRangeProvider.js +79 -30
- package/dist/cjs/context/index.js +22 -22
- package/dist/cjs/css/styles.js +43 -39
- package/dist/cjs/index.js +19 -20
- package/dist/cjs/test/dashboard-provider.js +51 -0
- package/dist/cjs/test/index.js +18 -18
- package/dist/cjs/test/plugin-registry.js +52 -25
- package/dist/cjs/test/render.js +25 -22
- package/dist/cjs/test/setup-tests.js +4 -2
- package/dist/cjs/test/testDashboard.js +193 -109
- package/dist/cjs/utils/functions.js +9 -5
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +67 -0
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +83 -0
- package/dist/cjs/views/ViewDashboard/index.js +28 -0
- package/dist/cjs/views/index.js +16 -17
- package/dist/components/Dashboard.js +38 -1
- package/dist/components/Dashboard.js.map +1 -0
- package/dist/components/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar.js +154 -1
- package/dist/components/DashboardToolbar.js.map +1 -0
- package/dist/components/GridLayout/GridItemContent.js +35 -1
- package/dist/components/GridLayout/GridItemContent.js.map +1 -0
- package/dist/components/GridLayout/GridLayout.js +99 -1
- package/dist/components/GridLayout/GridLayout.js.map +1 -0
- package/dist/components/GridLayout/GridTitle.js +77 -1
- package/dist/components/GridLayout/GridTitle.js.map +1 -0
- package/dist/components/GridLayout/index.js +16 -1
- package/dist/components/GridLayout/index.js.map +1 -0
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +170 -1
- package/dist/components/Panel/Panel.js.map +1 -0
- package/dist/components/Panel/Panel.test.js +71 -1
- package/dist/components/Panel/Panel.test.js.map +1 -0
- package/dist/components/Panel/PanelContent.d.ts +2 -4
- package/dist/components/Panel/PanelContent.d.ts.map +1 -1
- package/dist/components/Panel/PanelContent.js +40 -1
- package/dist/components/Panel/PanelContent.js.map +1 -0
- package/dist/components/Panel/index.js +15 -1
- package/dist/components/Panel/index.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +95 -1
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
- package/dist/components/PanelDrawer/PanelDrawer.test.js +103 -1
- package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
- package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelEditorForm.js +142 -0
- package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +7 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.js +34 -0
- package/dist/components/PanelDrawer/PanelSpecEditor.js.map +1 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +8 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +1 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.js +34 -0
- package/dist/components/PanelDrawer/PanelTypeSelect.js.map +1 -0
- package/dist/components/PanelDrawer/index.d.ts +2 -0
- package/dist/components/PanelDrawer/index.d.ts.map +1 -0
- package/dist/components/PanelDrawer/index.js +15 -0
- package/dist/components/PanelDrawer/index.js.map +1 -0
- package/dist/components/PanelDrawer/panel-editor-model.d.ts +27 -0
- package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +1 -0
- package/dist/components/PanelDrawer/panel-editor-model.js +133 -0
- package/dist/components/PanelDrawer/panel-editor-model.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +138 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
- package/dist/components/TimeRangeControls/index.js +15 -1
- package/dist/components/TimeRangeControls/index.js.map +1 -0
- package/dist/components/Variables/Variable.d.ts.map +1 -1
- package/dist/components/Variables/Variable.js +202 -1
- package/dist/components/Variables/Variable.js.map +1 -0
- package/dist/components/Variables/VariableList.js +108 -1
- package/dist/components/Variables/VariableList.js.map +1 -0
- package/dist/components/Variables/index.js +16 -1
- package/dist/components/Variables/index.js.map +1 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +20 -1
- package/dist/components/index.js.map +1 -0
- package/dist/context/DashboardAppSlice.js +45 -1
- package/dist/context/DashboardAppSlice.js.map +1 -0
- package/dist/context/DashboardProvider.d.ts +4 -2
- package/dist/context/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider.js +107 -1
- package/dist/context/DashboardProvider.js.map +1 -0
- package/dist/context/DatasourceStoreProvider.d.ts +16 -0
- package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
- package/dist/context/DatasourceStoreProvider.js +64 -0
- package/dist/context/DatasourceStoreProvider.js.map +1 -0
- package/dist/context/LayoutsSlice.js +43 -1
- package/dist/context/LayoutsSlice.js.map +1 -0
- package/dist/context/QueryStringProvider.js +40 -1
- package/dist/context/QueryStringProvider.js.map +1 -0
- package/dist/context/TemplateVariableProvider.d.ts +6 -3
- package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
- package/dist/context/TemplateVariableProvider.js +192 -1
- package/dist/context/TemplateVariableProvider.js.map +1 -0
- package/dist/context/TimeRangeProvider.js +72 -1
- package/dist/context/TimeRangeProvider.js.map +1 -0
- package/dist/context/index.d.ts +3 -2
- package/dist/context/index.d.ts.map +1 -1
- package/dist/context/index.js +21 -1
- package/dist/context/index.js.map +1 -0
- package/dist/css/styles.js +186 -1
- package/dist/css/styles.js.map +1 -0
- package/dist/index.js +17 -1
- package/dist/index.js.map +1 -0
- package/dist/test/dashboard-provider.d.ts +19 -0
- package/dist/test/dashboard-provider.d.ts.map +1 -0
- package/dist/test/dashboard-provider.js +40 -0
- package/dist/test/dashboard-provider.js.map +1 -0
- package/dist/test/index.d.ts +1 -0
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +17 -1
- package/dist/test/index.js.map +1 -0
- package/dist/test/plugin-registry.d.ts +2 -3
- package/dist/test/plugin-registry.d.ts.map +1 -1
- package/dist/test/plugin-registry.js +74 -1
- package/dist/test/plugin-registry.js.map +1 -0
- package/dist/test/render.d.ts +1 -2
- package/dist/test/render.d.ts.map +1 -1
- package/dist/test/render.js +34 -1
- package/dist/test/render.js.map +1 -0
- package/dist/test/setup-tests.js +18 -1
- package/dist/test/setup-tests.js.map +1 -0
- package/dist/test/testDashboard.d.ts.map +1 -1
- package/dist/test/testDashboard.js +274 -1
- package/dist/test/testDashboard.js.map +1 -0
- package/dist/utils/functions.js +17 -1
- package/dist/utils/functions.js.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -0
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -0
- package/dist/views/ViewDashboard/DashboardApp.js +56 -0
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
- package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +3 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
- package/dist/views/ViewDashboard/ViewDashboard.js +79 -0
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
- package/dist/views/ViewDashboard/index.d.ts +2 -0
- package/dist/views/ViewDashboard/index.d.ts.map +1 -0
- package/dist/views/ViewDashboard/index.js +15 -0
- package/dist/views/ViewDashboard/index.js.map +1 -0
- package/dist/views/index.js +15 -1
- package/dist/views/index.js.map +1 -0
- package/package.json +13 -7
- package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
- package/dist/cjs/views/DashboardApp.js +0 -46
- package/dist/cjs/views/ViewDashboard.js +0 -43
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
- package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
- package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
- package/dist/views/DashboardApp.d.ts +0 -4
- package/dist/views/DashboardApp.d.ts.map +0 -1
- package/dist/views/DashboardApp.js +0 -1
- package/dist/views/ViewDashboard.d.ts.map +0 -1
- package/dist/views/ViewDashboard.js +0 -1
|
@@ -1 +1,170 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { useState, useMemo } from 'react';
|
|
15
|
+
import useResizeObserver from 'use-resize-observer';
|
|
16
|
+
import { useInView } from 'react-intersection-observer';
|
|
17
|
+
import { ErrorBoundary, ErrorAlert, InfoTooltip, TooltipPlacement } from '@perses-dev/components';
|
|
18
|
+
import { Box, Card, CardHeader, CardContent, Typography, IconButton as MuiIconButton, Stack, styled } from '@mui/material';
|
|
19
|
+
import InformationOutlineIcon from 'mdi-material-ui/InformationOutline';
|
|
20
|
+
import PencilIcon from 'mdi-material-ui/Pencil';
|
|
21
|
+
import DragIcon from 'mdi-material-ui/DragVertical';
|
|
22
|
+
import { useDashboardApp, useEditMode } from '../../context';
|
|
23
|
+
import { PanelContent } from './PanelContent';
|
|
24
|
+
/**
|
|
25
|
+
* Renders a PanelDefinition's content inside of a Card.
|
|
26
|
+
*/ export function Panel(props) {
|
|
27
|
+
const { definition , groupIndex , panelKey , ...others } = props;
|
|
28
|
+
const [contentElement, setContentElement] = useState(null);
|
|
29
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
30
|
+
const { width , height } = useResizeObserver({
|
|
31
|
+
ref: contentElement
|
|
32
|
+
});
|
|
33
|
+
const contentDimensions = useMemo(()=>{
|
|
34
|
+
if (width === undefined || height === undefined) return undefined;
|
|
35
|
+
return {
|
|
36
|
+
width,
|
|
37
|
+
height
|
|
38
|
+
};
|
|
39
|
+
}, [
|
|
40
|
+
width,
|
|
41
|
+
height
|
|
42
|
+
]);
|
|
43
|
+
const { ref , inView } = useInView({
|
|
44
|
+
threshold: 0.3,
|
|
45
|
+
initialInView: false,
|
|
46
|
+
triggerOnce: true
|
|
47
|
+
});
|
|
48
|
+
// TODO: adjust padding for small panels, consistent way to determine isLargePanel here and in StatChart
|
|
49
|
+
const panelPadding = 1.5;
|
|
50
|
+
const { isEditMode } = useEditMode();
|
|
51
|
+
const { openPanelDrawer } = useDashboardApp();
|
|
52
|
+
const handleEditButtonClick = ()=>{
|
|
53
|
+
openPanelDrawer({
|
|
54
|
+
groupIndex,
|
|
55
|
+
panelKey
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
return /*#__PURE__*/ _jsxs(Card, {
|
|
59
|
+
ref: ref,
|
|
60
|
+
sx: {
|
|
61
|
+
...others.sx,
|
|
62
|
+
width: '100%',
|
|
63
|
+
height: '100%',
|
|
64
|
+
display: 'flex',
|
|
65
|
+
flexFlow: 'column nowrap'
|
|
66
|
+
},
|
|
67
|
+
variant: "outlined",
|
|
68
|
+
...others,
|
|
69
|
+
onMouseEnter: ()=>setIsHovered(true),
|
|
70
|
+
onMouseLeave: ()=>setIsHovered(false),
|
|
71
|
+
children: [
|
|
72
|
+
/*#__PURE__*/ _jsx(CardHeader, {
|
|
73
|
+
title: /*#__PURE__*/ _jsxs(Box, {
|
|
74
|
+
sx: {
|
|
75
|
+
display: 'flex',
|
|
76
|
+
alignItems: 'center',
|
|
77
|
+
minHeight: '24px'
|
|
78
|
+
},
|
|
79
|
+
children: [
|
|
80
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
81
|
+
component: "h2",
|
|
82
|
+
variant: "body2",
|
|
83
|
+
fontWeight: (theme)=>theme.typography.fontWeightMedium,
|
|
84
|
+
whiteSpace: "nowrap",
|
|
85
|
+
overflow: "hidden",
|
|
86
|
+
textOverflow: "ellipsis",
|
|
87
|
+
children: definition.spec.display.name
|
|
88
|
+
}),
|
|
89
|
+
/*#__PURE__*/ _jsxs(Box, {
|
|
90
|
+
sx: {
|
|
91
|
+
display: 'flex',
|
|
92
|
+
alignItems: 'center',
|
|
93
|
+
marginLeft: 'auto'
|
|
94
|
+
},
|
|
95
|
+
children: [
|
|
96
|
+
!isEditMode && isHovered && definition.spec.display.description && /*#__PURE__*/ _jsx(InfoTooltip, {
|
|
97
|
+
id: "info-tooltip",
|
|
98
|
+
description: definition.spec.display.description,
|
|
99
|
+
placement: TooltipPlacement.Bottom,
|
|
100
|
+
children: /*#__PURE__*/ _jsx(InformationOutlineIcon, {
|
|
101
|
+
"aria-describedby": "info-tooltip",
|
|
102
|
+
"aria-hidden": false,
|
|
103
|
+
fontSize: "small",
|
|
104
|
+
sx: {
|
|
105
|
+
cursor: 'pointer'
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
}),
|
|
109
|
+
isEditMode && isHovered && /*#__PURE__*/ _jsxs(Stack, {
|
|
110
|
+
direction: "row",
|
|
111
|
+
alignItems: "center",
|
|
112
|
+
spacing: 0.5,
|
|
113
|
+
children: [
|
|
114
|
+
/*#__PURE__*/ _jsx(IconButton, {
|
|
115
|
+
"aria-label": "edit panel",
|
|
116
|
+
size: "small",
|
|
117
|
+
onClick: handleEditButtonClick,
|
|
118
|
+
children: /*#__PURE__*/ _jsx(PencilIcon, {})
|
|
119
|
+
}),
|
|
120
|
+
/*#__PURE__*/ _jsx(IconButton, {
|
|
121
|
+
"aria-label": "drag handle",
|
|
122
|
+
size: "small",
|
|
123
|
+
children: /*#__PURE__*/ _jsx(DragIcon, {
|
|
124
|
+
className: "drag-handle",
|
|
125
|
+
sx: {
|
|
126
|
+
cursor: 'grab'
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
]
|
|
131
|
+
})
|
|
132
|
+
]
|
|
133
|
+
})
|
|
134
|
+
]
|
|
135
|
+
}),
|
|
136
|
+
sx: {
|
|
137
|
+
display: 'block',
|
|
138
|
+
padding: (theme)=>theme.spacing(1, panelPadding),
|
|
139
|
+
borderBottom: (theme)=>`solid 1px ${theme.palette.divider}`
|
|
140
|
+
}
|
|
141
|
+
}),
|
|
142
|
+
/*#__PURE__*/ _jsx(CardContent, {
|
|
143
|
+
sx: {
|
|
144
|
+
position: 'relative',
|
|
145
|
+
overflow: 'hidden',
|
|
146
|
+
flexGrow: 1,
|
|
147
|
+
padding: (theme)=>theme.spacing(panelPadding),
|
|
148
|
+
// Override MUI default style for last-child
|
|
149
|
+
':last-child': {
|
|
150
|
+
padding: (theme)=>theme.spacing(panelPadding)
|
|
151
|
+
}
|
|
152
|
+
},
|
|
153
|
+
ref: setContentElement,
|
|
154
|
+
children: /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
155
|
+
FallbackComponent: ErrorAlert,
|
|
156
|
+
children: inView === true && /*#__PURE__*/ _jsx(PanelContent, {
|
|
157
|
+
definition: definition,
|
|
158
|
+
contentDimensions: contentDimensions
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
})
|
|
162
|
+
]
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
const IconButton = styled(MuiIconButton)(({ theme })=>({
|
|
166
|
+
borderRadius: theme.shape.borderRadius,
|
|
167
|
+
padding: '4px'
|
|
168
|
+
}));
|
|
169
|
+
|
|
170
|
+
//# sourceMappingURL=Panel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Panel/Panel.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState, useMemo } from 'react';\nimport useResizeObserver from 'use-resize-observer';\nimport { useInView } from 'react-intersection-observer';\nimport { ErrorBoundary, ErrorAlert, InfoTooltip, TooltipPlacement } from '@perses-dev/components';\nimport { PanelDefinition } from '@perses-dev/core';\nimport {\n Box,\n Card,\n CardProps,\n CardHeader,\n CardContent,\n Typography,\n IconButton as MuiIconButton,\n Stack,\n styled,\n} from '@mui/material';\nimport InformationOutlineIcon from 'mdi-material-ui/InformationOutline';\nimport PencilIcon from 'mdi-material-ui/Pencil';\nimport DragIcon from 'mdi-material-ui/DragVertical';\nimport { useDashboardApp, useEditMode } from '../../context';\nimport { PanelContent } from './PanelContent';\n\nexport interface PanelProps extends CardProps {\n definition: PanelDefinition;\n groupIndex: number;\n panelKey: string;\n}\n\n/**\n * Renders a PanelDefinition's content inside of a Card.\n */\nexport function Panel(props: PanelProps) {\n const { definition, groupIndex, panelKey, ...others } = props;\n\n const [contentElement, setContentElement] = useState<HTMLDivElement | null>(null);\n const [isHovered, setIsHovered] = useState(false);\n\n const { width, height } = useResizeObserver({ ref: contentElement });\n\n const contentDimensions = useMemo(() => {\n if (width === undefined || height === undefined) return undefined;\n return { width, height };\n }, [width, height]);\n\n const { ref, inView } = useInView({\n threshold: 0.3,\n initialInView: false,\n triggerOnce: true,\n });\n\n // TODO: adjust padding for small panels, consistent way to determine isLargePanel here and in StatChart\n const panelPadding = 1.5;\n\n const { isEditMode } = useEditMode();\n\n const { openPanelDrawer } = useDashboardApp();\n\n const handleEditButtonClick = () => {\n openPanelDrawer({ groupIndex, panelKey });\n };\n\n return (\n <Card\n ref={ref}\n sx={{\n ...others.sx,\n width: '100%',\n height: '100%',\n display: 'flex',\n flexFlow: 'column nowrap',\n }}\n variant=\"outlined\"\n {...others}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n <CardHeader\n title={\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n minHeight: '24px',\n }}\n >\n <Typography\n component=\"h2\"\n variant=\"body2\"\n fontWeight={(theme) => theme.typography.fontWeightMedium}\n whiteSpace=\"nowrap\"\n overflow=\"hidden\"\n textOverflow=\"ellipsis\"\n >\n {definition.spec.display.name}\n </Typography>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n marginLeft: 'auto',\n }}\n >\n {!isEditMode && isHovered && definition.spec.display.description && (\n <InfoTooltip\n id=\"info-tooltip\"\n description={definition.spec.display.description}\n placement={TooltipPlacement.Bottom}\n >\n <InformationOutlineIcon\n aria-describedby=\"info-tooltip\"\n aria-hidden={false}\n fontSize=\"small\"\n sx={{ cursor: 'pointer' }}\n />\n </InfoTooltip>\n )}\n {isEditMode && isHovered && (\n <Stack direction=\"row\" alignItems=\"center\" spacing={0.5}>\n <IconButton aria-label=\"edit panel\" size=\"small\" onClick={handleEditButtonClick}>\n <PencilIcon />\n </IconButton>\n <IconButton aria-label=\"drag handle\" size=\"small\">\n <DragIcon className=\"drag-handle\" sx={{ cursor: 'grab' }} />\n </IconButton>\n </Stack>\n )}\n </Box>\n </Box>\n }\n sx={{\n display: 'block',\n padding: (theme) => theme.spacing(1, panelPadding),\n borderBottom: (theme) => `solid 1px ${theme.palette.divider}`,\n }}\n />\n <CardContent\n sx={{\n position: 'relative',\n overflow: 'hidden',\n flexGrow: 1,\n padding: (theme) => theme.spacing(panelPadding),\n // Override MUI default style for last-child\n ':last-child': {\n padding: (theme) => theme.spacing(panelPadding),\n },\n }}\n ref={setContentElement}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n {inView === true && <PanelContent definition={definition} contentDimensions={contentDimensions} />}\n </ErrorBoundary>\n </CardContent>\n </Card>\n );\n}\n\nconst IconButton = styled(MuiIconButton)(({ theme }) => ({\n borderRadius: theme.shape.borderRadius,\n padding: '4px',\n}));\n"],"names":["useState","useMemo","useResizeObserver","useInView","ErrorBoundary","ErrorAlert","InfoTooltip","TooltipPlacement","Box","Card","CardHeader","CardContent","Typography","IconButton","MuiIconButton","Stack","styled","InformationOutlineIcon","PencilIcon","DragIcon","useDashboardApp","useEditMode","PanelContent","Panel","props","definition","groupIndex","panelKey","others","contentElement","setContentElement","isHovered","setIsHovered","width","height","ref","contentDimensions","undefined","inView","threshold","initialInView","triggerOnce","panelPadding","isEditMode","openPanelDrawer","handleEditButtonClick","sx","display","flexFlow","variant","onMouseEnter","onMouseLeave","title","alignItems","minHeight","component","fontWeight","theme","typography","fontWeightMedium","whiteSpace","overflow","textOverflow","spec","name","marginLeft","description","id","placement","Bottom","aria-describedby","aria-hidden","fontSize","cursor","direction","spacing","aria-label","size","onClick","className","padding","borderBottom","palette","divider","position","flexGrow","FallbackComponent","borderRadius","shape"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,EAAEC,OAAO,QAAQ,OA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ACkB,OAAO,CAAC,CAAC,EAAEjC,YAAY,CAAC;oBAClDuC,YAAY,EAAE,CAACxB,KAAK,GAAK,CAAC,UAAU,EAAEA,KAAK,CAACyB,OAAO,CAACC,OAAO,CAAC,CAAC;iBAC9D;cACD;0BACF,KAACxE,WAAW;gBACVmC,EAAE,EAAE;oBACFsC,QAAQ,EAAE,UAAU;oBACpBvB,QAAQ,EAAE,QAAQ;oBAClBwB,QAAQ,EAAE,CAAC;oBACXL,OAAO,EAAE,CAACvB,KAAK,GAAKA,KAAK,CAACkB,OAAO,CAACjC,YAAY,CAAC;oBAC/C,4CAA4C;oBAC5C,aAAa,EAAE;wBACbsC,OAAO,EAAE,CAACvB,KAAK,GAAKA,KAAK,CAACkB,OAAO,CAACjC,YAAY,CAAC;qBAChD;iBACF;gBACDP,GAAG,EAAEL,iBAAiB;0BAEtB,cAAA,KAAC1B,aAAa;oBAACkF,iBAAiB,EAAEjF,UAAU;8BACzCiC,MAAM,KAAK,IAAI,kBAAI,KAAChB,YAAY;wBAACG,UAAU,EAAEA,UAAU;wBAAEW,iBAAiB,EAAEA,iBAAiB;sBAAI;kBACpF;cACJ;;MACT,CACP;AACJ,CAAC;AAED,MAAMvB,UAAU,GAAGG,MAAM,CAACF,aAAa,CAAC,CAAC,CAAC,EAAE2C,KAAK,CAAA,EAAE,GAAM,CAAA;QACvD8B,YAAY,EAAE9B,KAAK,CAAC+B,KAAK,CAACD,YAAY;QACtCP,OAAO,EAAE,KAAK;KACf,CAAA,AAAC,CAAC,AAAC"}
|
|
@@ -1 +1,71 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { PluginRegistry } from '@perses-dev/plugin-system';
|
|
15
|
+
import 'intersection-observer'; // TODO: Why do we need this side-effect? Should it be in test setup somewhere?
|
|
16
|
+
import { screen } from '@testing-library/react';
|
|
17
|
+
import { renderWithContext, mockPluginRegistryProps, FAKE_PANEL_PLUGIN, getTestDashboard } from '../../test';
|
|
18
|
+
import { DashboardProvider } from '../../context';
|
|
19
|
+
import { Panel } from './Panel';
|
|
20
|
+
describe('Panel', ()=>{
|
|
21
|
+
// Helper to create panel props for rendering tests
|
|
22
|
+
const createPanelProps = ()=>{
|
|
23
|
+
return {
|
|
24
|
+
definition: {
|
|
25
|
+
kind: 'Panel',
|
|
26
|
+
spec: {
|
|
27
|
+
display: {
|
|
28
|
+
name: 'Fake Panel',
|
|
29
|
+
description: 'This is a fake panel'
|
|
30
|
+
},
|
|
31
|
+
plugin: {
|
|
32
|
+
kind: 'FakePanel',
|
|
33
|
+
spec: {}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
groupIndex: 0,
|
|
38
|
+
panelKey: 'panelRef'
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
// Helper to render the panel with some context set
|
|
42
|
+
const renderPanel = (isEditMode = false)=>{
|
|
43
|
+
const { addMockPlugin , pluginRegistryProps } = mockPluginRegistryProps();
|
|
44
|
+
addMockPlugin('Panel', 'FakePanel', FAKE_PANEL_PLUGIN);
|
|
45
|
+
renderWithContext(/*#__PURE__*/ _jsx(PluginRegistry, {
|
|
46
|
+
...pluginRegistryProps,
|
|
47
|
+
children: /*#__PURE__*/ _jsx(DashboardProvider, {
|
|
48
|
+
initialState: {
|
|
49
|
+
dashboardSpec: getTestDashboard().spec,
|
|
50
|
+
isEditMode
|
|
51
|
+
},
|
|
52
|
+
children: /*#__PURE__*/ _jsx(Panel, {
|
|
53
|
+
...createPanelProps()
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
}));
|
|
57
|
+
};
|
|
58
|
+
it('should render name and info icon', async ()=>{
|
|
59
|
+
renderPanel();
|
|
60
|
+
await screen.findByText('Fake Panel');
|
|
61
|
+
screen.queryByLabelText('info-tooltip');
|
|
62
|
+
});
|
|
63
|
+
it('should render edit icons when in edit mode', ()=>{
|
|
64
|
+
renderPanel(true);
|
|
65
|
+
screen.queryByLabelText('drag handle');
|
|
66
|
+
screen.queryByLabelText('edit panel');
|
|
67
|
+
screen.queryByLabelText('more');
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
//# sourceMappingURL=Panel.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Panel/Panel.test.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PluginRegistry } from '@perses-dev/plugin-system';\nimport 'intersection-observer'; // TODO: Why do we need this side-effect? Should it be in test setup somewhere?\nimport { screen } from '@testing-library/react';\nimport { renderWithContext, mockPluginRegistryProps, FAKE_PANEL_PLUGIN, getTestDashboard } from '../../test';\nimport { DashboardProvider } from '../../context';\nimport { Panel, PanelProps } from './Panel';\n\ndescribe('Panel', () => {\n // Helper to create panel props for rendering tests\n const createPanelProps = (): PanelProps => {\n return {\n definition: {\n kind: 'Panel',\n spec: {\n display: {\n name: 'Fake Panel',\n description: 'This is a fake panel',\n },\n plugin: {\n kind: 'FakePanel',\n spec: {},\n },\n },\n },\n groupIndex: 0,\n panelKey: 'panelRef',\n };\n };\n\n // Helper to render the panel with some context set\n const renderPanel = (isEditMode = false) => {\n const { addMockPlugin, pluginRegistryProps } = mockPluginRegistryProps();\n addMockPlugin('Panel', 'FakePanel', FAKE_PANEL_PLUGIN);\n\n renderWithContext(\n <PluginRegistry {...pluginRegistryProps}>\n <DashboardProvider initialState={{ dashboardSpec: getTestDashboard().spec, isEditMode }}>\n <Panel {...createPanelProps()} />\n </DashboardProvider>\n </PluginRegistry>\n );\n };\n\n it('should render name and info icon', async () => {\n renderPanel();\n await screen.findByText('Fake Panel');\n screen.queryByLabelText('info-tooltip');\n });\n\n it('should render edit icons when in edit mode', () => {\n renderPanel(true);\n screen.queryByLabelText('drag handle');\n screen.queryByLabelText('edit panel');\n screen.queryByLabelText('more');\n });\n});\n"],"names":["PluginRegistry","screen","renderWithContext","mockPluginRegistryProps","FAKE_PANEL_PLUGIN","getTestDashboard","DashboardProvider","Panel","describe","createPanelProps","definition","kind","spec","display","name","description","plugin","groupIndex","panelKey","renderPanel","isEditMode","addMockPlugin","pluginRegistryProps","initialState","dashboardSpec","it","findByText","queryByLabelText"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,cAAc,QAAQ,2BAA2B,CAAC;AAC3D,OAAO,uBAAuB,CAAC,CAAC,+EAA+E;AAC/G,SAASC,MAAM,QAAQ,wBAAwB,CAAC;AAChD,SAASC,iBAAiB,EAAEC,uBAAuB,EAAEC,iBAAiB,EAAEC,gBAAgB,QAAQ,YAAY,CAAC;AAC7G,SAASC,iBAAiB,QAAQ,eAAe,CAAC;AAClD,SAASC,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AAM,CAAC0B,gBAAgB,CAAC,aAAa,CAAC,CAAC;QACvC1B,MAAM,CAAC0B,gBAAgB,CAAC,YAAY,CAAC,CAAC;QACtC1B,MAAM,CAAC0B,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAClC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { JsonObject } from '@perses-dev/core';
|
|
3
2
|
import { PanelProps } from '@perses-dev/plugin-system';
|
|
4
|
-
export declare type PanelContentProps = PanelProps<
|
|
3
|
+
export declare type PanelContentProps = PanelProps<unknown>;
|
|
5
4
|
/**
|
|
6
5
|
* A small wrapper component that renders the appropriate PanelComponent from a Panel plugin based on the panel
|
|
7
|
-
* definition's kind. Used so that
|
|
8
|
-
* the plugin is loading.
|
|
6
|
+
* definition's kind. Used so that an ErrorBoundary can be wrapped around this.
|
|
9
7
|
*/
|
|
10
8
|
export declare function PanelContent(props: PanelContentProps): JSX.Element;
|
|
11
9
|
//# sourceMappingURL=PanelContent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelContent.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/PanelContent.tsx"],"names":[],"mappings":";AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"PanelContent.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/PanelContent.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAa,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAGlE,oBAAY,iBAAiB,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;AAEpD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eAqBpD"}
|
|
@@ -1 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { usePlugin } from '@perses-dev/plugin-system';
|
|
15
|
+
import { Skeleton } from '@mui/material';
|
|
16
|
+
/**
|
|
17
|
+
* A small wrapper component that renders the appropriate PanelComponent from a Panel plugin based on the panel
|
|
18
|
+
* definition's kind. Used so that an ErrorBoundary can be wrapped around this.
|
|
19
|
+
*/ export function PanelContent(props) {
|
|
20
|
+
const { definition: { spec: { plugin: { kind: panelPluginKind } , } , } , contentDimensions , } = props;
|
|
21
|
+
const { data: plugin , isLoading } = usePlugin('Panel', panelPluginKind, {
|
|
22
|
+
useErrorBoundary: true
|
|
23
|
+
});
|
|
24
|
+
const PanelComponent = plugin === null || plugin === void 0 ? void 0 : plugin.PanelComponent;
|
|
25
|
+
if (isLoading) {
|
|
26
|
+
return /*#__PURE__*/ _jsx(Skeleton, {
|
|
27
|
+
variant: "rectangular",
|
|
28
|
+
width: contentDimensions === null || contentDimensions === void 0 ? void 0 : contentDimensions.width,
|
|
29
|
+
height: contentDimensions === null || contentDimensions === void 0 ? void 0 : contentDimensions.height
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (PanelComponent === undefined) {
|
|
33
|
+
throw new Error(`Missing PanelComponent from panel plugin for kind '${panelPluginKind}'`);
|
|
34
|
+
}
|
|
35
|
+
return /*#__PURE__*/ _jsx(PanelComponent, {
|
|
36
|
+
...props
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
//# sourceMappingURL=PanelContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Panel/PanelContent.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { usePlugin, PanelProps } from '@perses-dev/plugin-system';\nimport { Skeleton } from '@mui/material';\n\nexport type PanelContentProps = PanelProps<unknown>;\n\n/**\n * A small wrapper component that renders the appropriate PanelComponent from a Panel plugin based on the panel\n * definition's kind. Used so that an ErrorBoundary can be wrapped around this.\n */\nexport function PanelContent(props: PanelContentProps) {\n const {\n definition: {\n spec: {\n plugin: { kind: panelPluginKind },\n },\n },\n contentDimensions,\n } = props;\n const { data: plugin, isLoading } = usePlugin('Panel', panelPluginKind, { useErrorBoundary: true });\n const PanelComponent = plugin?.PanelComponent;\n\n if (isLoading) {\n return <Skeleton variant=\"rectangular\" width={contentDimensions?.width} height={contentDimensions?.height} />;\n }\n\n if (PanelComponent === undefined) {\n throw new Error(`Missing PanelComponent from panel plugin for kind '${panelPluginKind}'`);\n }\n\n return <PanelComponent {...props} />;\n}\n"],"names":["usePlugin","Skeleton","PanelContent","props","definition","spec","plugin","kind","panelPluginKind","contentDimensions","data","isLoading","useErrorBoundary","PanelComponent","variant","width","height","undefined","Error"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,SAAS,QAAoB,2BAA2B,CAAC;AAClE,SAASC,QAAQ,QAAQ,eAAe,CAAC;AAIzC;;;CAGC,GACD,OAAO,SAASC,YAAY,CAACC,KAAwB,EAAE;IACrD,MAAM,EACJC,UAAU,EAAE,EACVC,IAAI,EAAE,EACJC,MAAM,EAAE,EAAEC,IAAI,EAAEC,eAAe,CAAA,EAAE,CAAA,IAClC,CAAA,IACF,CAAA,EACDC,iBAAiB,CAAA,IAClB,GAAGN,KAAK,AAAC;IACV,MAAM,EAAEO,IAAI,EAAEJ,MAAM,CAAA,EAAEK,SAAS,CAAA,EAAE,GAAGX,SAAS,CAAC,OAAO,EAAEQ,eAAe,EAAE;QAAEI,gBAAgB,EAAE,IAAI;KAAE,CAAC,AAAC;IACpG,MAAMC,cAAc,GAAGP,MAAM,aAANA,MAAM,WAAgB,GAAtBA,KAAAA,CAAsB,GAAtBA,MAAM,CAAEO,cAAc,AAAC;IAE9C,IAAIF,SAAS,EAAE;QACb,qBAAO,KAACV,QAAQ;YAACa,OAAO,EAAC,aAAa;YAACC,KAAK,EAAEN,iBAAiB,aAAjBA,iBAAiB,WAAO,GAAxBA,KAAAA,CAAwB,GAAxBA,iBAAiB,CAAEM,KAAK;YAAEC,MAAM,EAAEP,iBAAiB,aAAjBA,iBAAiB,WAAQ,GAAzBA,KAAAA,CAAyB,GAAzBA,iBAAiB,CAAEO,MAAM;UAAI,CAAC;IAChH,CAAC;IAED,IAAIH,cAAc,KAAKI,SAAS,EAAE;QAChC,MAAM,IAAIC,KAAK,CAAC,CAAC,mDAAmD,EAAEV,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5F,CAAC;IAED,qBAAO,KAACK,cAAc;QAAE,GAAGV,KAAK;MAAI,CAAC;AACvC,CAAC"}
|
|
@@ -1 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
export * from './Panel';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/Panel/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './Panel';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,SAAS,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* The Add/Edit panel drawer for editing a panel's options.
|
|
4
|
+
*/
|
|
5
|
+
export declare const PanelDrawer: () => JSX.Element;
|
|
4
6
|
//# sourceMappingURL=PanelDrawer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PanelDrawer.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelDrawer.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"PanelDrawer.d.ts","sourceRoot":"","sources":["../../../src/components/PanelDrawer/PanelDrawer.tsx"],"names":[],"mappings":";AAoBA;;GAEG;AACH,eAAO,MAAM,WAAW,mBAwDvB,CAAC"}
|
|
@@ -1 +1,95 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { useState } from 'react';
|
|
15
|
+
import { Stack, Box, Button, Typography } from '@mui/material';
|
|
16
|
+
import { Drawer } from '@perses-dev/components';
|
|
17
|
+
import { useDashboardApp } from '../../context';
|
|
18
|
+
import { usePanelDrawerModel } from './panel-editor-model';
|
|
19
|
+
import { PanelEditorForm, panelEditorFormId } from './PanelEditorForm';
|
|
20
|
+
/**
|
|
21
|
+
* The Add/Edit panel drawer for editing a panel's options.
|
|
22
|
+
*/ export const PanelDrawer = ()=>{
|
|
23
|
+
const { closePanelDrawer } = useDashboardApp();
|
|
24
|
+
const model = usePanelDrawerModel();
|
|
25
|
+
// When the user clicks close, start closing but don't call the store yet to keep values stable during animtation
|
|
26
|
+
const [isClosing, setIsClosing] = useState(false);
|
|
27
|
+
const handleClose = ()=>setIsClosing(true);
|
|
28
|
+
// Don't call closeDrawer on the store until the Drawer has completely transitioned out
|
|
29
|
+
const handleExited = ()=>{
|
|
30
|
+
closePanelDrawer();
|
|
31
|
+
setIsClosing(false);
|
|
32
|
+
};
|
|
33
|
+
// Drawer is open if we have a model and we're not transitioning out
|
|
34
|
+
const isOpen = model !== undefined && isClosing === false;
|
|
35
|
+
const handleSubmit = (values)=>{
|
|
36
|
+
// This shouldn't happen since we don't render the submit button until we have a model, but check to make TS happy
|
|
37
|
+
if (model === undefined) {
|
|
38
|
+
throw new Error('Cannot apply changes');
|
|
39
|
+
}
|
|
40
|
+
model.applyChanges(values);
|
|
41
|
+
handleClose();
|
|
42
|
+
};
|
|
43
|
+
return /*#__PURE__*/ _jsx(Drawer, {
|
|
44
|
+
isOpen: isOpen,
|
|
45
|
+
onClose: handleClose,
|
|
46
|
+
SlideProps: {
|
|
47
|
+
onExited: handleExited
|
|
48
|
+
},
|
|
49
|
+
children: model !== undefined && /*#__PURE__*/ _jsxs(_Fragment, {
|
|
50
|
+
children: [
|
|
51
|
+
/*#__PURE__*/ _jsxs(Box, {
|
|
52
|
+
sx: {
|
|
53
|
+
display: 'flex',
|
|
54
|
+
alignItems: 'center',
|
|
55
|
+
marginBottom: (theme)=>theme.spacing(2),
|
|
56
|
+
paddingBottom: (theme)=>theme.spacing(2),
|
|
57
|
+
borderBottom: (theme)=>`1px solid ${theme.palette.grey[100]}`
|
|
58
|
+
},
|
|
59
|
+
children: [
|
|
60
|
+
/*#__PURE__*/ _jsx(Typography, {
|
|
61
|
+
variant: "h2",
|
|
62
|
+
children: model.drawerTitle
|
|
63
|
+
}),
|
|
64
|
+
/*#__PURE__*/ _jsxs(Stack, {
|
|
65
|
+
direction: "row",
|
|
66
|
+
spacing: 1,
|
|
67
|
+
sx: {
|
|
68
|
+
marginLeft: 'auto'
|
|
69
|
+
},
|
|
70
|
+
children: [
|
|
71
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
72
|
+
type: "submit",
|
|
73
|
+
variant: "contained",
|
|
74
|
+
form: panelEditorFormId,
|
|
75
|
+
children: model.submitButtonText
|
|
76
|
+
}),
|
|
77
|
+
/*#__PURE__*/ _jsx(Button, {
|
|
78
|
+
variant: "outlined",
|
|
79
|
+
onClick: handleClose,
|
|
80
|
+
children: "Cancel"
|
|
81
|
+
})
|
|
82
|
+
]
|
|
83
|
+
})
|
|
84
|
+
]
|
|
85
|
+
}),
|
|
86
|
+
/*#__PURE__*/ _jsx(PanelEditorForm, {
|
|
87
|
+
onSubmit: handleSubmit,
|
|
88
|
+
initialValues: model.initialValues
|
|
89
|
+
})
|
|
90
|
+
]
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=PanelDrawer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/PanelDrawer/PanelDrawer.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { useState } from 'react';\nimport { Stack, Box, Button, Typography } from '@mui/material';\nimport { Drawer } from '@perses-dev/components';\nimport { useDashboardApp } from '../../context';\nimport { usePanelDrawerModel } from './panel-editor-model';\nimport { PanelEditorForm, panelEditorFormId, PanelEditorFormProps } from './PanelEditorForm';\n\n/**\n * The Add/Edit panel drawer for editing a panel's options.\n */\nexport const PanelDrawer = () => {\n const { closePanelDrawer } = useDashboardApp();\n const model = usePanelDrawerModel();\n\n // When the user clicks close, start closing but don't call the store yet to keep values stable during animtation\n const [isClosing, setIsClosing] = useState(false);\n const handleClose = () => setIsClosing(true);\n\n // Don't call closeDrawer on the store until the Drawer has completely transitioned out\n const handleExited = () => {\n closePanelDrawer();\n setIsClosing(false);\n };\n\n // Drawer is open if we have a model and we're not transitioning out\n const isOpen = model !== undefined && isClosing === false;\n\n const handleSubmit: PanelEditorFormProps['onSubmit'] = (values) => {\n // This shouldn't happen since we don't render the submit button until we have a model, but check to make TS happy\n if (model === undefined) {\n throw new Error('Cannot apply changes');\n }\n model.applyChanges(values);\n handleClose();\n };\n\n return (\n <Drawer isOpen={isOpen} onClose={handleClose} SlideProps={{ onExited: handleExited }}>\n {/* When the drawer is opened, we should have a model (this also ensures the form state gets reset between opens) */}\n {model !== undefined && (\n <>\n <Box\n sx={{\n display: 'flex',\n alignItems: 'center',\n marginBottom: (theme) => theme.spacing(2),\n paddingBottom: (theme) => theme.spacing(2),\n borderBottom: (theme) => `1px solid ${theme.palette.grey[100]}`,\n }}\n >\n <Typography variant=\"h2\">{model.drawerTitle}</Typography>\n <Stack direction=\"row\" spacing={1} sx={{ marginLeft: 'auto' }}>\n {/* Using the 'form' attribute lets us have a submit button like this outside the form element */}\n <Button type=\"submit\" variant=\"contained\" form={panelEditorFormId}>\n {model.submitButtonText}\n </Button>\n <Button variant=\"outlined\" onClick={handleClose}>\n Cancel\n </Button>\n </Stack>\n </Box>\n <PanelEditorForm onSubmit={handleSubmit} initialValues={model.initialValues} />\n </>\n )}\n </Drawer>\n );\n};\n"],"names":["useState","Stack","Box","Button","Typography","Drawer","useDashboardApp","usePanelDrawerModel","PanelEditorForm","panelEditorFormId","PanelDrawer","closePanelDrawer","model","isClosing","setIsClosing","handleClose","handleExited","isOpen","undefined","handleSubmit","values","Error","applyChanges","onClose","SlideProps","onExited","sx","display","alignItems","marginBottom","theme","spacing","paddingBottom","borderBottom","palette","grey","variant","drawerTitle","direction","marginLeft","type","form","submitButtonText","onClick","onSubmit","initialValues"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AAC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,EAAER,WAAW;QAAES,UAAU,EAAE;YAAEC,QAAQ,EAAET,YAAY;SAAE;kBAEjFJ,KAAK,KAAKM,SAAS,kBAClB;;8BACE,MAAChB,GAAG;oBACFwB,EAAE,EAAE;wBACFC,OAAO,EAAE,MAAM;wBACfC,UAAU,EAAE,QAAQ;wBACpBC,YAAY,EAAE,CAACC,KAAK,GAAKA,KAAK,CAACC,OAAO,CAAC,CAAC,CAAC;wBACzCC,aAAa,EAAE,CAACF,KAAK,GAAKA,KAAK,CAACC,OAAO,CAAC,CAAC,CAAC;wBAC1CE,YAAY,EAAE,CAACH,KAAK,GAAK,CAAC,UAAU,EAAEA,KAAK,CAACI,OAAO,CAACC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;qBAChE;;sCAED,KAAC/B,UAAU;4BAACgC,OAAO,EAAC,IAAI;sCAAExB,KAAK,CAACyB,WAAW;0BAAc;sCACzD,MAACpC,KAAK;4BAACqC,SAAS,EAAC,KAAK;4BAACP,OAAO,EAAE,CAAC;4BAAEL,EAAE,EAAE;gCAAEa,UAAU,EAAE,MAAM;6BAAE;;8CAE3D,KAACpC,MAAM;oCAACqC,IAAI,EAAC,QAAQ;oCAACJ,OAAO,EAAC,WAAW;oCAACK,IAAI,EAAEhC,iBAAiB;8CAC9DG,KAAK,CAAC8B,gBAAgB;kCAChB;8CACT,KAACvC,MAAM;oCAACiC,OAAO,EAAC,UAAU;oCAACO,OAAO,EAAE5B,WAAW;8CAAE,QAEjD;kCAAS;;0BACH;;kBACJ;8BACN,KAACP,eAAe;oBAACoC,QAAQ,EAAEzB,YAAY;oBAAE0B,aAAa,EAAEjC,KAAK,CAACiC,aAAa;kBAAI;;UAC9E,AACJ;MACM,CACT;AACJ,CAAC,CAAC"}
|
|
@@ -1 +1,103 @@
|
|
|
1
|
-
|
|
1
|
+
// Copyright 2022 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { PluginRegistry } from '@perses-dev/plugin-system';
|
|
15
|
+
import { screen } from '@testing-library/react';
|
|
16
|
+
import userEvent from '@testing-library/user-event';
|
|
17
|
+
import { act } from 'react-dom/test-utils';
|
|
18
|
+
import { createDashboardProviderSpy, FAKE_PANEL_PLUGIN, getTestDashboard, mockPluginRegistryProps, renderWithContext } from '../../test';
|
|
19
|
+
import { DashboardProvider } from '../../context/DashboardProvider';
|
|
20
|
+
import { PanelDrawer } from './PanelDrawer';
|
|
21
|
+
describe('Panel Drawer', ()=>{
|
|
22
|
+
const renderPanelDrawer = ()=>{
|
|
23
|
+
const { addMockPlugin , pluginRegistryProps } = mockPluginRegistryProps();
|
|
24
|
+
addMockPlugin('Panel', 'LineChart', FAKE_PANEL_PLUGIN);
|
|
25
|
+
const { store , DashboardProviderSpy } = createDashboardProviderSpy();
|
|
26
|
+
renderWithContext(/*#__PURE__*/ _jsx(PluginRegistry, {
|
|
27
|
+
...pluginRegistryProps,
|
|
28
|
+
children: /*#__PURE__*/ _jsxs(DashboardProvider, {
|
|
29
|
+
initialState: {
|
|
30
|
+
dashboardSpec: getTestDashboard().spec,
|
|
31
|
+
isEditMode: true
|
|
32
|
+
},
|
|
33
|
+
children: [
|
|
34
|
+
/*#__PURE__*/ _jsx(DashboardProviderSpy, {}),
|
|
35
|
+
/*#__PURE__*/ _jsx(PanelDrawer, {})
|
|
36
|
+
]
|
|
37
|
+
})
|
|
38
|
+
}));
|
|
39
|
+
const { value: storeApi } = store;
|
|
40
|
+
if (storeApi === undefined) {
|
|
41
|
+
throw new Error('Expected dashboard store to be set after initial render');
|
|
42
|
+
}
|
|
43
|
+
return storeApi;
|
|
44
|
+
};
|
|
45
|
+
it('should add new panel', async ()=>{
|
|
46
|
+
const storeApi = renderPanelDrawer();
|
|
47
|
+
// Open the drawer for a new panel (i.e. no panel key)
|
|
48
|
+
act(()=>storeApi.getState().openPanelDrawer({
|
|
49
|
+
groupIndex: 0
|
|
50
|
+
}));
|
|
51
|
+
const nameInput = await screen.findByLabelText(/Panel Name/);
|
|
52
|
+
userEvent.type(nameInput, 'New Panel');
|
|
53
|
+
userEvent.click(screen.getByText('Add'));
|
|
54
|
+
// TODO: Assert drawer is closed?
|
|
55
|
+
const panels = storeApi.getState().panels;
|
|
56
|
+
expect(panels).toMatchObject({
|
|
57
|
+
// Should have the new panel in the store
|
|
58
|
+
NewPanel: {
|
|
59
|
+
kind: 'Panel',
|
|
60
|
+
spec: {
|
|
61
|
+
display: {
|
|
62
|
+
name: 'New Panel',
|
|
63
|
+
description: ''
|
|
64
|
+
},
|
|
65
|
+
plugin: {
|
|
66
|
+
kind: '',
|
|
67
|
+
spec: {}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
it('should edit an existing panel', async ()=>{
|
|
74
|
+
const storeApi = renderPanelDrawer();
|
|
75
|
+
// Open the drawer for an existing panel
|
|
76
|
+
act(()=>storeApi.getState().openPanelDrawer({
|
|
77
|
+
groupIndex: 0,
|
|
78
|
+
panelKey: 'cpu'
|
|
79
|
+
}));
|
|
80
|
+
const nameInput = await screen.findByLabelText(/Panel Name/);
|
|
81
|
+
userEvent.clear(nameInput);
|
|
82
|
+
userEvent.type(nameInput, 'cpu usage');
|
|
83
|
+
userEvent.click(screen.getByText('Apply'));
|
|
84
|
+
const panels = storeApi.getState().panels;
|
|
85
|
+
expect(panels).toMatchObject({
|
|
86
|
+
cpu: {
|
|
87
|
+
kind: 'Panel',
|
|
88
|
+
spec: {
|
|
89
|
+
display: {
|
|
90
|
+
name: 'cpu usage',
|
|
91
|
+
description: ''
|
|
92
|
+
},
|
|
93
|
+
plugin: {
|
|
94
|
+
kind: 'TimeSeriesChart',
|
|
95
|
+
spec: {}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=PanelDrawer.test.js.map
|