@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.
Files changed (196) hide show
  1. package/dist/cjs/components/Dashboard.js +29 -14
  2. package/dist/cjs/components/DashboardToolbar.js +148 -20
  3. package/dist/cjs/components/GridLayout/GridItemContent.js +24 -18
  4. package/dist/cjs/components/GridLayout/GridLayout.js +88 -26
  5. package/dist/cjs/components/GridLayout/GridTitle.js +69 -31
  6. package/dist/cjs/components/GridLayout/index.js +18 -19
  7. package/dist/cjs/components/Panel/Panel.js +145 -55
  8. package/dist/cjs/components/Panel/Panel.test.js +50 -41
  9. package/dist/cjs/components/Panel/PanelContent.js +40 -12
  10. package/dist/cjs/components/Panel/index.js +16 -17
  11. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +82 -107
  12. package/dist/cjs/components/PanelDrawer/PanelDrawer.test.js +91 -92
  13. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +152 -0
  14. package/dist/cjs/components/PanelDrawer/PanelSpecEditor.js +40 -0
  15. package/dist/cjs/components/PanelDrawer/PanelTypeSelect.js +38 -0
  16. package/dist/cjs/components/PanelDrawer/index.js +28 -0
  17. package/dist/cjs/components/PanelDrawer/panel-editor-model.js +140 -0
  18. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +120 -31
  19. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.test.js +90 -83
  20. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.js +120 -38
  21. package/dist/cjs/components/TimeRangeControls/TimeRangeControls.test.js +42 -27
  22. package/dist/cjs/components/TimeRangeControls/index.js +16 -17
  23. package/dist/cjs/components/Variables/Variable.js +186 -35
  24. package/dist/cjs/components/Variables/VariableList.js +100 -13
  25. package/dist/cjs/components/Variables/index.js +17 -18
  26. package/dist/cjs/components/index.js +21 -21
  27. package/dist/cjs/context/DashboardAppSlice.js +43 -31
  28. package/dist/cjs/context/DashboardProvider.js +88 -58
  29. package/dist/cjs/context/DatasourceStoreProvider.js +68 -0
  30. package/dist/cjs/context/LayoutsSlice.js +40 -27
  31. package/dist/cjs/context/QueryStringProvider.js +69 -15
  32. package/dist/cjs/context/TemplateVariableProvider.js +128 -136
  33. package/dist/cjs/context/TimeRangeProvider.js +79 -30
  34. package/dist/cjs/context/index.js +22 -22
  35. package/dist/cjs/css/styles.js +43 -39
  36. package/dist/cjs/index.js +19 -20
  37. package/dist/cjs/test/dashboard-provider.js +51 -0
  38. package/dist/cjs/test/index.js +18 -18
  39. package/dist/cjs/test/plugin-registry.js +52 -25
  40. package/dist/cjs/test/render.js +25 -22
  41. package/dist/cjs/test/setup-tests.js +4 -2
  42. package/dist/cjs/test/testDashboard.js +193 -109
  43. package/dist/cjs/utils/functions.js +9 -5
  44. package/dist/cjs/views/ViewDashboard/DashboardApp.js +67 -0
  45. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +83 -0
  46. package/dist/cjs/views/ViewDashboard/index.js +28 -0
  47. package/dist/cjs/views/index.js +16 -17
  48. package/dist/components/Dashboard.js +38 -1
  49. package/dist/components/Dashboard.js.map +1 -0
  50. package/dist/components/DashboardToolbar.d.ts.map +1 -1
  51. package/dist/components/DashboardToolbar.js +154 -1
  52. package/dist/components/DashboardToolbar.js.map +1 -0
  53. package/dist/components/GridLayout/GridItemContent.js +35 -1
  54. package/dist/components/GridLayout/GridItemContent.js.map +1 -0
  55. package/dist/components/GridLayout/GridLayout.js +99 -1
  56. package/dist/components/GridLayout/GridLayout.js.map +1 -0
  57. package/dist/components/GridLayout/GridTitle.js +77 -1
  58. package/dist/components/GridLayout/GridTitle.js.map +1 -0
  59. package/dist/components/GridLayout/index.js +16 -1
  60. package/dist/components/GridLayout/index.js.map +1 -0
  61. package/dist/components/Panel/Panel.d.ts.map +1 -1
  62. package/dist/components/Panel/Panel.js +170 -1
  63. package/dist/components/Panel/Panel.js.map +1 -0
  64. package/dist/components/Panel/Panel.test.js +71 -1
  65. package/dist/components/Panel/Panel.test.js.map +1 -0
  66. package/dist/components/Panel/PanelContent.d.ts +2 -4
  67. package/dist/components/Panel/PanelContent.d.ts.map +1 -1
  68. package/dist/components/Panel/PanelContent.js +40 -1
  69. package/dist/components/Panel/PanelContent.js.map +1 -0
  70. package/dist/components/Panel/index.js +15 -1
  71. package/dist/components/Panel/index.js.map +1 -0
  72. package/dist/components/PanelDrawer/PanelDrawer.d.ts +4 -2
  73. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  74. package/dist/components/PanelDrawer/PanelDrawer.js +95 -1
  75. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -0
  76. package/dist/components/PanelDrawer/PanelDrawer.test.js +103 -1
  77. package/dist/components/PanelDrawer/PanelDrawer.test.js.map +1 -0
  78. package/dist/components/PanelDrawer/PanelEditorForm.d.ts +12 -0
  79. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -0
  80. package/dist/components/PanelDrawer/PanelEditorForm.js +142 -0
  81. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -0
  82. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts +7 -0
  83. package/dist/components/PanelDrawer/PanelSpecEditor.d.ts.map +1 -0
  84. package/dist/components/PanelDrawer/PanelSpecEditor.js +34 -0
  85. package/dist/components/PanelDrawer/PanelSpecEditor.js.map +1 -0
  86. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts +8 -0
  87. package/dist/components/PanelDrawer/PanelTypeSelect.d.ts.map +1 -0
  88. package/dist/components/PanelDrawer/PanelTypeSelect.js +34 -0
  89. package/dist/components/PanelDrawer/PanelTypeSelect.js.map +1 -0
  90. package/dist/components/PanelDrawer/index.d.ts +2 -0
  91. package/dist/components/PanelDrawer/index.d.ts.map +1 -0
  92. package/dist/components/PanelDrawer/index.js +15 -0
  93. package/dist/components/PanelDrawer/index.js.map +1 -0
  94. package/dist/components/PanelDrawer/panel-editor-model.d.ts +27 -0
  95. package/dist/components/PanelDrawer/panel-editor-model.d.ts.map +1 -0
  96. package/dist/components/PanelDrawer/panel-editor-model.js +133 -0
  97. package/dist/components/PanelDrawer/panel-editor-model.js.map +1 -0
  98. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  99. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +138 -1
  100. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -0
  101. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js +95 -1
  102. package/dist/components/PanelGroupDialog/PanelGroupDialog.test.js.map +1 -0
  103. package/dist/components/TimeRangeControls/TimeRangeControls.js +137 -1
  104. package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -0
  105. package/dist/components/TimeRangeControls/TimeRangeControls.test.js +59 -1
  106. package/dist/components/TimeRangeControls/TimeRangeControls.test.js.map +1 -0
  107. package/dist/components/TimeRangeControls/index.js +15 -1
  108. package/dist/components/TimeRangeControls/index.js.map +1 -0
  109. package/dist/components/Variables/Variable.d.ts.map +1 -1
  110. package/dist/components/Variables/Variable.js +202 -1
  111. package/dist/components/Variables/Variable.js.map +1 -0
  112. package/dist/components/Variables/VariableList.js +108 -1
  113. package/dist/components/Variables/VariableList.js.map +1 -0
  114. package/dist/components/Variables/index.js +16 -1
  115. package/dist/components/Variables/index.js.map +1 -0
  116. package/dist/components/index.d.ts +1 -0
  117. package/dist/components/index.d.ts.map +1 -1
  118. package/dist/components/index.js +20 -1
  119. package/dist/components/index.js.map +1 -0
  120. package/dist/context/DashboardAppSlice.js +45 -1
  121. package/dist/context/DashboardAppSlice.js.map +1 -0
  122. package/dist/context/DashboardProvider.d.ts +4 -2
  123. package/dist/context/DashboardProvider.d.ts.map +1 -1
  124. package/dist/context/DashboardProvider.js +107 -1
  125. package/dist/context/DashboardProvider.js.map +1 -0
  126. package/dist/context/DatasourceStoreProvider.d.ts +16 -0
  127. package/dist/context/DatasourceStoreProvider.d.ts.map +1 -0
  128. package/dist/context/DatasourceStoreProvider.js +64 -0
  129. package/dist/context/DatasourceStoreProvider.js.map +1 -0
  130. package/dist/context/LayoutsSlice.js +43 -1
  131. package/dist/context/LayoutsSlice.js.map +1 -0
  132. package/dist/context/QueryStringProvider.js +40 -1
  133. package/dist/context/QueryStringProvider.js.map +1 -0
  134. package/dist/context/TemplateVariableProvider.d.ts +6 -3
  135. package/dist/context/TemplateVariableProvider.d.ts.map +1 -1
  136. package/dist/context/TemplateVariableProvider.js +192 -1
  137. package/dist/context/TemplateVariableProvider.js.map +1 -0
  138. package/dist/context/TimeRangeProvider.js +72 -1
  139. package/dist/context/TimeRangeProvider.js.map +1 -0
  140. package/dist/context/index.d.ts +3 -2
  141. package/dist/context/index.d.ts.map +1 -1
  142. package/dist/context/index.js +21 -1
  143. package/dist/context/index.js.map +1 -0
  144. package/dist/css/styles.js +186 -1
  145. package/dist/css/styles.js.map +1 -0
  146. package/dist/index.js +17 -1
  147. package/dist/index.js.map +1 -0
  148. package/dist/test/dashboard-provider.d.ts +19 -0
  149. package/dist/test/dashboard-provider.d.ts.map +1 -0
  150. package/dist/test/dashboard-provider.js +40 -0
  151. package/dist/test/dashboard-provider.js.map +1 -0
  152. package/dist/test/index.d.ts +1 -0
  153. package/dist/test/index.d.ts.map +1 -1
  154. package/dist/test/index.js +17 -1
  155. package/dist/test/index.js.map +1 -0
  156. package/dist/test/plugin-registry.d.ts +2 -3
  157. package/dist/test/plugin-registry.d.ts.map +1 -1
  158. package/dist/test/plugin-registry.js +74 -1
  159. package/dist/test/plugin-registry.js.map +1 -0
  160. package/dist/test/render.d.ts +1 -2
  161. package/dist/test/render.d.ts.map +1 -1
  162. package/dist/test/render.js +34 -1
  163. package/dist/test/render.js.map +1 -0
  164. package/dist/test/setup-tests.js +18 -1
  165. package/dist/test/setup-tests.js.map +1 -0
  166. package/dist/test/testDashboard.d.ts.map +1 -1
  167. package/dist/test/testDashboard.js +274 -1
  168. package/dist/test/testDashboard.js.map +1 -0
  169. package/dist/utils/functions.js +17 -1
  170. package/dist/utils/functions.js.map +1 -0
  171. package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -0
  172. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -0
  173. package/dist/views/ViewDashboard/DashboardApp.js +56 -0
  174. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -0
  175. package/dist/views/{ViewDashboard.d.ts → ViewDashboard/ViewDashboard.d.ts} +3 -1
  176. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -0
  177. package/dist/views/ViewDashboard/ViewDashboard.js +79 -0
  178. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -0
  179. package/dist/views/ViewDashboard/index.d.ts +2 -0
  180. package/dist/views/ViewDashboard/index.d.ts.map +1 -0
  181. package/dist/views/ViewDashboard/index.js +15 -0
  182. package/dist/views/ViewDashboard/index.js.map +1 -0
  183. package/dist/views/index.js +15 -1
  184. package/dist/views/index.js.map +1 -0
  185. package/package.json +13 -7
  186. package/dist/cjs/components/PanelDrawer/PanelOptionsEditor.js +0 -19
  187. package/dist/cjs/views/DashboardApp.js +0 -46
  188. package/dist/cjs/views/ViewDashboard.js +0 -43
  189. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts +0 -9
  190. package/dist/components/PanelDrawer/PanelOptionsEditor.d.ts.map +0 -1
  191. package/dist/components/PanelDrawer/PanelOptionsEditor.js +0 -1
  192. package/dist/views/DashboardApp.d.ts +0 -4
  193. package/dist/views/DashboardApp.d.ts.map +0 -1
  194. package/dist/views/DashboardApp.js +0 -1
  195. package/dist/views/ViewDashboard.d.ts.map +0 -1
  196. package/dist/views/ViewDashboard.js +0 -1
