@perses-dev/dashboards 0.52.0-beta.4 → 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.
Files changed (117) hide show
  1. package/dist/cjs/components/GridLayout/GridItemContent.js +137 -17
  2. package/dist/cjs/components/GridLayout/GridLayout.js +78 -126
  3. package/dist/cjs/components/GridLayout/Row.js +150 -0
  4. package/dist/cjs/components/GridLayout/index.js +1 -0
  5. package/dist/cjs/components/LeaveDialog/LeaveDialog.js +44 -0
  6. package/dist/cjs/components/LeaveDialog/index.js +30 -0
  7. package/dist/cjs/components/Panel/Panel.js +7 -2
  8. package/dist/cjs/components/Panel/PanelActions.js +25 -5
  9. package/dist/cjs/components/Panel/PanelHeader.js +33 -15
  10. package/dist/cjs/components/PanelDrawer/PanelDrawer.js +58 -21
  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/index.js +1 -0
  14. package/dist/cjs/constants/user-interface-text.js +4 -2
  15. package/dist/cjs/context/DashboardProvider/DashboardProvider.js +7 -8
  16. package/dist/cjs/context/DashboardProvider/DashboardProviderWithQueryParams.js +3 -3
  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/useDashboard.js +5 -4
  23. package/dist/cjs/views/ViewDashboard/DashboardApp.js +7 -3
  24. package/dist/cjs/views/ViewDashboard/ViewDashboard.js +9 -8
  25. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts +2 -2
  26. package/dist/components/DashboardToolbar/DashboardToolbar.d.ts.map +1 -1
  27. package/dist/components/DashboardToolbar/DashboardToolbar.js.map +1 -1
  28. package/dist/components/GridLayout/GridItemContent.d.ts.map +1 -1
  29. package/dist/components/GridLayout/GridItemContent.js +99 -20
  30. package/dist/components/GridLayout/GridItemContent.js.map +1 -1
  31. package/dist/components/GridLayout/GridLayout.d.ts +8 -0
  32. package/dist/components/GridLayout/GridLayout.d.ts.map +1 -1
  33. package/dist/components/GridLayout/GridLayout.js +72 -126
  34. package/dist/components/GridLayout/GridLayout.js.map +1 -1
  35. package/dist/components/GridLayout/Row.d.ts +17 -0
  36. package/dist/components/GridLayout/Row.d.ts.map +1 -0
  37. package/dist/components/GridLayout/Row.js +142 -0
  38. package/dist/components/GridLayout/Row.js.map +1 -0
  39. package/dist/components/GridLayout/index.d.ts +1 -0
  40. package/dist/components/GridLayout/index.d.ts.map +1 -1
  41. package/dist/components/GridLayout/index.js +1 -0
  42. package/dist/components/GridLayout/index.js.map +1 -1
  43. package/dist/components/LeaveDialog/LeaveDialog.d.ts +7 -0
  44. package/dist/components/LeaveDialog/LeaveDialog.d.ts.map +1 -0
  45. package/dist/components/LeaveDialog/LeaveDialog.js +36 -0
  46. package/dist/components/LeaveDialog/LeaveDialog.js.map +1 -0
  47. package/dist/components/LeaveDialog/index.d.ts +2 -0
  48. package/dist/components/LeaveDialog/index.d.ts.map +1 -0
  49. package/dist/components/LeaveDialog/index.js +15 -0
  50. package/dist/components/LeaveDialog/index.js.map +1 -0
  51. package/dist/components/Panel/Panel.d.ts +6 -0
  52. package/dist/components/Panel/Panel.d.ts.map +1 -1
  53. package/dist/components/Panel/Panel.js +7 -2
  54. package/dist/components/Panel/Panel.js.map +1 -1
  55. package/dist/components/Panel/PanelActions.d.ts +5 -0
  56. package/dist/components/Panel/PanelActions.d.ts.map +1 -1
  57. package/dist/components/Panel/PanelActions.js +25 -5
  58. package/dist/components/Panel/PanelActions.js.map +1 -1
  59. package/dist/components/Panel/PanelHeader.d.ts +7 -1
  60. package/dist/components/Panel/PanelHeader.d.ts.map +1 -1
  61. package/dist/components/Panel/PanelHeader.js +34 -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/PanelGroupDialog/PanelGroupDialog.d.ts.map +1 -1
  67. package/dist/components/PanelGroupDialog/PanelGroupDialog.js +3 -0
  68. package/dist/components/PanelGroupDialog/PanelGroupDialog.js.map +1 -1
  69. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts +1 -0
  70. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.d.ts.map +1 -1
  71. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js +36 -16
  72. package/dist/components/PanelGroupDialog/PanelGroupEditorForm.js.map +1 -1
  73. package/dist/components/index.d.ts +1 -0
  74. package/dist/components/index.d.ts.map +1 -1
  75. package/dist/components/index.js +1 -0
  76. package/dist/components/index.js.map +1 -1
  77. package/dist/constants/user-interface-text.d.ts +2 -0
  78. package/dist/constants/user-interface-text.d.ts.map +1 -1
  79. package/dist/constants/user-interface-text.js +4 -2
  80. package/dist/constants/user-interface-text.js.map +1 -1
  81. package/dist/context/DashboardProvider/DashboardProvider.d.ts +5 -5
  82. package/dist/context/DashboardProvider/DashboardProvider.d.ts.map +1 -1
  83. package/dist/context/DashboardProvider/DashboardProvider.js +7 -8
  84. package/dist/context/DashboardProvider/DashboardProvider.js.map +1 -1
  85. package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js +4 -4
  86. package/dist/context/DashboardProvider/DashboardProviderWithQueryParams.js.map +1 -1
  87. package/dist/context/DashboardProvider/common.d.ts +1 -1
  88. package/dist/context/DashboardProvider/common.d.ts.map +1 -1
  89. package/dist/context/DashboardProvider/common.js.map +1 -1
  90. package/dist/context/DashboardProvider/panel-editor-slice.d.ts +1 -0
  91. package/dist/context/DashboardProvider/panel-editor-slice.d.ts.map +1 -1
  92. package/dist/context/DashboardProvider/panel-editor-slice.js +1 -0
  93. package/dist/context/DashboardProvider/panel-editor-slice.js.map +1 -1
  94. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts +1 -0
  95. package/dist/context/DashboardProvider/panel-group-editor-slice.d.ts.map +1 -1
  96. package/dist/context/DashboardProvider/panel-group-editor-slice.js +6 -2
  97. package/dist/context/DashboardProvider/panel-group-editor-slice.js.map +1 -1
  98. package/dist/context/DashboardProvider/panel-group-slice.d.ts +3 -0
  99. package/dist/context/DashboardProvider/panel-group-slice.d.ts.map +1 -1
  100. package/dist/context/DashboardProvider/panel-group-slice.js +1 -0
  101. package/dist/context/DashboardProvider/panel-group-slice.js.map +1 -1
  102. package/dist/context/DashboardProvider/view-panel-slice.d.ts +6 -2
  103. package/dist/context/DashboardProvider/view-panel-slice.d.ts.map +1 -1
  104. package/dist/context/DashboardProvider/view-panel-slice.js +10 -3
  105. package/dist/context/DashboardProvider/view-panel-slice.js.map +1 -1
  106. package/dist/context/VariableProvider/VariableProvider.js +1 -1
  107. package/dist/context/VariableProvider/VariableProvider.js.map +1 -1
  108. package/dist/context/useDashboard.js +5 -4
  109. package/dist/context/useDashboard.js.map +1 -1
  110. package/dist/views/ViewDashboard/DashboardApp.d.ts +7 -6
  111. package/dist/views/ViewDashboard/DashboardApp.d.ts.map +1 -1
  112. package/dist/views/ViewDashboard/DashboardApp.js +8 -4
  113. package/dist/views/ViewDashboard/DashboardApp.js.map +1 -1
  114. package/dist/views/ViewDashboard/ViewDashboard.d.ts.map +1 -1
  115. package/dist/views/ViewDashboard/ViewDashboard.js +9 -8
  116. package/dist/views/ViewDashboard/ViewDashboard.js.map +1 -1
  117. package/package.json +5 -5
