@perses-dev/dashboards 0.52.0-beta.5 → 0.52.0-rc.1

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 (127) hide show
  1. package/dist/cjs/components/GridLayout/GridLayout.js +78 -126
  2. package/dist/cjs/components/GridLayout/Row.js +150 -0
  3. package/dist/cjs/components/GridLayout/index.js +1 -0
  4. package/dist/cjs/components/LeaveDialog/LeaveDialog.js +72 -0
  5. package/dist/cjs/components/LeaveDialog/index.js +30 -0
  6. package/dist/cjs/components/Panel/Panel.js +5 -1
  7. package/dist/cjs/components/Panel/PanelActions.js +4 -4
  8. package/dist/cjs/components/Panel/PanelHeader.js +32 -15
  9. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +58 -21
  10. package/dist/cjs/components/PanelDrawer/PanelEditorForm.js +204 -185
  11. package/dist/cjs/components/PanelGroupDialog/PanelGroupDialog.js +3 -0
  12. package/dist/cjs/components/PanelGroupDialog/PanelGroupEditorForm.js +35 -15
  13. package/dist/cjs/components/Variables/VariableEditor.js +22 -15
  14. package/dist/cjs/components/index.js +1 -0
  15. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +7 -8
  16. package/dist/cjs/context/DashboardProvider/DashboardProviderWithQueryParams.js +27 -5
  17. package/dist/cjs/context/DashboardProvider/panel-editor-slice.js +1 -0
  18. package/dist/cjs/context/DashboardProvider/panel-group-editor-slice.js +6 -2
  19. package/dist/cjs/context/DashboardProvider/panel-group-slice.js +1 -0
  20. package/dist/cjs/context/DashboardProvider/view-panel-slice.js +10 -3
  21. package/dist/cjs/context/VariableProvider/VariableProvider.js +1 -1
  22. package/dist/cjs/context/VariableProvider/query-params.js +12 -14
  23. package/dist/cjs/context/useDashboard.js +5 -4
  24. package/dist/cjs/test/render.js +6 -8
  25. package/dist/cjs/views/ViewDashboard/DashboardApp.js +7 -3
  26. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +9 -8
  27. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +2 -2
  28. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  29. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  30. package/dist/components/GridLayout/GridLayout.d.ts +8 -0
  31. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  32. package/dist/components/GridLayout/GridLayout.js +72 -126
  33. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  34. package/dist/components/GridLayout/Row.d.ts +17 -0
  35. package/dist/components/GridLayout/Row.d.ts.map +1 -0
  36. package/dist/components/GridLayout/Row.js +142 -0
  37. package/dist/components/GridLayout/Row.js.map +1 -0
  38. package/dist/components/GridLayout/index.d.ts +1 -0
  39. package/dist/components/GridLayout/index.d.ts.map +1 -1
  40. package/dist/components/GridLayout/index.js +1 -0
  41. package/dist/components/GridLayout/index.js.map +1 -1
  42. package/dist/components/LeaveDialog/LeaveDialog.d.ts +12 -0
  43. package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -0
  44. package/dist/components/LeaveDialog/LeaveDialog.js +61 -0
  45. package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -0
  46. package/dist/components/LeaveDialog/index.d.ts +2 -0
  47. package/dist/components/LeaveDialog/index.d.ts.map +1 -0
  48. package/dist/components/LeaveDialog/index.js +15 -0
  49. package/dist/components/LeaveDialog/index.js.map +1 -0
  50. package/dist/components/Panel/HeaderIconButton.d.ts +1 -1
  51. package/dist/components/Panel/Panel.d.ts +5 -0
  52. package/dist/components/Panel/Panel.d.ts.map +1 -1
  53. package/dist/components/Panel/Panel.js +5 -1
  54. package/dist/components/Panel/Panel.js.map +1 -1
  55. package/dist/components/Panel/PanelActions.d.ts +2 -0
  56. package/dist/components/Panel/PanelActions.d.ts.map +1 -1
  57. package/dist/components/Panel/PanelActions.js +4 -4
  58. package/dist/components/Panel/PanelActions.js.map +1 -1
  59. package/dist/components/Panel/PanelHeader.d.ts +6 -1
  60. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  61. package/dist/components/Panel/PanelHeader.js +33 -16
  62. package/dist/components/Panel/PanelHeader.js.map +1 -1
  63. package/dist/components/PanelDrawer/PanelDrawer.d.ts.map +1 -1
  64. package/dist/components/PanelDrawer/PanelDrawer.js +59 -22
  65. package/dist/components/PanelDrawer/PanelDrawer.js.map +1 -1
  66. package/dist/components/PanelDrawer/PanelEditorForm.d.ts.map +1 -1
  67. package/dist/components/PanelDrawer/PanelEditorForm.js +207 -188
  68. package/dist/components/PanelDrawer/PanelEditorForm.js.map +1 -1
  69. package/dist/components/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  70. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +3 -0
  71. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  72. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +1 -0
  73. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -1
  74. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +36 -16
  75. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
  76. package/dist/components/Variables/VariableEditor.d.ts.map +1 -1
  77. package/dist/components/Variables/VariableEditor.js +24 -17
  78. package/dist/components/Variables/VariableEditor.js.map +1 -1
  79. package/dist/components/index.d.ts +1 -0
  80. package/dist/components/index.d.ts.map +1 -1
  81. package/dist/components/index.js +1 -0
  82. package/dist/components/index.js.map +1 -1
  83. package/dist/context/DashboardProvider/DashboardProvider.d.ts +5 -5
  84. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  85. package/dist/context/DashboardProvider/DashboardProvider.js +7 -8
  86. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  87. package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.d.ts.map +1 -1
  88. package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js +27 -5
  89. package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js.map +1 -1
  90. package/dist/context/DashboardProvider/common.d.ts +1 -1
  91. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  92. package/dist/context/DashboardProvider/common.js.map +1 -1
  93. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +1 -0
  94. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  95. package/dist/context/DashboardProvider/panel-editor-slice.js +1 -0
  96. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  97. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +1 -0
  98. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
  99. package/dist/context/DashboardProvider/panel-group-editor-slice.js +6 -2
  100. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  101. package/dist/context/DashboardProvider/panel-group-slice.d.ts +3 -0
  102. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  103. package/dist/context/DashboardProvider/panel-group-slice.js +1 -0
  104. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  105. package/dist/context/DashboardProvider/view-panel-slice.d.ts +6 -2
  106. package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
  107. package/dist/context/DashboardProvider/view-panel-slice.js +10 -3
  108. package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
  109. package/dist/context/VariableProvider/VariableProvider.js +1 -1
  110. package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
  111. package/dist/context/VariableProvider/query-params.d.ts +4 -3
  112. package/dist/context/VariableProvider/query-params.d.ts.map +1 -1
  113. package/dist/context/VariableProvider/query-params.js +9 -14
  114. package/dist/context/VariableProvider/query-params.js.map +1 -1
  115. package/dist/context/useDashboard.js +5 -4
  116. package/dist/context/useDashboard.js.map +1 -1
  117. package/dist/test/render.d.ts.map +1 -1
  118. package/dist/test/render.js +6 -8
  119. package/dist/test/render.js.map +1 -1
  120. package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -6
  121. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  122. package/dist/views/ViewDashboard/DashboardApp.js +8 -4
  123. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  124. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  125. package/dist/views/ViewDashboard/ViewDashboard.js +9 -8
  126. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  127. package/package.json +6 -6