@@ -1 +1,170 @@
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}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 DragIcon from"mdi-material-ui/DragVertical";import{useDashboardApp,useEditMode}from"../../context";import{PanelContent}from"./PanelContent";export function Panel(e){const{definition:i,groupIndex:o,panelKey:n,...r}=e,[t,a]=useState(null),[s,l]=useState(!1),{width:d,height:p}=useResizeObserver({ref:t}),c=useMemo((()=>{if(void 0!==d&&void 0!==p)return{width:d,height:p}}),[d,p]),{ref:m,inView:u}=useInView({threshold:.3,initialInView:!1,triggerOnce:!0}),{isEditMode:x}=useEditMode(),{openPanelDrawer:f}=useDashboardApp();return _jsxs(Card,{ref:m,sx:{...r.sx,width:"100%",height:"100%",display:"flex",flexFlow:"column nowrap"},variant:"outlined",...r,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),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:[!x&&s&&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"}})}),x&&s&&_jsxs(Stack,{direction:"row",alignItems:"center",spacing:.5,children:[_jsx(IconButton,{"aria-label":"edit panel",size:"small",onClick:()=>{f({groupIndex:o,panelKey:n})},children:_jsx(PencilIcon,{})}),_jsx(IconButton,{"aria-label":"drag handle",size:"small",children:_jsx(DragIcon,{className:"drag-handle",sx:{cursor:"grab"}})})]})]})]}),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:a,children:_jsx(PluginBoundary,{loadingFallback:"Loading...",ErrorFallbackComponent:ErrorAlert,children:!0===u&&_jsx(PanelContent,{definition:i,contentDimensions:c})})})]})}const IconButton=styled(MuiIconButton)((({theme:e})=>({borderRadius:e.shape.borderRadius,padding:"4px"})));
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,OAAO,CAAC;AAC1C,OAAOC,iBAAiB,MAAM,qBAAqB,CAAC;AACpD,SAASC,SAAS,QAAQ,6BAA6B,CAAC;AACxD,SAASC,aAAa,EAAEC,UAAU,EAAEC,WAAW,EAAEC,gBAAgB,QAAQ,wBAAwB,CAAC;AAElG,SACEC,GAAG,EACHC,IAAI,EAEJC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,UAAU,IAAIC,aAAa,EAC3BC,KAAK,EACLC,MAAM,QAC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AO,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
- 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,FAKE_PANEL_PLUGIN}from"../../test";import testDashboard from"../../test/testDashboard";import{Panel}from"./Panel";describe("Panel",(()=>{let e,r;beforeEach((()=>{e={definition:{display:{name:"Fake Panel",description:"This is a fake panel"},kind:"FakePanel",options:{}},groupIndex:0,panelKey:"panelRef"},r={isEditMode:!1,dashboardSpec:testDashboard.spec}}));const n=r=>{const{addMockPlugin:n,pluginRegistryProps:t}=mockPluginRegistryProps();n("Panel","FakePanel",FAKE_PANEL_PLUGIN),renderWithContext(_jsx(PluginRegistry,{...t,children:_jsx(Panel,{...e})}),r)};it("should render name and info icon",(async()=>{n(),await screen.findByText("Fake Panel"),screen.queryByLabelText("info-tooltip")})),it("should render edit icons when in edit mode",(async()=>{r.isEditMode=!0,n(r),await screen.queryByLabelText("drag handle"),screen.queryByLabelText("edit panel"),screen.queryByLabelText("more")}))}));
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,KAAK,QAAoB,SAAS,CAAC;AAE5CC,QAAQ,CAAC,OAAO,EAAE,IAAM;IACtB,mDAAmD;IACnD,MAAMC,gBAAgB,GAAG,IAAkB;QACzC,OAAO;YACLC,UAAU,EAAE;gBACVC,IAAI,EAAE,OAAO;gBACbC,IAAI,EAAE;oBACJC,O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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<JsonObject>;
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 a PluginLoadingBoundary can be wrapped around this for fallback UI while
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,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAkB,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvE,oBAAY,iBAAiB,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;AAEvD;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,eAGpD"}
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
- import{jsx as _jsx}from"react/jsx-runtime";import{usePanelPlugin}from"@perses-dev/plugin-system";export function PanelContent(n){const{PanelComponent:e}=usePanelPlugin(n.definition.kind);return _jsx(e,{...n})}
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
- export*from"./Panel";
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
- declare const PanelDrawer: () => JSX.Element;
3
- export default PanelDrawer;
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":";AAuCA,QAAA,MAAM,WAAW,mBA0JhB,CAAC;AA2BF,eAAe,WAAW,CAAC"}
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
- 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,ErrorAlert}from"@perses-dev/components";import{PluginBoundary}from"@perses-dev/plugin-system";import{useState,useEffect}from"react";import{useDashboardApp,useLayouts,usePanels}from"../../context";import{removeWhiteSpacesAndSpecialCharacters}from"../../utils/functions";import{PanelOptionsEditor}from"./PanelOptionsEditor";const PanelDrawer=()=>{var e,l,n,a;const{layouts:r}=useLayouts(),{panels:i,updatePanel:t}=usePanels(),{panelDrawer:o,closePanelDrawer:s}=useDashboardApp();let d="",u="";(null==o?void 0:o.panelKey)&&(d=null!==(l=null===(e=i[o.panelKey])||void 0===e?void 0:e.display.name)&&void 0!==l?l:"",u=null!==(a=null===(n=i[o.panelKey])||void 0===n?void 0:n.display.description)&&void 0!==a?a:"");const[p,c]=useState(null==o?void 0:o.groupIndex),[x,v]=useState(d),[m,h]=useState(u),[y,g]=useState(""),[j,_]=useState({});useEffect((()=>{var e,l,n,a;c(null==o?void 0:o.groupIndex),(null==o?void 0:o.panelKey)?(v(null!==(l=null===(e=i[o.panelKey])||void 0===e?void 0:e.display.name)&&void 0!==l?l:""),h(null!==(a=null===(n=i[o.panelKey])||void 0===n?void 0:n.display.description)&&void 0!==a?a:"")):(v(""),h(""))}),[o,i]);return _jsx(Drawer,{isOpen:!!o,onClose:()=>s(),children:_jsxs("form",{onSubmit:e=>{e.preventDefault(),void 0===(null==o?void 0:o.groupIndex)||(null==o?void 0:o.panelKey)?(null==o?void 0:o.panelKey)&&(void 0!==(null==o?void 0:o.panelKey)&&t(o.panelKey,{...i[o.panelKey],kind:y,options:j,display:{name:null!=x?x:"",description:m}})):(()=>{if(void 0===(null==o?void 0:o.groupIndex))return;const e=removeWhiteSpacesAndSpecialCharacters(x);t(e,{kind:y,options:j,display:{name:x,description:m}},o.groupIndex)})(),s()},children:[_jsx(PanelDrawerHeader,{panelKey:null==o?void 0:o.panelKey,onClose:()=>s()}),_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:null!=p?p:0,onChange:e=>{const{value:l}=e.target;"string"!=typeof l&&c(l)},children:r.map(((e,l)=>{var n;return _jsx(MenuItem,{value:l,children:(null===(n=e.spec.display)||void 0===n?void 0:n.title)||`Group ${l+1}`},l)}))})]})}),_jsx(Grid,{item:!0,xs:8,children:_jsxs(Stack,{spacing:2,sx:{flexGrow:"1"},children:[_jsx(TextField,{required:!0,label:"Panel Name",value:x,variant:"outlined",onChange:e=>{v(e.target.value)}}),_jsx(TextField,{label:"Description",value:m,variant:"outlined",onChange:e=>{h(e.target.value)}})]})}),_jsx(Grid,{item:!0,xs:4,children:_jsxs(FormControl,{children:[_jsx(InputLabel,{id:"panel-type-label",children:"Panel Type"}),_jsxs(Select,{required:!0,labelId:"panel-type-label",label:"Panel Type",value:y,onChange:e=>{g(e.target.value)},children:[_jsx(MenuItem,{value:"LineChart",children:"Line Chart"}),_jsx(MenuItem,{value:"GaugeChart",children:"Gauge Chart"}),_jsx(MenuItem,{value:"StatChart",children:"Stat Chart"})]})]})}),_jsx(Grid,{item:!0,xs:8,children:_jsx(PluginBoundary,{loadingFallback:"Loading...",ErrorFallbackComponent:ErrorAlert,children:""!==y&&_jsx(PanelOptionsEditor,{kind:y,value:j,onChange:e=>{_(e)}})})})]})]})})},PanelDrawerHeader=({panelKey:e,onClose:l})=>_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:"h2",children:(e?"Edit":"Add")+" Panel"}),_jsxs(Stack,{direction:"row",spacing:1,sx:{marginLeft:"auto"},children:[_jsx(Button,{type:"submit",variant:"contained",children:e?"Apply":"Add"}),_jsx(Button,{variant:"outlined",onClick:l,children:"Cancel"})]})]});export default PanelDrawer;
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;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,SAASA,QAAQ,QAAQ,OAAO,CAAC;AACjC,SAASC,KAAK,EAAEC,GAAG,EAAEC,MAAM,EAAEC,UAAU,QAAQ,eAAe,CAAC;AAC/D,SAASC,MAAM,QAAQ,wBAAwB,CAAC;AAChD,SAASC,eAAe,QAAQ,eAAe,CAAC;AAChD,SAASC,mBAAmB,QAAQ,sBAAsB,CAAC;AAC3D,SAASC,eAAe,EAAEC,iBAAiB,QAA8B,mBAAmB,CAAC;AAE7F;;CAEC,GACD,OAAO,MAAMC,WAAW,GAAG,IAAM;IAC/B,MAAM,EAAEC,gBAAgB,CAAA,EAAE,GAAGL,eAAe,EAAE,AAAC;IAC/C,MAAMM,KAAK,GAAGL,mBAAmB,EAAE,AAAC;IAEpC,iHAAiH;IACjH,MAAM,CAACM,SAAS,EAAEC,YAAY,CAAC,GAAGd,QAAQ,CAAC,KAAK,CAAC,AAAC;IAClD,MAAMe,WAAW,GAAG,IAAMD,YAAY,CAAC,IAAI,CAAC,AAAC;IAE7C,uFAAuF;IACvF,MAAME,YAAY,GAAG,IAAM;QACzBL,gBAAgB,EAAE,CAAC;QACnBG,YAAY,CAAC,KAAK,CAAC,CAAC;IACtB,CAAC,AAAC;IAEF,oEAAoE;IACpE,MAAMG,MAAM,GAAGL,KAAK,KAAKM,SAAS,IAAIL,SAAS,KAAK,KAAK,AAAC;IAE1D,MAAMM,YAAY,GAAqC,CAACC,MAAM,GAAK;QACjE,kHAAkH;QAClH,IAAIR,KAAK,KAAKM,SAAS,EAAE;YACvB,M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iC,aAAa;kBAAI;;UAC9E,AACJ;MACM,CACT;AACJ,CAAC,CAAC"}
@@ -1 +1,103 @@
1
- import{jsx as _jsx,jsxs as _jsxs}from"react/jsx-runtime";import{PluginRegistry}from"@perses-dev/plugin-system";import{screen}from"@testing-library/react";import userEvent from"@testing-library/user-event";import*as dashboardAppSlice from"../../context/DashboardAppSlice";import*as layoutsSlice from"../../context/LayoutsSlice";import*as context from"../../context/DashboardProvider";import{FAKE_PANEL_PLUGIN,mockPluginRegistryProps,renderWithContext}from"../../test";import testDashboard from"../../test/testDashboard";import PanelDrawer from"./PanelDrawer";const updatePanel=jest.fn();jest.spyOn(context,"usePanels").mockReturnValue({updatePanel,panels:{}});const addItemToLayout=jest.fn();jest.spyOn(layoutsSlice,"useLayouts").mockReturnValue({addItemToLayout,updateLayout:jest.fn(),layouts:testDashboard.spec.layouts});const dashboardApp={panelDrawer:{groupIndex:0},openPanelDrawer:jest.fn(),closePanelDrawer:jest.fn(),panelGroupDialog:void 0,openPanelGroupDialog:jest.fn(),closePanelGroupDialog:jest.fn()};describe("Panel Drawer",(()=>{beforeEach((()=>{jest.clearAllMocks()}));const e=()=>{const{addMockPlugin:e,pluginRegistryProps:t}=mockPluginRegistryProps();e("Panel","FakePanel",FAKE_PANEL_PLUGIN),renderWithContext(_jsxs(PluginRegistry,{...t,children:[_jsx(PanelDrawer,{}),","]}))};it("should add new panel",(()=>{jest.spyOn(dashboardAppSlice,"useDashboardApp").mockReturnValue(dashboardApp),e();const t=screen.getByLabelText(/Panel Name/);userEvent.type(t,"New Panel"),userEvent.click(screen.getByText("Add")),expect(updatePanel).toHaveBeenCalledWith("NewPanel",{kind:"",display:{name:"New Panel",description:""},options:{}},0)})),it("should edit an existing panel",(()=>{jest.spyOn(dashboardAppSlice,"useDashboardApp").mockReturnValue({...dashboardApp,panelDrawer:{groupIndex:0,panelKey:"cpu"}}),e();const t=screen.getByLabelText(/Panel Name/);userEvent.type(t,"cpu usage"),userEvent.click(screen.getByText("Apply")),expect(updatePanel).toHaveBeenCalledWith("cpu",{display:{name:"cpu usage",description:""},kind:"",options:{}})}))}));
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