@@ -24,9 +24,51 @@ const _jsxruntime = require("react/jsx-runtime");
24
24
  const _material = require("@mui/material");
25
25
  const _reactintersectionobserver = require("react-intersection-observer");
26
26
  const _pluginsystem = require("@perses-dev/plugin-system");
27
+ const _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
27
28
  const _context = require("../../context");
28
29
  const _Panel = require("../Panel");
29
30
  const _panelgroupslice = require("../../context/DashboardProvider/panel-group-slice");
31
+ function _getRequireWildcardCache(nodeInterop) {
32
+ if (typeof WeakMap !== "function") return null;
33
+ var cacheBabelInterop = new WeakMap();
34
+ var cacheNodeInterop = new WeakMap();
35
+ return (_getRequireWildcardCache = function(nodeInterop) {
36
+ return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
37
+ })(nodeInterop);
38
+ }
39
+ function _interop_require_wildcard(obj, nodeInterop) {
40
+ if (!nodeInterop && obj && obj.__esModule) {
41
+ return obj;
42
+ }
43
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
44
+ return {
45
+ default: obj
46
+ };
47
+ }
48
+ var cache = _getRequireWildcardCache(nodeInterop);
49
+ if (cache && cache.has(obj)) {
50
+ return cache.get(obj);
51
+ }
52
+ var newObj = {
53
+ __proto__: null
54
+ };
55
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
56
+ for(var key in obj){
57
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
58
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
59
+ if (desc && (desc.get || desc.set)) {
60
+ Object.defineProperty(newObj, key, desc);
61
+ } else {
62
+ newObj[key] = obj[key];
63
+ }
64
+ }
65
+ }
66
+ newObj.default = obj;
67
+ if (cache) {
68
+ cache.set(obj, newObj);
69
+ }
70
+ return newObj;
71
+ }
30
72
  function GridItemContent(props) {
31
73
  const { panelGroupItemId, width } = props;
32
74
  const panelDefinition = (0, _context.usePanel)(panelGroupItemId);
@@ -39,6 +81,17 @@ function GridItemContent(props) {
39
81
  initialInView: false,
40
82
  triggerOnce: true
41
83
  });