@@ -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, jsxs as _jsxs } from "react/jsx-runtime";
14
- import { useEffect, useMemo, useState } from 'react';
15
- import { Responsive, WidthProvider } from 'react-grid-layout';
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 { GRID_LAYOUT_COLS, GRID_LAYOUT_SMALL_BREAKPOINT } from '../../constants';
20
- import { GridTitle } from './GridTitle';
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 [isOpen, setIsOpen] = useState(!groupDefinition.isCollapsed);
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
- // https://github.com/react-grid-layout/react-grid-layout?tab=readme-ov-file#react-hooks-performance
91
- const ResponsiveGridLayout = useMemo(()=>WidthProvider(Responsive), []);
92
- return /*#__PURE__*/ _jsxs(GridContainer, {
93
- sx: {
94
- display: isGridDisplayed ? 'block' : 'none',
95
- height: itemLayoutViewed ? `${panelFullHeight}px` : 'unset',
96
- overflow: itemLayoutViewed ? 'hidden' : 'unset'
97
- },
98
- children: [
99
- groupDefinition.title !== undefined && /*#__PURE__*/ _jsx(GridTitle, {
100
- panelGroupId: panelGroupId,
101
- title: groupDefinition.title,
102
- collapse: groupDefinition.isCollapsed === undefined ? undefined : {
103
- isOpen,
104
- onToggleOpen: ()=>setIsOpen((current)=>!current)
105
- }
106
- }),
107
- /*#__PURE__*/ _jsx(Collapse, {
108
- in: isOpen,
109
- unmountOnExit: true,
110
- appear: false,
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
- * Calculates grid item width
163
- * @param w number of columns the grid item spans
164
- * @param colWidth the width of each column in px
165
- * @returns grid item's width in px
166
- * https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35
167
- */ const calculateGridItemWidth = (w, colWidth)=>{
168
- // 0 * Infinity === NaN, which causes problems with resize contraints
169
- if (!Number.isFinite(w)) return w;
170
- return Math.round(colWidth * w + Math.max(0, w - 1) * DEFAULT_MARGIN);
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,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E0B;oBAAY;oBACvDiD,gBAAgBpC;oBAChBqC,eAAejC;oBACfkC,cAAcxD;8BAEbK,YAAYC,GAAG,CAAC,CAAC,EAAEE,CAAC,EAAEO,CAAC,EAAE,iBACxB,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,wBA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C,QAAQ;gBAEvBH,OAAO;oBAAEI,OAAO;wBAAE,GAAGT,SAAS;wBAAE,CAACD,mBAAmB,EAAE;4BAAEM;4BAAOK,SAAS;wBAAM;oBAAE;gBAAE;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,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AoBA,qBAAqBM,IAAI,UAAU,SAAU;4BAC5E;sCAEA,cAAA,KAAC/B;gCAAcuE,mBAAmBxE;0CAChC,cAAA,KAACK;oCACCS,cAAcA;oCACd2D,kBAAkB;wCAAE/D;wCAAciB,wBAAwBK;wCAAGd;oCAAe;oCAC5EwD,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"}
@@ -2,4 +2,5 @@ export * from './GridContainer';
2
2
  export * from './GridItemContent';
3
3
  export * from './GridLayout';
4
4
  export * from './GridTitle';
5
+ export * from './Row';
5
6
  //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -14,5 +14,6 @@ export * from './GridContainer';
14
14
  export * from './GridItemContent';
15
15
  export * from './GridLayout';
16
16
  export * from './GridTitle';
17
+ export * from './Row';
17
18
 
18
19
  //# sourceMappingURL=index.js.map
@@ -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,12 @@
1
+ import { DashboardResource, EphemeralDashboardResource } from '@perses-dev/core';
2
+ import { ReactElement, ReactNode } from 'react';
3
+ export interface LeaveDialogProps {
4
+ isBlocked: boolean;
5
+ message: string;
6
+ }
7
+ export declare function Prompt({ isBlocked, message }: LeaveDialogProps): ReactElement;
8
+ export declare function LeaveDialog({ original, current, }: {
9
+ original: DashboardResource | EphemeralDashboardResource | undefined;
10
+ current: DashboardResource | EphemeralDashboardResource;
11
+ }): ReactNode;
12
+ //# 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,YAAY,EAAE,SAAS,EAAa,MAAM,OAAO,CAAC;AAU3D,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAMD,wBAAgB,MAAM,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,gBAAgB,GAAG,YAAY,CA4B7E;AAKD,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,CAOZ"}
@@ -0,0 +1,61 @@
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 } from "react/jsx-runtime";
14
+ import { useEffect } from 'react';
15
+ import { useBlocker } from 'react-router-dom';
16
+ import { DiscardChangesConfirmationDialog } from '@perses-dev/components';
17
+ const handleRouteChange = (event)=>{
18
+ event.preventDefault();
19
+ event.returnValue = ''; // Required for Chrome
20
+ return ''; // Required for other browsers
21
+ };
22
+ /*
23
+ * Prompt component uses the useBlocker hook to block react-router navigation when there are unsaved changes.
24
+ * It also listens to the beforeunload event to show a browser confirmation dialog when the user tries to close the tab, refresh the page or change url manually.
25
+ */ export function Prompt({ isBlocked, message }) {
26
+ const blocker = useBlocker(isBlocked);
27
+ const isBlockedState = blocker.state === 'blocked';
28
+ const isProceedingState = blocker.state === 'proceeding';
29
+ useEffect(()=>{
30
+ if (isBlocked) {
31
+ window.addEventListener('beforeunload', handleRouteChange);
32
+ } else {
33
+ window.removeEventListener('beforeunload', handleRouteChange);
34
+ }
35
+ return ()=>{
36
+ window.removeEventListener('beforeunload', handleRouteChange);
37
+ };
38
+ }, [
39
+ blocker,
40
+ isBlocked,
41
+ isBlockedState
42
+ ]);
43
+ const handleDiscardChanges = ()=>blocker.proceed?.();
44
+ const handleCancel = ()=>blocker.reset?.();
45
+ return /*#__PURE__*/ _jsx(DiscardChangesConfirmationDialog, {
46
+ description: message,
47
+ isOpen: isBlockedState || isProceedingState,
48
+ onDiscardChanges: handleDiscardChanges,
49
+ onCancel: handleCancel
50
+ });
51
+ }
52
+ /*
53
+ * LeaveDialog prompts the user with a confirmation dialog when they attempt to leave the page with unsaved changes.
54
+ */ export function LeaveDialog({ original, current }) {
55
+ return /*#__PURE__*/ _jsx(Prompt, {
56
+ isBlocked: JSON.stringify(original) !== JSON.stringify(current),
57
+ message: "You have unsaved changes, are you sure you want to leave?"
58
+ });
59
+ }
60
+
61
+ //# 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 { ReactElement, ReactNode, useEffect } from 'react';\nimport { useBlocker } from 'react-router-dom';\nimport { DiscardChangesConfirmationDialog } from '@perses-dev/components';\n\nconst handleRouteChange = (event: BeforeUnloadEvent): string => {\n event.preventDefault();\n event.returnValue = ''; // Required for Chrome\n return ''; // Required for other browsers\n};\n\nexport interface LeaveDialogProps {\n isBlocked: boolean;\n message: string;\n}\n\n/*\n * Prompt component uses the useBlocker hook to block react-router navigation when there are unsaved changes.\n * It also listens to the beforeunload event to show a browser confirmation dialog when the user tries to close the tab, refresh the page or change url manually.\n */\nexport function Prompt({ isBlocked, message }: LeaveDialogProps): ReactElement {\n const blocker = useBlocker(isBlocked);\n const isBlockedState = blocker.state === 'blocked';\n const isProceedingState = blocker.state === 'proceeding';\n\n useEffect(() => {\n if (isBlocked) {\n window.addEventListener('beforeunload', handleRouteChange);\n } else {\n window.removeEventListener('beforeunload', handleRouteChange);\n }\n\n return (): void => {\n window.removeEventListener('beforeunload', handleRouteChange);\n };\n }, [blocker, isBlocked, isBlockedState]);\n\n const handleDiscardChanges = (): void => blocker.proceed?.();\n const handleCancel = (): void => blocker.reset?.();\n\n return (\n <DiscardChangesConfirmationDialog\n description={message}\n isOpen={isBlockedState || isProceedingState}\n onDiscardChanges={handleDiscardChanges}\n onCancel={handleCancel}\n />\n );\n}\n\n/*\n * LeaveDialog prompts the user with a confirmation dialog when they attempt to leave the page with unsaved changes.\n */\nexport function LeaveDialog({\n original,\n current,\n}: {\n original: DashboardResource | EphemeralDashboardResource | undefined;\n current: DashboardResource | EphemeralDashboardResource;\n}): ReactNode {\n return (\n <Prompt\n isBlocked={JSON.stringify(original) !== JSON.stringify(current)}\n message=\"You have unsaved changes, are you sure you want to leave?\"\n />\n );\n}\n"],"names":["useEffect","useBlocker","DiscardChangesConfirmationDialog","handleRouteChange","event","preventDefault","returnValue","Prompt","isBlocked","message","blocker","isBlockedState","state","isProceedingState","window","addEventListener","removeEventListener","handleDiscardChanges","proceed","handleCancel","reset","description","isOpen","onDiscardChanges","onCancel","LeaveDialog","original","current","JSON","stringify"],"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,SAAkCA,SAAS,QAAQ,QAAQ;AAC3D,SAASC,UAAU,QAAQ,mBAAmB;AAC9C,SAASC,gCAAgC,QAAQ,yBAAyB;AAE1E,MAAMC,oBAAoB,CAACC;IACzBA,MAAMC,cAAc;IACpBD,MAAME,WAAW,GAAG,IAAI,sBAAsB;IAC9C,OAAO,IAAI,8BAA8B;AAC3C;AAOA;;;CAGC,GACD,OAAO,SAASC,OAAO,EAAEC,SAAS,EAAEC,OAAO,EAAoB;IAC7D,MAAMC,UAAUT,WAAWO;IAC3B,MAAMG,iBAAiBD,QAAQE,KAAK,KAAK;IACzC,MAAMC,oBAAoBH,QAAQE,KAAK,KAAK;IAE5CZ,UAAU;QACR,IAAIQ,WAAW;YACbM,OAAOC,gBAAgB,CAAC,gBAAgBZ;QAC1C,OAAO;YACLW,OAAOE,mBAAmB,CAAC,gBAAgBb;QAC7C;QAEA,OAAO;YACLW,OAAOE,mBAAmB,CAAC,gBAAgBb;QAC7C;IACF,GAAG;QAACO;QAASF;QAAWG;KAAe;IAEvC,MAAMM,uBAAuB,IAAYP,QAAQQ,OAAO;IACxD,MAAMC,eAAe,IAAYT,QAAQU,KAAK;IAE9C,qBACE,KAAClB;QACCmB,aAAaZ;QACba,QAAQX,kBAAkBE;QAC1BU,kBAAkBN;QAClBO,UAAUL;;AAGhB;AAEA;;CAEC,GACD,OAAO,SAASM,YAAY,EAC1BC,QAAQ,EACRC,OAAO,EAIR;IACC,qBACE,KAACpB;QACCC,WAAWoB,KAAKC,SAAS,CAACH,cAAcE,KAAKC,SAAS,CAACF;QACvDlB,SAAQ;;AAGd"}
@@ -0,0 +1,2 @@
1
+ export * from './LeaveDialog';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -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"}