@perses-dev/dashboards 0.52.0-beta.5 → 0.52.0-rc.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/GridLayout/GridLayout.js +78 -126
- package/dist/cjs/components/GridLayout/Row.js +150 -0
- package/dist/cjs/components/GridLayout/index.js +1 -0
- package/dist/cjs/components/LeaveDialog/LeaveDialog.js +44 -0
- package/dist/cjs/components/LeaveDialog/index.js +30 -0
- package/dist/cjs/components/Panel/Panel.js +5 -1
- package/dist/cjs/components/Panel/PanelActions.js +3 -3
- package/dist/cjs/components/Panel/PanelHeader.js +32 -15
- package/dist/cjs/components/PanelDrawer/PanelDrawer.js +58 -21
- package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +3 -0
- package/dist/cjs/components/PanelGroupDialog/PanelGroupEditorForm.js +35 -15
- package/dist/cjs/components/index.js +1 -0
- package/dist/cjs/context/DashboardProvider/DashboardProvider.js +7 -8
- package/dist/cjs/context/DashboardProvider/DashboardProviderWithQueryParams.js +3 -3
- package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +1 -0
- package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +6 -2
- package/dist/cjs/context/DashboardProvider/panel-group-slice.js +1 -0
- package/dist/cjs/context/DashboardProvider/view-panel-slice.js +10 -3
- package/dist/cjs/context/VariableProvider/VariableProvider.js +1 -1
- package/dist/cjs/context/useDashboard.js +5 -4
- package/dist/cjs/views/ViewDashboard/DashboardApp.js +7 -3
- package/dist/cjs/views/ViewDashboard/ViewDashboard.js +9 -8
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +2 -2
- package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
- package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
- package/dist/components/GridLayout/GridLayout.d.ts +8 -0
- package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
- package/dist/components/GridLayout/GridLayout.js +72 -126
- package/dist/components/GridLayout/GridLayout.js.map +1 -1
- package/dist/components/GridLayout/Row.d.ts +17 -0
- package/dist/components/GridLayout/Row.d.ts.map +1 -0
- package/dist/components/GridLayout/Row.js +142 -0
- package/dist/components/GridLayout/Row.js.map +1 -0
- package/dist/components/GridLayout/index.d.ts +1 -0
- package/dist/components/GridLayout/index.d.ts.map +1 -1
- package/dist/components/GridLayout/index.js +1 -0
- package/dist/components/GridLayout/index.js.map +1 -1
- package/dist/components/LeaveDialog/LeaveDialog.d.ts +7 -0
- package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -0
- package/dist/components/LeaveDialog/LeaveDialog.js +36 -0
- package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -0
- package/dist/components/LeaveDialog/index.d.ts +2 -0
- package/dist/components/LeaveDialog/index.d.ts.map +1 -0
- package/dist/components/LeaveDialog/index.js +15 -0
- package/dist/components/LeaveDialog/index.js.map +1 -0
- package/dist/components/Panel/Panel.d.ts +5 -0
- package/dist/components/Panel/Panel.d.ts.map +1 -1
- package/dist/components/Panel/Panel.js +5 -1
- package/dist/components/Panel/Panel.js.map +1 -1
- package/dist/components/Panel/PanelActions.d.ts +2 -0
- package/dist/components/Panel/PanelActions.d.ts.map +1 -1
- package/dist/components/Panel/PanelActions.js +3 -3
- package/dist/components/Panel/PanelActions.js.map +1 -1
- package/dist/components/Panel/PanelHeader.d.ts +6 -1
- package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
- package/dist/components/Panel/PanelHeader.js +33 -16
- package/dist/components/Panel/PanelHeader.js.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
- package/dist/components/PanelDrawer/PanelDrawer.js +59 -22
- package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js +3 -0
- package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +1 -0
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -1
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +36 -16
- package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +1 -0
- package/dist/components/index.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.d.ts +5 -5
- package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
- package/dist/context/DashboardProvider/DashboardProvider.js +7 -8
- package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js +4 -4
- package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js.map +1 -1
- package/dist/context/DashboardProvider/common.d.ts +1 -1
- package/dist/context/DashboardProvider/common.d.ts.map +1 -1
- package/dist/context/DashboardProvider/common.js.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts +1 -0
- package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-editor-slice.js +1 -0
- package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +1 -0
- package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-editor-slice.js +6 -2
- package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.d.ts +3 -0
- package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/panel-group-slice.js +1 -0
- package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.d.ts +6 -2
- package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
- package/dist/context/DashboardProvider/view-panel-slice.js +10 -3
- package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
- package/dist/context/VariableProvider/VariableProvider.js +1 -1
- package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
- package/dist/context/useDashboard.js +5 -4
- package/dist/context/useDashboard.js.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -6
- package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
- package/dist/views/ViewDashboard/DashboardApp.js +8 -4
- package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
- package/dist/views/ViewDashboard/ViewDashboard.js +9 -8
- package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
- package/package.json +5 -5
|
@@ -10,63 +10,22 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx,
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { Collapse, useTheme } from '@mui/material';
|
|
17
|
-
import { ErrorAlert, ErrorBoundary } from '@perses-dev/components';
|
|
13
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { useState } from 'react';
|
|
15
|
+
import { useVariableValues, VariableContext } from '@perses-dev/plugin-system';
|
|
18
16
|
import { useEditMode, usePanelGroup, usePanelGroupActions, useViewPanelGroup } from '../../context';
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { GridItemContent } from './GridItemContent';
|
|
22
|
-
import { GridContainer } from './GridContainer';
|
|
23
|
-
const DEFAULT_MARGIN = 10;
|
|
24
|
-
const ROW_HEIGHT = 30;
|
|
17
|
+
import { GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';
|
|
18
|
+
import { Row } from './Row';
|
|
25
19
|
/**
|
|
26
20
|
* Layout component that arranges children in a Grid based on the definition.
|
|
27
21
|
*/ export function GridLayout(props) {
|
|
28
22
|
const { panelGroupId, panelOptions, panelFullHeight } = props;
|
|
29
|
-
const theme = useTheme();
|
|
30
23
|
const groupDefinition = usePanelGroup(panelGroupId);
|
|
31
24
|
const { updatePanelGroupLayouts } = usePanelGroupActions(panelGroupId);
|
|
32
|
-
const
|
|
25
|
+
const viewPanelItemId = useViewPanelGroup();
|
|
33
26
|
const { isEditMode } = useEditMode();
|
|
34
27
|
const [gridColWidth, setGridColWidth] = useState(0);
|
|
35
|
-
const viewPanelItemId = useViewPanelGroup();
|
|
36
28
|
const hasViewPanel = viewPanelItemId?.panelGroupId === panelGroupId; // current panelGroup contains the panel extended?
|
|
37
|
-
const itemLayoutViewed = viewPanelItemId?.panelGroupItemLayoutId;
|
|
38
|
-
useEffect(()=>{
|
|
39
|
-
if (hasViewPanel) {
|
|
40
|
-
setIsOpen(true);
|
|
41
|
-
}
|
|
42
|
-
}, [
|
|
43
|
-
hasViewPanel
|
|
44
|
-
]);
|
|
45
|
-
// If there is a panel in view mode, we should hide the grid if the panel is not in the current group.
|
|
46
|
-
const isGridDisplayed = viewPanelItemId === undefined || hasViewPanel;
|
|
47
|
-
// Item layout is override if there is a panel in view mode
|
|
48
|
-
const itemLayouts = useMemo(()=>{
|
|
49
|
-
if (itemLayoutViewed) {
|
|
50
|
-
return groupDefinition.itemLayouts.map((itemLayout)=>{
|
|
51
|
-
if (itemLayout.i === itemLayoutViewed) {
|
|
52
|
-
const rowTitleHeight = 40 + 8; // 40 is the height of the row title and 8 is the margin height
|
|
53
|
-
return {
|
|
54
|
-
h: Math.round(((panelFullHeight ?? window.innerHeight) - rowTitleHeight) / (ROW_HEIGHT + DEFAULT_MARGIN)),
|
|
55
|
-
i: itemLayoutViewed,
|
|
56
|
-
w: 48,
|
|
57
|
-
x: 0,
|
|
58
|
-
y: 0
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
return itemLayout;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
return groupDefinition.itemLayouts;
|
|
65
|
-
}, [
|
|
66
|
-
groupDefinition.itemLayouts,
|
|
67
|
-
itemLayoutViewed,
|
|
68
|
-
panelFullHeight
|
|
69
|
-
]);
|
|
70
29
|
const handleLayoutChange = (currentLayout, allLayouts)=>{
|
|
71
30
|
// Using the value from `allLayouts` instead of `currentLayout` because of
|
|
72
31
|
// a bug in react-layout-grid where `currentLayout` does not adjust properly
|
|
@@ -87,87 +46,74 @@ const ROW_HEIGHT = 30;
|
|
|
87
46
|
// exclude margin and padding from total width
|
|
88
47
|
setGridColWidth((containerWidth - marginWidth - containerPaddingWidth) / cols);
|
|
89
48
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
"data-testid": "panel-group-content",
|
|
112
|
-
children: /*#__PURE__*/ _jsx(ResponsiveGridLayout, {
|
|
113
|
-
className: "layout",
|
|
114
|
-
breakpoints: {
|
|
115
|
-
sm: theme.breakpoints.values.sm,
|
|
116
|
-
xxs: 0
|
|
117
|
-
},
|
|
118
|
-
cols: GRID_LAYOUT_COLS,
|
|
119
|
-
rowHeight: ROW_HEIGHT,
|
|
120
|
-
draggableHandle: ".drag-handle",
|
|
121
|
-
resizeHandles: [
|
|
122
|
-
'se'
|
|
123
|
-
],
|
|
124
|
-
isDraggable: isEditMode && !hasViewPanel,
|
|
125
|
-
isResizable: isEditMode && !hasViewPanel,
|
|
126
|
-
margin: [
|
|
127
|
-
DEFAULT_MARGIN,
|
|
128
|
-
DEFAULT_MARGIN
|
|
129
|
-
],
|
|
130
|
-
containerPadding: [
|
|
131
|
-
0,
|
|
132
|
-
10
|
|
133
|
-
],
|
|
134
|
-
layouts: {
|
|
135
|
-
[GRID_LAYOUT_SMALL_BREAKPOINT]: itemLayouts
|
|
136
|
-
},
|
|
137
|
-
onLayoutChange: handleLayoutChange,
|
|
138
|
-
onWidthChange: handleWidthChange,
|
|
139
|
-
allowOverlap: hasViewPanel,
|
|
140
|
-
children: itemLayouts.map(({ i, w })=>/*#__PURE__*/ _jsx("div", {
|
|
141
|
-
style: {
|
|
142
|
-
display: itemLayoutViewed !== undefined ? itemLayoutViewed === i ? 'unset' : 'none' : 'unset'
|
|
143
|
-
},
|
|
144
|
-
children: /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
145
|
-
FallbackComponent: ErrorAlert,
|
|
146
|
-
children: /*#__PURE__*/ _jsx(GridItemContent, {
|
|
147
|
-
panelOptions: panelOptions,
|
|
148
|
-
panelGroupItemId: {
|
|
149
|
-
panelGroupId,
|
|
150
|
-
panelGroupItemLayoutId: i
|
|
151
|
-
},
|
|
152
|
-
width: calculateGridItemWidth(w, gridColWidth)
|
|
153
|
-
})
|
|
154
|
-
})
|
|
155
|
-
}, i))
|
|
156
|
-
})
|
|
157
|
-
})
|
|
158
|
-
]
|
|
49
|
+
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
50
|
+
children: !groupDefinition.repeatVariable ? /*#__PURE__*/ _jsx(Row, {
|
|
51
|
+
panelGroupId: panelGroupId,
|
|
52
|
+
groupDefinition: groupDefinition,
|
|
53
|
+
gridColWidth: gridColWidth,
|
|
54
|
+
panelFullHeight: panelFullHeight,
|
|
55
|
+
panelOptions: panelOptions,
|
|
56
|
+
isEditMode: isEditMode,
|
|
57
|
+
onLayoutChange: handleLayoutChange,
|
|
58
|
+
onWidthChange: handleWidthChange
|
|
59
|
+
}) : /*#__PURE__*/ _jsx(RepeatGridLayout, {
|
|
60
|
+
repeatVariableName: groupDefinition.repeatVariable,
|
|
61
|
+
panelGroupId: panelGroupId,
|
|
62
|
+
groupDefinition: groupDefinition,
|
|
63
|
+
gridColWidth: gridColWidth,
|
|
64
|
+
panelFullHeight: panelFullHeight,
|
|
65
|
+
panelOptions: panelOptions,
|
|
66
|
+
isEditMode: isEditMode,
|
|
67
|
+
onLayoutChange: handleLayoutChange,
|
|
68
|
+
onWidthChange: handleWidthChange
|
|
69
|
+
})
|
|
159
70
|
});
|
|
160
71
|
}
|
|
161
72
|
/**
|
|
162
|
-
*
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
73
|
+
* Renders a grid layout for a repeated variable, where each value of the variable will create a new row.
|
|
74
|
+
*/ export function RepeatGridLayout({ repeatVariableName, panelGroupId, groupDefinition, gridColWidth, panelFullHeight, panelOptions, isEditMode = false, onLayoutChange, onWidthChange }) {
|
|
75
|
+
const variables = useVariableValues();
|
|
76
|
+
const variable = variables[repeatVariableName];
|
|
77
|
+
// If the variable is not defined, or if it is defined but has no values, render a standard row without repeating
|
|
78
|
+
if (variable === undefined || !Array.isArray(variable.value) || variable.value.length === 0) {
|
|
79
|
+
return /*#__PURE__*/ _jsx(Row, {
|
|
80
|
+
panelGroupId: panelGroupId,
|
|
81
|
+
groupDefinition: groupDefinition,
|
|
82
|
+
gridColWidth: gridColWidth,
|
|
83
|
+
panelFullHeight: panelFullHeight,
|
|
84
|
+
panelOptions: panelOptions,
|
|
85
|
+
isEditMode: isEditMode,
|
|
86
|
+
onLayoutChange: onLayoutChange,
|
|
87
|
+
onWidthChange: onWidthChange
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return /*#__PURE__*/ _jsx(_Fragment, {
|
|
91
|
+
children: variable.value.map((value)=>/*#__PURE__*/ _jsx(VariableContext.Provider, {
|
|
92
|
+
value: {
|
|
93
|
+
state: {
|
|
94
|
+
...variables,
|
|
95
|
+
[repeatVariableName]: {
|
|
96
|
+
value,
|
|
97
|
+
loading: false
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
children: /*#__PURE__*/ _jsx(Row, {
|
|
102
|
+
panelGroupId: panelGroupId,
|
|
103
|
+
groupDefinition: groupDefinition,
|
|
104
|
+
gridColWidth: gridColWidth,
|
|
105
|
+
panelFullHeight: panelFullHeight,
|
|
106
|
+
panelOptions: panelOptions,
|
|
107
|
+
isEditMode: isEditMode,
|
|
108
|
+
onLayoutChange: onLayoutChange,
|
|
109
|
+
onWidthChange: onWidthChange,
|
|
110
|
+
repeatVariable: [
|
|
111
|
+
repeatVariableName,
|
|
112
|
+
value
|
|
113
|
+
]
|
|
114
|
+
})
|
|
115
|
+
}, `${repeatVariableName}-${value}`))
|
|
116
|
+
});
|
|
117
|
+
}
|
|
172
118
|
|
|
173
119
|
//# sourceMappingURL=GridLayout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/GridLayout/GridLayout.tsx"],"sourcesContent":["// Copyright 2023 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.\nimport { ReactElement, useEffect, useMemo, useState } from 'react';\nimport { Responsive, WidthProvider, Layouts, Layout } from 'react-grid-layout';\nimport { Collapse, useTheme } from '@mui/material';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { PanelGroupId } from '@perses-dev/core';\nimport {\n useEditMode,\n usePanelGroup,\n usePanelGroupActions,\n PanelGroupItemLayout,\n useViewPanelGroup,\n PanelGroupDefinition,\n} from '../../context';\nimport { GRID_LAYOUT_COLS, GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';\nimport { PanelOptions } from '../Panel';\nimport { GridTitle } from './GridTitle';\nimport { GridItemContent } from './GridItemContent';\nimport { GridContainer } from './GridContainer';\nconst DEFAULT_MARGIN = 10;\nconst ROW_HEIGHT = 30;\n\nexport interface GridLayoutProps {\n panelGroupId: PanelGroupId;\n panelOptions?: PanelOptions;\n panelFullHeight?: number;\n}\n\n/**\n * Layout component that arranges children in a Grid based on the definition.\n */\nexport function GridLayout(props: GridLayoutProps): ReactElement {\n const { panelGroupId, panelOptions, panelFullHeight } = props;\n const theme = useTheme();\n const groupDefinition: PanelGroupDefinition = usePanelGroup(panelGroupId);\n const { updatePanelGroupLayouts } = usePanelGroupActions(panelGroupId);\n\n const [isOpen, setIsOpen] = useState(!groupDefinition.isCollapsed);\n const { isEditMode } = useEditMode();\n\n const [gridColWidth, setGridColWidth] = useState(0);\n\n const viewPanelItemId = useViewPanelGroup();\n const hasViewPanel = viewPanelItemId?.panelGroupId === panelGroupId; // current panelGroup contains the panel extended?\n const itemLayoutViewed = viewPanelItemId?.panelGroupItemLayoutId;\n\n useEffect(() => {\n if (hasViewPanel) {\n setIsOpen(true);\n }\n }, [hasViewPanel]);\n\n // If there is a panel in view mode, we should hide the grid if the panel is not in the current group.\n const isGridDisplayed = viewPanelItemId === undefined || hasViewPanel;\n\n // Item layout is override if there is a panel in view mode\n const itemLayouts: PanelGroupItemLayout[] = useMemo(() => {\n if (itemLayoutViewed) {\n return groupDefinition.itemLayouts.map((itemLayout) => {\n if (itemLayout.i === itemLayoutViewed) {\n const rowTitleHeight = 40 + 8; // 40 is the height of the row title and 8 is the margin height\n return {\n h: Math.round(((panelFullHeight ?? window.innerHeight) - rowTitleHeight) / (ROW_HEIGHT + DEFAULT_MARGIN)), // Viewed panel should take the full height remaining\n i: itemLayoutViewed,\n w: 48,\n x: 0,\n y: 0,\n } as PanelGroupItemLayout;\n }\n return itemLayout;\n });\n }\n return groupDefinition.itemLayouts;\n }, [groupDefinition.itemLayouts, itemLayoutViewed, panelFullHeight]);\n\n const handleLayoutChange = (currentLayout: Layout[], allLayouts: Layouts): void => {\n // Using the value from `allLayouts` instead of `currentLayout` because of\n // a bug in react-layout-grid where `currentLayout` does not adjust properly\n // when going to a smaller breakpoint and then back to a larger breakpoint.\n // https://github.com/react-grid-layout/react-grid-layout/issues/1663\n const smallLayout = allLayouts[GRID_LAYOUT_SMALL_BREAKPOINT];\n if (smallLayout && !hasViewPanel) {\n updatePanelGroupLayouts(smallLayout);\n }\n };\n\n /**\n * Calculate the column width so we can determine the width of each panel for suggested step ms\n * https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35\n */\n const handleWidthChange = (\n containerWidth: number,\n margin: [number, number],\n cols: number,\n containerPadding: [number, number]\n ): void => {\n const marginX = margin[0];\n const marginWidth = marginX * (cols - 1);\n const containerPaddingWidth = containerPadding[0] * 2;\n // exclude margin and padding from total width\n setGridColWidth((containerWidth - marginWidth - containerPaddingWidth) / cols);\n };\n\n // https://github.com/react-grid-layout/react-grid-layout?tab=readme-ov-file#react-hooks-performance\n const ResponsiveGridLayout = useMemo(() => WidthProvider(Responsive), []);\n\n return (\n <GridContainer\n sx={{\n display: isGridDisplayed ? 'block' : 'none',\n height: itemLayoutViewed ? `${panelFullHeight}px` : 'unset',\n overflow: itemLayoutViewed ? 'hidden' : 'unset',\n }}\n >\n {groupDefinition.title !== undefined && (\n <GridTitle\n panelGroupId={panelGroupId}\n title={groupDefinition.title}\n collapse={\n groupDefinition.isCollapsed === undefined\n ? undefined\n : { isOpen, onToggleOpen: () => setIsOpen((current) => !current) }\n }\n />\n )}\n <Collapse in={isOpen} unmountOnExit appear={false} data-testid=\"panel-group-content\">\n <ResponsiveGridLayout\n className=\"layout\"\n breakpoints={{ sm: theme.breakpoints.values.sm, xxs: 0 }}\n cols={GRID_LAYOUT_COLS}\n rowHeight={ROW_HEIGHT}\n draggableHandle=\".drag-handle\"\n resizeHandles={['se']}\n isDraggable={isEditMode && !hasViewPanel}\n isResizable={isEditMode && !hasViewPanel}\n margin={[DEFAULT_MARGIN, DEFAULT_MARGIN]}\n containerPadding={[0, 10]}\n layouts={{ [GRID_LAYOUT_SMALL_BREAKPOINT]: itemLayouts }}\n onLayoutChange={handleLayoutChange}\n onWidthChange={handleWidthChange}\n allowOverlap={hasViewPanel} // Enabling overlap when viewing a specific panel because panel in front of the viewed panel will add empty spaces (empty row height)\n >\n {itemLayouts.map(({ i, w }) => (\n <div\n key={i}\n style={{\n display: itemLayoutViewed !== undefined ? (itemLayoutViewed === i ? 'unset' : 'none') : 'unset',\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <GridItemContent\n panelOptions={panelOptions}\n panelGroupItemId={{ panelGroupId, panelGroupItemLayoutId: i }}\n width={calculateGridItemWidth(w, gridColWidth)}\n />\n </ErrorBoundary>\n </div>\n ))}\n </ResponsiveGridLayout>\n </Collapse>\n </GridContainer>\n );\n}\n\n/**\n * Calculates grid item width\n * @param w number of columns the grid item spans\n * @param colWidth the width of each column in px\n * @returns grid item's width in px\n * https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35\n */\nconst calculateGridItemWidth = (w: number, colWidth: number): number => {\n // 0 * Infinity === NaN, which causes problems with resize contraints\n if (!Number.isFinite(w)) return w;\n return Math.round(colWidth * w + Math.max(0, w - 1) * DEFAULT_MARGIN);\n};\n"],"names":["useEffect","useMemo","useState","Responsive","WidthProvider","Collapse","useTheme","ErrorAlert","ErrorBoundary","useEditMode","usePanelGroup","usePanelGroupActions","useViewPanelGroup","GRID_LAYOUT_COLS","GRID_LAYOUT_SMALL_BREAKPOINT","GridTitle","GridItemContent","GridContainer","DEFAULT_MARGIN","ROW_HEIGHT","GridLayout","props","panelGroupId","panelOptions","panelFullHeight","theme","groupDefinition","updatePanelGroupLayouts","isOpen","setIsOpen","isCollapsed","isEditMode","gridColWidth","setGridColWidth","viewPanelItemId","hasViewPanel","itemLayoutViewed","panelGroupItemLayoutId","isGridDisplayed","undefined","itemLayouts","map","itemLayout","i","rowTitleHeight","h","Math","round","window","innerHeight","w","x","y","handleLayoutChange","currentLayout","allLayouts","smallLayout","handleWidthChange","containerWidth","margin","cols","containerPadding","marginX","marginWidth","containerPaddingWidth","ResponsiveGridLayout","sx","display","height","overflow","title","collapse","onToggleOpen","current","in","unmountOnExit","appear","data-testid","className","breakpoints","sm","values","xxs","rowHeight","draggableHandle","resizeHandles","isDraggable","isResizable","layouts","onLayoutChange","onWidthChange","allowOverlap","div","style","FallbackComponent","panelGroupItemId","width","calculateGridItemWidth","colWidth","Number","isFinite","max"],"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;;AACjC,SAAuBA,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACnE,SAASC,UAAU,EAAEC,aAAa,QAAyB,oBAAoB;AAC/E,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,gBAAgB;AACnD,SAASC,UAAU,EAAEC,aAAa,QAAQ,yBAAyB;AAEnE,SACEC,WAAW,EACXC,aAAa,EACbC,oBAAoB,EAEpBC,iBAAiB,QAEZ,gBAAgB;AACvB,SAASC,gBAAgB,EAAEC,4BAA4B,QAAQ,kBAAkB;AAEjF,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,aAAa,QAAQ,kBAAkB;AAChD,MAAMC,iBAAiB;AACvB,MAAMC,aAAa;AAQnB;;CAEC,GACD,OAAO,SAASC,WAAWC,KAAsB;IAC/C,MAAM,EAAEC,YAAY,EAAEC,YAAY,EAAEC,eAAe,EAAE,GAAGH;IACxD,MAAMI,QAAQnB;IACd,MAAMoB,kBAAwChB,cAAcY;IAC5D,MAAM,EAAEK,uBAAuB,EAAE,GAAGhB,qBAAqBW;IAEzD,MAAM,CAACM,QAA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ACxB,KAAC0C;4BAECC,OAAO;gCACL1B,SAAS/B,qBAAqBG,YAAaH,qBAAqBO,IAAI,UAAU,SAAU;4BAC1F;sCAEA,cAAA,KAACnC;gCAAcsF,mBAAmBvF;0CAChC,cAAA,KAACS;oCACCO,cAAcA;oCACdwE,kBAAkB;wCAAEzE;wCAAce,wBAAwBM;oCAAE;oCAC5DqD,OAAOC,uBAAuB/C,GAAGlB;;;2BAThCW;;;;;AAkBnB;AAEA;;;;;;CAMC,GACD,MAAMsD,yBAAyB,CAAC/C,GAAWgD;IACzC,qEAAqE;IACrE,IAAI,CAACC,OAAOC,QAAQ,CAAClD,IAAI,OAAOA;IAChC,OAAOJ,KAAKC,KAAK,CAACmD,WAAWhD,IAAIJ,KAAKuD,GAAG,CAAC,GAAGnD,IAAI,KAAKhC;AACxD"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/GridLayout/GridLayout.tsx"],"sourcesContent":["// Copyright 2023 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.\nimport { ReactElement, useState } from 'react';\nimport { Layouts, Layout } from 'react-grid-layout';\nimport { PanelGroupId } from '@perses-dev/core';\nimport { useVariableValues, VariableContext } from '@perses-dev/plugin-system';\nimport {\n useEditMode,\n usePanelGroup,\n usePanelGroupActions,\n useViewPanelGroup,\n PanelGroupDefinition,\n} from '../../context';\nimport { GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';\nimport { PanelOptions } from '../Panel';\nimport { Row, RowProps } from './Row';\n\nexport interface GridLayoutProps {\n panelGroupId: PanelGroupId;\n panelOptions?: PanelOptions;\n panelFullHeight?: number;\n}\n\n/**\n * Layout component that arranges children in a Grid based on the definition.\n */\nexport function GridLayout(props: GridLayoutProps): ReactElement {\n const { panelGroupId, panelOptions, panelFullHeight } = props;\n const groupDefinition: PanelGroupDefinition = usePanelGroup(panelGroupId);\n const { updatePanelGroupLayouts } = usePanelGroupActions(panelGroupId);\n const viewPanelItemId = useViewPanelGroup();\n const { isEditMode } = useEditMode();\n\n const [gridColWidth, setGridColWidth] = useState(0);\n\n const hasViewPanel = viewPanelItemId?.panelGroupId === panelGroupId; // current panelGroup contains the panel extended?\n\n const handleLayoutChange = (currentLayout: Layout[], allLayouts: Layouts): void => {\n // Using the value from `allLayouts` instead of `currentLayout` because of\n // a bug in react-layout-grid where `currentLayout` does not adjust properly\n // when going to a smaller breakpoint and then back to a larger breakpoint.\n // https://github.com/react-grid-layout/react-grid-layout/issues/1663\n const smallLayout = allLayouts[GRID_LAYOUT_SMALL_BREAKPOINT];\n if (smallLayout && !hasViewPanel) {\n updatePanelGroupLayouts(smallLayout);\n }\n };\n\n /**\n * Calculate the column width so we can determine the width of each panel for suggested step ms\n * https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35\n */\n const handleWidthChange = (\n containerWidth: number,\n margin: [number, number],\n cols: number,\n containerPadding: [number, number]\n ): void => {\n const marginX = margin[0];\n const marginWidth = marginX * (cols - 1);\n const containerPaddingWidth = containerPadding[0] * 2;\n // exclude margin and padding from total width\n setGridColWidth((containerWidth - marginWidth - containerPaddingWidth) / cols);\n };\n\n return (\n <>\n {!groupDefinition.repeatVariable ? (\n <Row\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={handleLayoutChange}\n onWidthChange={handleWidthChange}\n />\n ) : (\n <RepeatGridLayout\n repeatVariableName={groupDefinition.repeatVariable}\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={handleLayoutChange}\n onWidthChange={handleWidthChange}\n />\n )}\n </>\n );\n}\n\nexport interface RepeatGridLayoutProps extends RowProps {\n repeatVariableName: string;\n}\n\n/**\n * Renders a grid layout for a repeated variable, where each value of the variable will create a new row.\n */\nexport function RepeatGridLayout({\n repeatVariableName,\n panelGroupId,\n groupDefinition,\n gridColWidth,\n panelFullHeight,\n panelOptions,\n isEditMode = false,\n onLayoutChange,\n onWidthChange,\n}: RepeatGridLayoutProps): ReactElement | null {\n const variables = useVariableValues();\n const variable = variables[repeatVariableName];\n\n // If the variable is not defined, or if it is defined but has no values, render a standard row without repeating\n if (variable === undefined || !Array.isArray(variable.value) || variable.value.length === 0) {\n return (\n <Row\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={onLayoutChange}\n onWidthChange={onWidthChange}\n />\n );\n }\n\n return (\n <>\n {variable.value.map((value) => (\n <VariableContext.Provider\n key={`${repeatVariableName}-${value}`}\n value={{ state: { ...variables, [repeatVariableName]: { value, loading: false } } }}\n >\n <Row\n panelGroupId={panelGroupId}\n groupDefinition={groupDefinition}\n gridColWidth={gridColWidth}\n panelFullHeight={panelFullHeight}\n panelOptions={panelOptions}\n isEditMode={isEditMode}\n onLayoutChange={onLayoutChange}\n onWidthChange={onWidthChange}\n repeatVariable={[repeatVariableName, value]}\n />\n </VariableContext.Provider>\n ))}\n </>\n );\n}\n"],"names":["useState","useVariableValues","VariableContext","useEditMode","usePanelGroup","usePanelGroupActions","useViewPanelGroup","GRID_LAYOUT_SMALL_BREAKPOINT","Row","GridLayout","props","panelGroupId","panelOptions","panelFullHeight","groupDefinition","updatePanelGroupLayouts","viewPanelItemId","isEditMode","gridColWidth","setGridColWidth","hasViewPanel","handleLayoutChange","currentLayout","allLayouts","smallLayout","handleWidthChange","containerWidth","margin","cols","containerPadding","marginX","marginWidth","containerPaddingWidth","repeatVariable","onLayoutChange","onWidthChange","RepeatGridLayout","repeatVariableName","variables","variable","undefined","Array","isArray","value","length","map","Provider","state","loading"],"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;;AACjC,SAAuBA,QAAQ,QAAQ,QAAQ;AAG/C,SAASC,iBAAiB,EAAEC,eAAe,QAAQ,4BAA4B;AAC/E,SACEC,WAAW,EACXC,aAAa,EACbC,oBAAoB,EACpBC,iBAAiB,QAEZ,gBAAgB;AACvB,SAASC,4BAA4B,QAAQ,kBAAkB;AAE/D,SAASC,GAAG,QAAkB,QAAQ;AAQtC;;CAEC,GACD,OAAO,SAASC,WAAWC,KAAsB;IAC/C,MAAM,EAAEC,YAAY,EAAEC,YAAY,EAAEC,eAAe,EAAE,GAAGH;IACxD,MAAMI,kBAAwCV,cAAcO;IAC5D,MAAM,EAAEI,uBAAuB,EAAE,GAAGV,qBAAqBM;IACzD,MAAMK,kBAAkBV;IACxB,MAAM,EAAEW,UAAU,EAAE,GAAGd;IAEvB,MAAM,CAACe,cAAcC,gBAAgB,GAAGnB,SAAS;IAEjD,MAAMoB,eAAeJ,iBAAiBL,iBAAiBA,cAAc,kDAAkD;IAEvH,MAAMU,qBAAqB,CAACC,eAAyBC;QACnD,0EAA0E;QAC1E,4EAA4E;QAC5E,2EAA2E;QAC3E,qEAAqE;QACrE,MAAMC,cAAcD,UAAU,CAAChB,6BAA6B;QAC5D,IAAIiB,eAAe,CAACJ,cAAc;YAChCL,wBAAwBS;QAC1B;IACF;IAEA;;;GAGC,GACD,MAAMC,oBAAoB,CACxBC,gBACAC,QACAC,MACAC;QAEA,MAAMC,UAAUH,MAAM,CAAC,EAAE;QACzB,MAA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AAE;0BAElF,cAAA,KAACxC;oBACCG,cAAcA;oBACdG,iBAAiBA;oBACjBI,cAAcA;oBACdL,iBAAiBA;oBACjBD,cAAcA;oBACdK,YAAYA;oBACZiB,gBAAgBA;oBAChBC,eAAeA;oBACfF,gBAAgB;wBAACI;wBAAoBM;qBAAM;;eAZxC,GAAGN,mBAAmB,CAAC,EAAEM,OAAO;;AAkB/C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { PanelGroupId } from '@perses-dev/core';
|
|
2
|
+
import { PanelGroupDefinition, PanelOptions } from '@perses-dev/dashboards';
|
|
3
|
+
import { ReactElement } from 'react';
|
|
4
|
+
import { Layout, Layouts } from 'react-grid-layout';
|
|
5
|
+
export interface RowProps {
|
|
6
|
+
panelGroupId: PanelGroupId;
|
|
7
|
+
groupDefinition: PanelGroupDefinition;
|
|
8
|
+
gridColWidth: number;
|
|
9
|
+
panelFullHeight?: number;
|
|
10
|
+
panelOptions?: PanelOptions;
|
|
11
|
+
isEditMode?: boolean;
|
|
12
|
+
onLayoutChange?: (currentLayout: Layout[], allLayouts: Layouts) => void;
|
|
13
|
+
onWidthChange?: (containerWidth: number, margin: [number, number], cols: number, containerPadding: [number, number]) => void;
|
|
14
|
+
repeatVariable?: [string, string];
|
|
15
|
+
}
|
|
16
|
+
export declare function Row({ panelGroupId, groupDefinition, gridColWidth, panelFullHeight, panelOptions, isEditMode, onLayoutChange, onWidthChange, repeatVariable, }: RowProps): ReactElement;
|
|
17
|
+
//# sourceMappingURL=Row.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Row.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/Row.tsx"],"names":[],"mappings":"AAcA,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAwB,YAAY,EAAqB,MAAM,wBAAwB,CAAC;AACrH,OAAO,EAAE,YAAY,EAAgC,MAAM,OAAO,CAAC;AACnE,OAAO,EAAE,MAAM,EAAE,OAAO,EAA6B,MAAM,mBAAmB,CAAC;AAU/E,MAAM,WAAW,QAAQ;IACvB,YAAY,EAAE,YAAY,CAAC;IAC3B,eAAe,EAAE,oBAAoB,CAAC;IACtC,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,CAAC,EAAE,CAAC,aAAa,EAAE,MAAM,EAAE,EAAE,UAAU,EAAE,OAAO,KAAK,IAAI,CAAC;IACxE,aAAa,CAAC,EAAE,CACd,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACxB,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,KAC/B,IAAI,CAAC;IACV,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,wBAAgB,GAAG,CAAC,EAClB,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,eAAe,EACf,YAAY,EACZ,UAAkB,EAClB,cAAc,EACd,aAAa,EACb,cAAc,GACf,EAAE,QAAQ,GAAG,YAAY,CAoGzB"}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// Copyright 2025 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 { Collapse, useTheme } from '@mui/material';
|
|
15
|
+
import { useViewPanelGroup } from '@perses-dev/dashboards';
|
|
16
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
17
|
+
import { Responsive, WidthProvider } from 'react-grid-layout';
|
|
18
|
+
import { ErrorAlert, ErrorBoundary } from '@perses-dev/components';
|
|
19
|
+
import { GRID_LAYOUT_COLS, GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';
|
|
20
|
+
import { GridContainer } from './GridContainer';
|
|
21
|
+
import { GridItemContent } from './GridItemContent';
|
|
22
|
+
import { GridTitle } from './GridTitle';
|
|
23
|
+
const DEFAULT_MARGIN = 10;
|
|
24
|
+
const ROW_HEIGHT = 30;
|
|
25
|
+
export function Row({ panelGroupId, groupDefinition, gridColWidth, panelFullHeight, panelOptions, isEditMode = false, onLayoutChange, onWidthChange, repeatVariable }) {
|
|
26
|
+
const ResponsiveGridLayout = useMemo(()=>WidthProvider(Responsive), []);
|
|
27
|
+
const theme = useTheme();
|
|
28
|
+
const viewPanelItemId = useViewPanelGroup();
|
|
29
|
+
const [isOpen, setIsOpen] = useState(!groupDefinition.isCollapsed);
|
|
30
|
+
const hasViewPanel = viewPanelItemId?.panelGroupId === panelGroupId && // Check for repeatVariable panels
|
|
31
|
+
viewPanelItemId.repeatVariable?.[0] === repeatVariable?.[0] && viewPanelItemId.repeatVariable?.[1] === repeatVariable?.[1];
|
|
32
|
+
const itemLayoutViewed = viewPanelItemId?.panelGroupItemLayoutId;
|
|
33
|
+
// If there is a panel in view mode, we should hide the grid if the panel is not in the current group.
|
|
34
|
+
const isGridDisplayed = !viewPanelItemId || hasViewPanel;
|
|
35
|
+
// TODO: handle it without useEffect
|
|
36
|
+
useEffect(()=>{
|
|
37
|
+
if (hasViewPanel) {
|
|
38
|
+
setIsOpen(true);
|
|
39
|
+
}
|
|
40
|
+
}, [
|
|
41
|
+
hasViewPanel
|
|
42
|
+
]);
|
|
43
|
+
// Item layout is override if there is a panel in view mode
|
|
44
|
+
const itemLayouts = useMemo(()=>{
|
|
45
|
+
if (itemLayoutViewed) {
|
|
46
|
+
return groupDefinition.itemLayouts.map((itemLayout)=>{
|
|
47
|
+
if (itemLayout.i === itemLayoutViewed) {
|
|
48
|
+
const rowTitleHeight = 40 + 8; // 40 is the height of the row title and 8 is the margin height
|
|
49
|
+
return {
|
|
50
|
+
h: Math.round(((panelFullHeight ?? window.innerHeight) - rowTitleHeight) / (ROW_HEIGHT + DEFAULT_MARGIN)),
|
|
51
|
+
i: itemLayoutViewed,
|
|
52
|
+
w: 48,
|
|
53
|
+
x: 0,
|
|
54
|
+
y: 0
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return itemLayout;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
return groupDefinition.itemLayouts;
|
|
61
|
+
}, [
|
|
62
|
+
groupDefinition.itemLayouts,
|
|
63
|
+
itemLayoutViewed,
|
|
64
|
+
panelFullHeight
|
|
65
|
+
]);
|
|
66
|
+
return /*#__PURE__*/ _jsxs(GridContainer, {
|
|
67
|
+
sx: {
|
|
68
|
+
display: isGridDisplayed ? 'block' : 'none',
|
|
69
|
+
height: itemLayoutViewed ? `${panelFullHeight}px` : 'unset',
|
|
70
|
+
overflow: itemLayoutViewed ? 'hidden' : 'unset'
|
|
71
|
+
},
|
|
72
|
+
children: [
|
|
73
|
+
groupDefinition.title && /*#__PURE__*/ _jsx(GridTitle, {
|
|
74
|
+
panelGroupId: panelGroupId,
|
|
75
|
+
title: groupDefinition.title,
|
|
76
|
+
collapse: groupDefinition.isCollapsed === undefined ? undefined : {
|
|
77
|
+
isOpen: isOpen,
|
|
78
|
+
onToggleOpen: ()=>setIsOpen((current)=>!current)
|
|
79
|
+
}
|
|
80
|
+
}),
|
|
81
|
+
/*#__PURE__*/ _jsx(Collapse, {
|
|
82
|
+
in: isOpen,
|
|
83
|
+
unmountOnExit: true,
|
|
84
|
+
appear: false,
|
|
85
|
+
"data-testid": "panel-group-content",
|
|
86
|
+
children: /*#__PURE__*/ _jsx(ResponsiveGridLayout, {
|
|
87
|
+
className: "layout",
|
|
88
|
+
breakpoints: {
|
|
89
|
+
[GRID_LAYOUT_SMALL_BREAKPOINT]: theme.breakpoints.values.sm,
|
|
90
|
+
xxs: 0
|
|
91
|
+
},
|
|
92
|
+
cols: GRID_LAYOUT_COLS,
|
|
93
|
+
rowHeight: ROW_HEIGHT,
|
|
94
|
+
draggableHandle: ".drag-handle",
|
|
95
|
+
resizeHandles: [
|
|
96
|
+
'se'
|
|
97
|
+
],
|
|
98
|
+
isDraggable: isEditMode && !hasViewPanel,
|
|
99
|
+
isResizable: isEditMode && !hasViewPanel,
|
|
100
|
+
margin: [
|
|
101
|
+
DEFAULT_MARGIN,
|
|
102
|
+
DEFAULT_MARGIN
|
|
103
|
+
],
|
|
104
|
+
containerPadding: [
|
|
105
|
+
0,
|
|
106
|
+
10
|
|
107
|
+
],
|
|
108
|
+
layouts: {
|
|
109
|
+
sm: itemLayouts
|
|
110
|
+
},
|
|
111
|
+
onLayoutChange: onLayoutChange,
|
|
112
|
+
onWidthChange: onWidthChange,
|
|
113
|
+
allowOverlap: hasViewPanel,
|
|
114
|
+
children: itemLayouts.map(({ i, w })=>/*#__PURE__*/ _jsx("div", {
|
|
115
|
+
style: {
|
|
116
|
+
display: itemLayoutViewed ? itemLayoutViewed === i ? 'unset' : 'none' : 'unset'
|
|
117
|
+
},
|
|
118
|
+
children: /*#__PURE__*/ _jsx(ErrorBoundary, {
|
|
119
|
+
FallbackComponent: ErrorAlert,
|
|
120
|
+
children: /*#__PURE__*/ _jsx(GridItemContent, {
|
|
121
|
+
panelOptions: panelOptions,
|
|
122
|
+
panelGroupItemId: {
|
|
123
|
+
panelGroupId,
|
|
124
|
+
panelGroupItemLayoutId: i,
|
|
125
|
+
repeatVariable
|
|
126
|
+
},
|
|
127
|
+
width: calculateGridItemWidth(w, gridColWidth)
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
}, i))
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
]
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
const calculateGridItemWidth = (w, colWidth)=>{
|
|
137
|
+
// 0 * Infinity === NaN, which causes problems with resize contraints
|
|
138
|
+
if (!Number.isFinite(w)) return w;
|
|
139
|
+
return Math.round(colWidth * w + Math.max(0, w - 1) * DEFAULT_MARGIN);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
//# sourceMappingURL=Row.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/GridLayout/Row.tsx"],"sourcesContent":["// Copyright 2025 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 { Collapse, useTheme } from '@mui/material';\nimport { PanelGroupId } from '@perses-dev/core';\nimport { PanelGroupDefinition, PanelGroupItemLayout, PanelOptions, useViewPanelGroup } from '@perses-dev/dashboards';\nimport { ReactElement, useEffect, useMemo, useState } from 'react';\nimport { Layout, Layouts, Responsive, WidthProvider } from 'react-grid-layout';\nimport { ErrorAlert, ErrorBoundary } from '@perses-dev/components';\nimport { GRID_LAYOUT_COLS, GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';\nimport { GridContainer } from './GridContainer';\nimport { GridItemContent } from './GridItemContent';\nimport { GridTitle } from './GridTitle';\n\nconst DEFAULT_MARGIN = 10;\nconst ROW_HEIGHT = 30;\n\nexport interface RowProps {\n panelGroupId: PanelGroupId;\n groupDefinition: PanelGroupDefinition;\n gridColWidth: number;\n panelFullHeight?: number;\n panelOptions?: PanelOptions;\n isEditMode?: boolean;\n onLayoutChange?: (currentLayout: Layout[], allLayouts: Layouts) => void;\n onWidthChange?: (\n containerWidth: number,\n margin: [number, number],\n cols: number,\n containerPadding: [number, number]\n ) => void;\n repeatVariable?: [string, string];\n}\n\nexport function Row({\n panelGroupId,\n groupDefinition,\n gridColWidth,\n panelFullHeight,\n panelOptions,\n isEditMode = false,\n onLayoutChange,\n onWidthChange,\n repeatVariable,\n}: RowProps): ReactElement {\n const ResponsiveGridLayout = useMemo(() => WidthProvider(Responsive), []);\n const theme = useTheme();\n const viewPanelItemId = useViewPanelGroup();\n\n const [isOpen, setIsOpen] = useState(!groupDefinition.isCollapsed);\n\n const hasViewPanel =\n viewPanelItemId?.panelGroupId === panelGroupId &&\n // Check for repeatVariable panels\n viewPanelItemId.repeatVariable?.[0] === repeatVariable?.[0] &&\n viewPanelItemId.repeatVariable?.[1] === repeatVariable?.[1];\n const itemLayoutViewed = viewPanelItemId?.panelGroupItemLayoutId;\n\n // If there is a panel in view mode, we should hide the grid if the panel is not in the current group.\n const isGridDisplayed = !viewPanelItemId || hasViewPanel;\n\n // TODO: handle it without useEffect\n useEffect(() => {\n if (hasViewPanel) {\n setIsOpen(true);\n }\n }, [hasViewPanel]);\n\n // Item layout is override if there is a panel in view mode\n const itemLayouts: PanelGroupItemLayout[] = useMemo(() => {\n if (itemLayoutViewed) {\n return groupDefinition.itemLayouts.map((itemLayout) => {\n if (itemLayout.i === itemLayoutViewed) {\n const rowTitleHeight = 40 + 8; // 40 is the height of the row title and 8 is the margin height\n return {\n h: Math.round(((panelFullHeight ?? window.innerHeight) - rowTitleHeight) / (ROW_HEIGHT + DEFAULT_MARGIN)), // Viewed panel should take the full height remaining\n i: itemLayoutViewed,\n w: 48,\n x: 0,\n y: 0,\n } as PanelGroupItemLayout;\n }\n return itemLayout;\n });\n }\n return groupDefinition.itemLayouts;\n }, [groupDefinition.itemLayouts, itemLayoutViewed, panelFullHeight]);\n\n return (\n <GridContainer\n sx={{\n display: isGridDisplayed ? 'block' : 'none',\n height: itemLayoutViewed ? `${panelFullHeight}px` : 'unset',\n overflow: itemLayoutViewed ? 'hidden' : 'unset',\n }}\n >\n {groupDefinition.title && (\n <GridTitle\n panelGroupId={panelGroupId}\n title={groupDefinition.title}\n collapse={\n groupDefinition.isCollapsed === undefined\n ? undefined\n : { isOpen: isOpen, onToggleOpen: () => setIsOpen((current) => !current) }\n }\n />\n )}\n <Collapse in={isOpen} unmountOnExit appear={false} data-testid=\"panel-group-content\">\n <ResponsiveGridLayout\n className=\"layout\"\n breakpoints={{ [GRID_LAYOUT_SMALL_BREAKPOINT]: theme.breakpoints.values.sm, xxs: 0 }}\n cols={GRID_LAYOUT_COLS}\n rowHeight={ROW_HEIGHT}\n draggableHandle=\".drag-handle\"\n resizeHandles={['se']}\n isDraggable={isEditMode && !hasViewPanel}\n isResizable={isEditMode && !hasViewPanel}\n margin={[DEFAULT_MARGIN, DEFAULT_MARGIN]}\n containerPadding={[0, 10]}\n layouts={{ sm: itemLayouts }}\n onLayoutChange={onLayoutChange}\n onWidthChange={onWidthChange}\n allowOverlap={hasViewPanel} // Enabling overlap when viewing a specific panel because panel in front of the viewed panel will add empty spaces (empty row height)\n >\n {itemLayouts.map(({ i, w }) => (\n <div\n key={i}\n style={{\n display: itemLayoutViewed ? (itemLayoutViewed === i ? 'unset' : 'none') : 'unset',\n }}\n >\n <ErrorBoundary FallbackComponent={ErrorAlert}>\n <GridItemContent\n panelOptions={panelOptions}\n panelGroupItemId={{ panelGroupId, panelGroupItemLayoutId: i, repeatVariable }}\n width={calculateGridItemWidth(w, gridColWidth)}\n />\n </ErrorBoundary>\n </div>\n ))}\n </ResponsiveGridLayout>\n </Collapse>\n </GridContainer>\n );\n}\n\nconst calculateGridItemWidth = (w: number, colWidth: number): number => {\n // 0 * Infinity === NaN, which causes problems with resize contraints\n if (!Number.isFinite(w)) return w;\n return Math.round(colWidth * w + Math.max(0, w - 1) * DEFAULT_MARGIN);\n};\n"],"names":["Collapse","useTheme","useViewPanelGroup","useEffect","useMemo","useState","Responsive","WidthProvider","ErrorAlert","ErrorBoundary","GRID_LAYOUT_COLS","GRID_LAYOUT_SMALL_BREAKPOINT","GridContainer","GridItemContent","GridTitle","DEFAULT_MARGIN","ROW_HEIGHT","Row","panelGroupId","groupDefinition","gridColWidth","panelFullHeight","panelOptions","isEditMode","onLayoutChange","onWidthChange","repeatVariable","ResponsiveGridLayout","theme","viewPanelItemId","isOpen","setIsOpen","isCollapsed","hasViewPanel","itemLayoutViewed","panelGroupItemLayoutId","isGridDisplayed","itemLayouts","map","itemLayout","i","rowTitleHeight","h","Math","round","window","innerHeight","w","x","y","sx","display","height","overflow","title","collapse","undefined","onToggleOpen","current","in","unmountOnExit","appear","data-testid","className","breakpoints","values","sm","xxs","cols","rowHeight","draggableHandle","resizeHandles","isDraggable","isResizable","margin","containerPadding","layouts","allowOverlap","div","style","FallbackComponent","panelGroupItemId","width","calculateGridItemWidth","colWidth","Number","isFinite","max"],"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,SAASA,QAAQ,EAAEC,QAAQ,QAAQ,gBAAgB;AAEnD,SAAmEC,iBAAiB,QAAQ,yBAAyB;AACrH,SAAuBC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACnE,SAA0BC,UAAU,EAAEC,aAAa,QAAQ,oBAAoB;AAC/E,SAASC,UAAU,EAAEC,aAAa,QAAQ,yBAAyB;AACnE,SAASC,gBAAgB,EAAEC,4BAA4B,QAAQ,kBAAkB;AACjF,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,SAAS,QAAQ,cAAc;AAExC,MAAMC,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CAC5EwD,OAAOC,uBAAuBpC,GAAG3B;;;2BAThCoB;;;;;AAkBnB;AAEA,MAAM2C,yBAAyB,CAACpC,GAAWqC;IACzC,qEAAqE;IACrE,IAAI,CAACC,OAAOC,QAAQ,CAACvC,IAAI,OAAOA;IAChC,OAAOJ,KAAKC,KAAK,CAACwC,WAAWrC,IAAIJ,KAAK4C,GAAG,CAAC,GAAGxC,IAAI,KAAKhC;AACxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/index.ts"],"names":[],"mappings":"AAaA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/GridLayout/index.ts"],"names":[],"mappings":"AAaA,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/components/GridLayout/index.ts"],"sourcesContent":["// Copyright 2023 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 './GridContainer';\nexport * from './GridItemContent';\nexport * from './GridLayout';\nexport * from './GridTitle';\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,kBAAkB;AAChC,cAAc,oBAAoB;AAClC,cAAc,eAAe;AAC7B,cAAc,cAAc"}
|
|
1
|
+
{"version":3,"sources":["../../../src/components/GridLayout/index.ts"],"sourcesContent":["// Copyright 2023 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 './GridContainer';\nexport * from './GridItemContent';\nexport * from './GridLayout';\nexport * from './GridTitle';\nexport * from './Row';\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,kBAAkB;AAChC,cAAc,oBAAoB;AAClC,cAAc,eAAe;AAC7B,cAAc,cAAc;AAC5B,cAAc,QAAQ"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { DashboardResource, EphemeralDashboardResource } from '@perses-dev/core';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export declare function LeaveDialog({ original, current, }: {
|
|
4
|
+
original: DashboardResource | EphemeralDashboardResource | undefined;
|
|
5
|
+
current: DashboardResource | EphemeralDashboardResource;
|
|
6
|
+
}): ReactNode;
|
|
7
|
+
//# sourceMappingURL=LeaveDialog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LeaveDialog.d.ts","sourceRoot":"","sources":["../../../src/components/LeaveDialog/LeaveDialog.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAE7C,wBAAgB,WAAW,CAAC,EAC1B,QAAQ,EACR,OAAO,GACR,EAAE;IACD,QAAQ,EAAE,iBAAiB,GAAG,0BAA0B,GAAG,SAAS,CAAC;IACrE,OAAO,EAAE,iBAAiB,GAAG,0BAA0B,CAAC;CACzD,GAAG,SAAS,CAmBZ"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Copyright 2025 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, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
|
+
import { useEffect } from 'react';
|
|
15
|
+
export function LeaveDialog({ original, current }) {
|
|
16
|
+
useEffect(()=>{
|
|
17
|
+
const handleBeforeUnload = (event)=>{
|
|
18
|
+
if (JSON.stringify(original) === JSON.stringify(current)) {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
event.returnValue = ''; // Required for Chrome
|
|
23
|
+
return ''; // Required for other browsers
|
|
24
|
+
};
|
|
25
|
+
window.addEventListener('beforeunload', handleBeforeUnload);
|
|
26
|
+
return ()=>{
|
|
27
|
+
window.removeEventListener('beforeunload', handleBeforeUnload);
|
|
28
|
+
};
|
|
29
|
+
}, [
|
|
30
|
+
original,
|
|
31
|
+
current
|
|
32
|
+
]);
|
|
33
|
+
return /*#__PURE__*/ _jsx(_Fragment, {});
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
//# sourceMappingURL=LeaveDialog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/LeaveDialog/LeaveDialog.tsx"],"sourcesContent":["// Copyright 2025 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 { DashboardResource, EphemeralDashboardResource } from '@perses-dev/core';\nimport { ReactNode, useEffect } from 'react';\n\nexport function LeaveDialog({\n original,\n current,\n}: {\n original: DashboardResource | EphemeralDashboardResource | undefined;\n current: DashboardResource | EphemeralDashboardResource;\n}): ReactNode {\n useEffect(() => {\n const handleBeforeUnload = (event: BeforeUnloadEvent): string | null => {\n if (JSON.stringify(original) === JSON.stringify(current)) {\n return null;\n }\n event.preventDefault();\n event.returnValue = ''; // Required for Chrome\n return ''; // Required for other browsers\n };\n\n window.addEventListener('beforeunload', handleBeforeUnload);\n\n return (): void => {\n window.removeEventListener('beforeunload', handleBeforeUnload);\n };\n }, [original, current]);\n\n return <></>;\n}\n"],"names":["useEffect","LeaveDialog","original","current","handleBeforeUnload","event","JSON","stringify","preventDefault","returnValue","window","addEventListener","removeEventListener"],"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;;AAGjC,SAAoBA,SAAS,QAAQ,QAAQ;AAE7C,OAAO,SAASC,YAAY,EAC1BC,QAAQ,EACRC,OAAO,EAIR;IACCH,UAAU;QACR,MAAMI,qBAAqB,CAACC;YAC1B,IAAIC,KAAKC,SAAS,CAACL,cAAcI,KAAKC,SAAS,CAACJ,UAAU;gBACxD,OAAO;YACT;YACAE,MAAMG,cAAc;YACpBH,MAAMI,WAAW,GAAG,IAAI,sBAAsB;YAC9C,OAAO,IAAI,8BAA8B;QAC3C;QAEAC,OAAOC,gBAAgB,CAAC,gBAAgBP;QAExC,OAAO;YACLM,OAAOE,mBAAmB,CAAC,gBAAgBR;QAC7C;IACF,GAAG;QAACF;QAAUC;KAAQ;IAEtB,qBAAO;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/LeaveDialog/index.ts"],"names":[],"mappings":"AAaA,cAAc,eAAe,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright 2025 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 './LeaveDialog';
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/LeaveDialog/index.ts"],"sourcesContent":["// Copyright 2025 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 './LeaveDialog';\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,gBAAgB"}
|
|
@@ -17,6 +17,11 @@ export type PanelOptions = {
|
|
|
17
17
|
* This can be useful in embedded mode for example.
|
|
18
18
|
*/
|
|
19
19
|
hideHeader?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether to show panel icons always, or only when hovering over the panel.
|
|
22
|
+
* Default: if the dashboard is in editing mode or the panel is in fullscreen mode: 'always', otherwise 'hover'
|
|
23
|
+
*/
|
|
24
|
+
showIcons?: 'always' | 'hover';
|
|
20
25
|
/**
|
|
21
26
|
* Content to render in right of the panel header. (top right of the panel)
|
|
22
27
|
* It will only be rendered when the panel is in edit mode.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Panel.d.ts","sourceRoot":"","sources":["../../../src/components/Panel/Panel.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAqB,SAAS,EAAE,MAAM,eAAe,CAAC;AAE7D,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAsC,MAAM,OAAO,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,OAAO,EAAe,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE9D,MAAM,WAAW,UAAW,SAA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