84
+ const [openQueryViewer, setOpenQueryViewer] = (0, _react.useState)(false);
85
+ const viewQueriesHandler = (0, _react.useMemo)(()=>{
86
+ return isEditMode || !queries?.length ? undefined : {
87
+ onClick: ()=>{
88
+ setOpenQueryViewer(true);
89
+ }
90
+ };
91
+ }, [
92
+ isEditMode,
93
+ queries
94
+ ]);
42
95
  const readHandlers = {
43
96
  isPanelViewed: (0, _panelgroupslice.isPanelGroupItemIdEqual)(viewPanelGroupItemId, panelGroupItemId),
44
97
  onViewPanelClick: function() {
@@ -69,28 +122,95 @@ function GridItemContent(props) {
69
122
  };
70
123
  });
71
124
  const pluginQueryOptions = typeof plugin?.queryOptions === 'function' ? plugin?.queryOptions(panelDefinition.spec.plugin.spec) : plugin?.queryOptions;
72
- return /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
125
+ const queryRows = (0, _react.useMemo)(()=>{
126
+ if (!queries?.length) return null;
127
+ const queryItems = [];
128
+ queries.forEach((query, index)=>{
129
+ if (query?.spec?.plugin?.kind && query?.kind) {
130
+ queryItems.push(/*#__PURE__*/ (0, _jsxruntime.jsxs)(_react.default.Fragment, {
131
+ children: [
132
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.PluginSpecEditor, {
133
+ value: query.spec.plugin.spec,
134
+ pluginSelection: {
135
+ kind: query.spec.plugin.kind,
136
+ type: query.kind
137
+ },
138
+ onChange: ()=>{},
139
+ isReadonly: true
140
+ }),
141
+ index < queries.length - 1 && /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Divider, {
142
+ sx: {
143
+ my: 2
144
+ }
145
+ })
146
+ ]
147
+ }, `query-${index}`));
148
+ }
149
+ });
150
+ return queryItems;
151
+ }, [
152
+ queries
153
+ ]);
154
+ const onCloseHandler = ()=>{
155
+ setOpenQueryViewer(false);
156
+ };
157
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Box, {
73
158
  ref: ref,
74
159
  sx: {
75
160
  width: '100%',
76
161
  height: '100%'
77
162
  },
78
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DataQueriesProvider, {
79
- definitions: definitions,
80
- options: {
81
- suggestedStepMs,
82
- ...pluginQueryOptions
83
- },
84
- queryOptions: {
85
- enabled: inView
86
- },
87
- children: inView && /*#__PURE__*/ (0, _jsxruntime.jsx)(_Panel.Panel, {
88
- definition: panelDefinition,
89
- readHandlers: readHandlers,
90
- editHandlers: editHandlers,
91
- panelOptions: props.panelOptions,
92
- panelGroupItemId: panelGroupItemId
163
+ children: [
164
+ /*#__PURE__*/ (0, _jsxruntime.jsxs)(_material.Dialog, {
165
+ fullWidth: true,
166
+ PaperProps: {
167
+ sx: {
168
+ margin: '10px',
169
+ width: 'calc(100% - 20px)'
170
+ }
171
+ },
172
+ maxWidth: "lg",
173
+ open: openQueryViewer,
174
+ children: [
175
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.DialogTitle, {
176
+ children: "Query Viewer"
177
+ }),
178
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.DialogContent, {
179
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Box, {
180
+ sx: {
181
+ padding: '5px'
182
+ },
183
+ children: queryRows
184
+ })
185
+ }),
186
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.DialogActions, {
187
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Button, {
188
+ variant: "outlined",
189
+ onClick: onCloseHandler,
190
+ color: "primary",
191
+ children: "Close"
192
+ })
193
+ })
194
+ ]
195
+ }),
196
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.DataQueriesProvider, {
197
+ definitions: definitions,
198
+ options: {
199
+ suggestedStepMs,
200
+ ...pluginQueryOptions
201
+ },
202
+ queryOptions: {
203
+ enabled: inView
204
+ },
205
+ children: inView && /*#__PURE__*/ (0, _jsxruntime.jsx)(_Panel.Panel, {
206
+ definition: panelDefinition,
207
+ readHandlers: readHandlers,
208
+ editHandlers: editHandlers,
209
+ viewQueriesHandler: viewQueriesHandler,
210
+ panelOptions: props.panelOptions,
211
+ panelGroupItemId: panelGroupItemId
212
+ })
93
213
  })
94
- })
214
+ ]
95
215
  });
96
216
  }
@@ -14,67 +14,34 @@
14
14
  Object.defineProperty(exports, "__esModule", {
15
15
  value: true
16
16
  });
17
- Object.defineProperty(exports, "GridLayout", {
18
- enumerable: true,
19
- get: function() {
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: all[name]
21
+ });
22
+ }
23
+ _export(exports, {
24
+ GridLayout: function() {
20
25
  return GridLayout;
26
+ },
27
+ RepeatGridLayout: function() {
28
+ return RepeatGridLayout;
21
29
  }
22
30
  });
23
31
  const _jsxruntime = require("react/jsx-runtime");
24
32
  const _react = require("react");
25
- const _reactgridlayout = require("react-grid-layout");
26
- const _material = require("@mui/material");
27
- const _components = require("@perses-dev/components");
33
+ const _pluginsystem = require("@perses-dev/plugin-system");
28
34
  const _context = require("../../context");
29
35
  const _constants = require("../../constants");
30
- const _GridTitle = require("./GridTitle");
31
- const _GridItemContent = require("./GridItemContent");
32
- const _GridContainer = require("./GridContainer");
33
- const DEFAULT_MARGIN = 10;
34
- const ROW_HEIGHT = 30;
36
+ const _Row = require("./Row");
35
37
  function GridLayout(props) {
36
38
  const { panelGroupId, panelOptions, panelFullHeight } = props;
37
- const theme = (0, _material.useTheme)();
38
39
  const groupDefinition = (0, _context.usePanelGroup)(panelGroupId);
39
40
  const { updatePanelGroupLayouts } = (0, _context.usePanelGroupActions)(panelGroupId);
40
- const [isOpen, setIsOpen] = (0, _react.useState)(!groupDefinition.isCollapsed);
41
+ const viewPanelItemId = (0, _context.useViewPanelGroup)();
41
42
  const { isEditMode } = (0, _context.useEditMode)();
42
43
  const [gridColWidth, setGridColWidth] = (0, _react.useState)(0);
43
- const viewPanelItemId = (0, _context.useViewPanelGroup)();
44
44
  const hasViewPanel = viewPanelItemId?.panelGroupId === panelGroupId; // current panelGroup contains the panel extended?
45
- const itemLayoutViewed = viewPanelItemId?.panelGroupItemLayoutId;
46
- (0, _react.useEffect)(()=>{
47
- if (hasViewPanel) {
48
- setIsOpen(true);
49
- }
50
- }, [
51
- hasViewPanel
52
- ]);
53
- // If there is a panel in view mode, we should hide the grid if the panel is not in the current group.
54
- const isGridDisplayed = viewPanelItemId === undefined || hasViewPanel;
55
- // Item layout is override if there is a panel in view mode
56
- const itemLayouts = (0, _react.useMemo)(()=>{
57
- if (itemLayoutViewed) {
58
- return groupDefinition.itemLayouts.map((itemLayout)=>{
59
- if (itemLayout.i === itemLayoutViewed) {
60
- const rowTitleHeight = 40 + 8; // 40 is the height of the row title and 8 is the margin height
61
- return {
62
- h: Math.round(((panelFullHeight ?? window.innerHeight) - rowTitleHeight) / (ROW_HEIGHT + DEFAULT_MARGIN)),
63
- i: itemLayoutViewed,
64
- w: 48,
65
- x: 0,
66
- y: 0
67
- };
68
- }
69
- return itemLayout;
70
- });
71
- }
72
- return groupDefinition.itemLayouts;
73
- }, [
74
- groupDefinition.itemLayouts,
75
- itemLayoutViewed,
76
- panelFullHeight
77
- ]);
78
45
  const handleLayoutChange = (currentLayout, allLayouts)=>{
79
46
  // Using the value from `allLayouts` instead of `currentLayout` because of
80
47
  // a bug in react-layout-grid where `currentLayout` does not adjust properly
@@ -95,85 +62,70 @@ function GridLayout(props) {
95
62
  // exclude margin and padding from total width
96
63
  setGridColWidth((containerWidth - marginWidth - containerPaddingWidth) / cols);
97
64
  };
98
- // https://github.com/react-grid-layout/react-grid-layout?tab=readme-ov-file#react-hooks-performance
99
- const ResponsiveGridLayout = (0, _react.useMemo)(()=>(0, _reactgridlayout.WidthProvider)(_reactgridlayout.Responsive), []);
100
- return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_GridContainer.GridContainer, {
101
- sx: {
102
- display: isGridDisplayed ? 'block' : 'none',
103
- height: itemLayoutViewed ? `${panelFullHeight}px` : 'unset',
104
- overflow: itemLayoutViewed ? 'hidden' : 'unset'
105
- },
106
- children: [
107
- groupDefinition.title !== undefined && /*#__PURE__*/ (0, _jsxruntime.jsx)(_GridTitle.GridTitle, {
108
- panelGroupId: panelGroupId,
109
- title: groupDefinition.title,
110
- collapse: groupDefinition.isCollapsed === undefined ? undefined : {
111
- isOpen,
112
- onToggleOpen: ()=>setIsOpen((current)=>!current)
113
- }
114
- }),
115
- /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Collapse, {
116
- in: isOpen,
117
- unmountOnExit: true,
118
- appear: false,
119
- "data-testid": "panel-group-content",
120
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(ResponsiveGridLayout, {
121
- className: "layout",
122
- breakpoints: {
123
- sm: theme.breakpoints.values.sm,
124
- xxs: 0
125
- },
126
- cols: _constants.GRID_LAYOUT_COLS,
127
- rowHeight: ROW_HEIGHT,
128
- draggableHandle: ".drag-handle",
129
- resizeHandles: [
130
- 'se'
131
- ],
132
- isDraggable: isEditMode && !hasViewPanel,
133
- isResizable: isEditMode && !hasViewPanel,
134
- margin: [
135
- DEFAULT_MARGIN,
136
- DEFAULT_MARGIN
137
- ],
138
- containerPadding: [
139
- 0,
140
- 10
141
- ],
142
- layouts: {
143
- [_constants.GRID_LAYOUT_SMALL_BREAKPOINT]: itemLayouts
144
- },
145
- onLayoutChange: handleLayoutChange,
146
- onWidthChange: handleWidthChange,
147
- allowOverlap: hasViewPanel,
148
- children: itemLayouts.map(({ i, w })=>/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
149
- style: {
150
- display: itemLayoutViewed !== undefined ? itemLayoutViewed === i ? 'unset' : 'none' : 'unset'
151
- },
152
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorBoundary, {
153
- FallbackComponent: _components.ErrorAlert,
154
- children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_GridItemContent.GridItemContent, {
155
- panelOptions: panelOptions,
156
- panelGroupItemId: {
157
- panelGroupId,
158
- panelGroupItemLayoutId: i
159
- },
160
- width: calculateGridItemWidth(w, gridColWidth)
161
- })
162
- })
163
- }, i))
65
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
66
+ children: !groupDefinition.repeatVariable ? /*#__PURE__*/ (0, _jsxruntime.jsx)(_Row.Row, {
67
+ panelGroupId: panelGroupId,
68
+ groupDefinition: groupDefinition,
69
+ gridColWidth: gridColWidth,
70
+ panelFullHeight: panelFullHeight,
71
+ panelOptions: panelOptions,
72
+ isEditMode: isEditMode,
73
+ onLayoutChange: handleLayoutChange,
74
+ onWidthChange: handleWidthChange
75
+ }) : /*#__PURE__*/ (0, _jsxruntime.jsx)(RepeatGridLayout, {
76
+ repeatVariableName: groupDefinition.repeatVariable,
77
+ panelGroupId: panelGroupId,
78
+ groupDefinition: groupDefinition,
79
+ gridColWidth: gridColWidth,
80
+ panelFullHeight: panelFullHeight,
81
+ panelOptions: panelOptions,
82
+ isEditMode: isEditMode,
83
+ onLayoutChange: handleLayoutChange,
84
+ onWidthChange: handleWidthChange
85
+ })
86
+ });
87
+ }
88
+ function RepeatGridLayout({ repeatVariableName, panelGroupId, groupDefinition, gridColWidth, panelFullHeight, panelOptions, isEditMode = false, onLayoutChange, onWidthChange }) {
89
+ const variables = (0, _pluginsystem.useVariableValues)();
90
+ const variable = variables[repeatVariableName];
91
+ // If the variable is not defined, or if it is defined but has no values, render a standard row without repeating
92
+ if (variable === undefined || !Array.isArray(variable.value) || variable.value.length === 0) {
93
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_Row.Row, {
94
+ panelGroupId: panelGroupId,
95
+ groupDefinition: groupDefinition,
96
+ gridColWidth: gridColWidth,
97
+ panelFullHeight: panelFullHeight,
98
+ panelOptions: panelOptions,
99
+ isEditMode: isEditMode,
100
+ onLayoutChange: onLayoutChange,
101
+ onWidthChange: onWidthChange
102
+ });
103
+ }
104
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {
105
+ children: variable.value.map((value)=>/*#__PURE__*/ (0, _jsxruntime.jsx)(_pluginsystem.VariableContext.Provider, {
106
+ value: {
107
+ state: {
108
+ ...variables,
109
+ [repeatVariableName]: {
110
+ value,
111
+ loading: false
112
+ }
113
+ }
114
+ },
115
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_Row.Row, {
116
+ panelGroupId: panelGroupId,
117
+ groupDefinition: groupDefinition,
118
+ gridColWidth: gridColWidth,
119
+ panelFullHeight: panelFullHeight,
120
+ panelOptions: panelOptions,
121
+ isEditMode: isEditMode,
122
+ onLayoutChange: onLayoutChange,
123
+ onWidthChange: onWidthChange,
124
+ repeatVariable: [
125
+ repeatVariableName,
126
+ value
127
+ ]
164
128
  })
165
- })
166
- ]
129
+ }, `${repeatVariableName}-${value}`))
167
130
  });
168
131
  }
169
- /**
170
- * Calculates grid item width
171
- * @param w number of columns the grid item spans
172
- * @param colWidth the width of each column in px
173
- * @returns grid item's width in px
174
- * https://github.com/react-grid-layout/react-grid-layout/blob/master/lib/calculateUtils.js#L14-L35
175
- */ const calculateGridItemWidth = (w, colWidth)=>{
176
- // 0 * Infinity === NaN, which causes problems with resize contraints
177
- if (!Number.isFinite(w)) return w;
178
- return Math.round(colWidth * w + Math.max(0, w - 1) * DEFAULT_MARGIN);
179
- };
@@ -0,0 +1,150 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "Row", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return Row;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _material = require("@mui/material");
25
+ const _dashboards = require("@perses-dev/dashboards");
26
+ const _react = require("react");
27
+ const _reactgridlayout = require("react-grid-layout");
28
+ const _components = require("@perses-dev/components");
29
+ const _constants = require("../../constants");
30
+ const _GridContainer = require("./GridContainer");
31
+ const _GridItemContent = require("./GridItemContent");
32
+ const _GridTitle = require("./GridTitle");
33
+ const DEFAULT_MARGIN = 10;
34
+ const ROW_HEIGHT = 30;
35
+ function Row({ panelGroupId, groupDefinition, gridColWidth, panelFullHeight, panelOptions, isEditMode = false, onLayoutChange, onWidthChange, repeatVariable }) {
36
+ const ResponsiveGridLayout = (0, _react.useMemo)(()=>(0, _reactgridlayout.WidthProvider)(_reactgridlayout.Responsive), []);
37
+ const theme = (0, _material.useTheme)();
38
+ const viewPanelItemId = (0, _dashboards.useViewPanelGroup)();
39
+ const [isOpen, setIsOpen] = (0, _react.useState)(!groupDefinition.isCollapsed);
40
+ const hasViewPanel = viewPanelItemId?.panelGroupId === panelGroupId && // Check for repeatVariable panels
41
+ viewPanelItemId.repeatVariable?.[0] === repeatVariable?.[0] && viewPanelItemId.repeatVariable?.[1] === repeatVariable?.[1];
42
+ const itemLayoutViewed = viewPanelItemId?.panelGroupItemLayoutId;
43
+ // If there is a panel in view mode, we should hide the grid if the panel is not in the current group.
44
+ const isGridDisplayed = !viewPanelItemId || hasViewPanel;
45
+ // TODO: handle it without useEffect
46
+ (0, _react.useEffect)(()=>{
47
+ if (hasViewPanel) {
48
+ setIsOpen(true);
49
+ }
50
+ }, [
51
+ hasViewPanel
52
+ ]);
53
+ // Item layout is override if there is a panel in view mode
54
+ const itemLayouts = (0, _react.useMemo)(()=>{
55
+ if (itemLayoutViewed) {
56
+ return groupDefinition.itemLayouts.map((itemLayout)=>{
57
+ if (itemLayout.i === itemLayoutViewed) {
58
+ const rowTitleHeight = 40 + 8; // 40 is the height of the row title and 8 is the margin height
59
+ return {
60
+ h: Math.round(((panelFullHeight ?? window.innerHeight) - rowTitleHeight) / (ROW_HEIGHT + DEFAULT_MARGIN)),
61
+ i: itemLayoutViewed,
62
+ w: 48,
63
+ x: 0,
64
+ y: 0
65
+ };
66
+ }
67
+ return itemLayout;
68
+ });
69
+ }
70
+ return groupDefinition.itemLayouts;
71
+ }, [
72
+ groupDefinition.itemLayouts,
73
+ itemLayoutViewed,
74
+ panelFullHeight
75
+ ]);
76
+ return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_GridContainer.GridContainer, {
77
+ sx: {
78
+ display: isGridDisplayed ? 'block' : 'none',
79
+ height: itemLayoutViewed ? `${panelFullHeight}px` : 'unset',
80
+ overflow: itemLayoutViewed ? 'hidden' : 'unset'
81
+ },
82
+ children: [
83
+ groupDefinition.title && /*#__PURE__*/ (0, _jsxruntime.jsx)(_GridTitle.GridTitle, {
84
+ panelGroupId: panelGroupId,
85
+ title: groupDefinition.title,
86
+ collapse: groupDefinition.isCollapsed === undefined ? undefined : {
87
+ isOpen: isOpen,
88
+ onToggleOpen: ()=>setIsOpen((current)=>!current)
89
+ }
90
+ }),
91
+ /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Collapse, {
92
+ in: isOpen,
93
+ unmountOnExit: true,
94
+ appear: false,
95
+ "data-testid": "panel-group-content",
96
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(ResponsiveGridLayout, {
97
+ className: "layout",
98
+ breakpoints: {
99
+ [_constants.GRID_LAYOUT_SMALL_BREAKPOINT]: theme.breakpoints.values.sm,
100
+ xxs: 0
101
+ },
102
+ cols: _constants.GRID_LAYOUT_COLS,
103
+ rowHeight: ROW_HEIGHT,
104
+ draggableHandle: ".drag-handle",
105
+ resizeHandles: [
106
+ 'se'
107
+ ],
108
+ isDraggable: isEditMode && !hasViewPanel,
109
+ isResizable: isEditMode && !hasViewPanel,
110
+ margin: [
111
+ DEFAULT_MARGIN,
112
+ DEFAULT_MARGIN
113
+ ],
114
+ containerPadding: [
115
+ 0,
116
+ 10
117
+ ],
118
+ layouts: {
119
+ sm: itemLayouts
120
+ },
121
+ onLayoutChange: onLayoutChange,
122
+ onWidthChange: onWidthChange,
123
+ allowOverlap: hasViewPanel,
124
+ children: itemLayouts.map(({ i, w })=>/*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
125
+ style: {
126
+ display: itemLayoutViewed ? itemLayoutViewed === i ? 'unset' : 'none' : 'unset'
127
+ },
128
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_components.ErrorBoundary, {
129
+ FallbackComponent: _components.ErrorAlert,
130
+ children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_GridItemContent.GridItemContent, {
131
+ panelOptions: panelOptions,
132
+ panelGroupItemId: {
133
+ panelGroupId,
134
+ panelGroupItemLayoutId: i,
135
+ repeatVariable
136
+ },
137
+ width: calculateGridItemWidth(w, gridColWidth)
138
+ })
139
+ })
140
+ }, i))
141
+ })
142
+ })
143
+ ]
144
+ });
145
+ }
146
+ const calculateGridItemWidth = (w, colWidth)=>{
147
+ // 0 * Infinity === NaN, which causes problems with resize contraints
148
+ if (!Number.isFinite(w)) return w;
149
+ return Math.round(colWidth * w + Math.max(0, w - 1) * DEFAULT_MARGIN);
150
+ };
@@ -18,6 +18,7 @@ _export_star(require("./GridContainer"), exports);
18
18
  _export_star(require("./GridItemContent"), exports);
19
19
  _export_star(require("./GridLayout"), exports);
20
20
  _export_star(require("./GridTitle"), exports);
21
+ _export_star(require("./Row"), exports);
21
22
  function _export_star(from, to) {
22
23
  Object.keys(from).forEach(function(k) {
23
24
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,44 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "LeaveDialog", {
18
+ enumerable: true,
19
+ get: function() {
20
+ return LeaveDialog;
21
+ }
22
+ });
23
+ const _jsxruntime = require("react/jsx-runtime");
24
+ const _react = require("react");
25
+ function LeaveDialog({ original, current }) {
26
+ (0, _react.useEffect)(()=>{
27
+ const handleBeforeUnload = (event)=>{
28
+ if (JSON.stringify(original) === JSON.stringify(current)) {
29
+ return null;
30
+ }
31
+ event.preventDefault();
32
+ event.returnValue = ''; // Required for Chrome
33
+ return ''; // Required for other browsers
34
+ };
35
+ window.addEventListener('beforeunload', handleBeforeUnload);
36
+ return ()=>{
37
+ window.removeEventListener('beforeunload', handleBeforeUnload);
38
+ };
39
+ }, [
40
+ original,
41
+ current
42
+ ]);
43
+ return /*#__PURE__*/ (0, _jsxruntime.jsx)(_jsxruntime.Fragment, {});
44
+ }
@@ -0,0 +1,30 @@
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
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _export_star(require("./LeaveDialog"), exports);
18
+ function _export_star(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
21
+ Object.defineProperty(to, k, {
22
+ enumerable: true,
23
+ get: function() {
24
+ return from[k];
25
+ }
26
+ });
27
+ }
28
+ });
29
+ return from;
30
+ }