Skip to content

Commit a8ea804

Browse files
authored
[Dashboard] Fix resize bug (#233755)
Closes #233517 ## Summary This fixes a bug where panels could not be resized to the max width when using a serverless / solution view. Essentially, when calculating the "max right" position of the panel on resize, we were not accounting for the left navigation. Rather than using the **panel** element to determine what the maximum right pixel is, we must use the layout element instead since it takes into account the left offset. | Before (no left nav) | After (no left nav) | |--------|--------| | ![Sep-02-2025 09-52-00](https://github.com/user-attachments/assets/77c9a2c3-b93f-488e-b1c1-b4ee3ab1f06f) | ![Sep-02-2025 09-42-17](https://github.com/user-attachments/assets/05bdc446-9266-480c-a615-7d5d452a50a9) | | Before (left nav) | After (left nav) | |--------|--------| | ![Sep-02-2025 09-53-07](https://github.com/user-attachments/assets/11bff577-973d-42df-9035-e00038d86aeb) | ![Sep-02-2025 09-45-18](https://github.com/user-attachments/assets/02ad582e-6b4c-4525-a522-330a3f7b7ea0) | ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [x] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels.
1 parent e8eb4c6 commit a8ea804

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

src/platform/packages/private/kbn-grid-layout/grid/use_grid_layout_events/panel/state_manager_actions.test.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
import type { MutableRefObject } from 'react';
11-
import type { GridPanelData } from '../../grid_panel';
11+
import type { ActivePanelEvent, GridPanelData } from '../../grid_panel';
1212
import { getGridLayoutStateManagerMock } from '../../test_utils/mocks';
1313
import { getSampleOrderedLayout } from '../../test_utils/sample_layout';
1414
import { moveAction } from './state_manager_actions';
@@ -34,7 +34,9 @@ describe('panel state manager actions', () => {
3434
} as any as HTMLDivElement,
3535
};
3636
gridLayoutStateManager.layoutRef.current = {
37-
getBoundingClientRect: jest.fn().mockReturnValue({ top: 0, height: 100, bottom: 100 }),
37+
getBoundingClientRect: jest
38+
.fn()
39+
.mockReturnValue({ top: 0, height: 100, bottom: 100, left: 0, width: 200, right: 200 }),
3840
} as any as HTMLDivElement;
3941
});
4042

@@ -135,6 +137,51 @@ describe('panel state manager actions', () => {
135137
expect(panel.height).toBe(2);
136138
expect(panel.width).toBe(2);
137139
});
140+
141+
it('can extend panel to the full width of the layout when it is offset', () => {
142+
gridLayoutStateManager.layoutRef.current = {
143+
getBoundingClientRect: jest.fn().mockReturnValue({
144+
top: 0,
145+
height: 100,
146+
bottom: 100,
147+
left: 100, // offset the layout by 100 pixels
148+
width: 200,
149+
right: 100 + 872, // 872 = the width of the layout when column pixel width is 10
150+
}),
151+
} as any as HTMLDivElement;
152+
gridLayoutStateManager.panelRefs.current.panel1 = {
153+
getBoundingClientRect: jest.fn().mockReturnValue({
154+
top: 0,
155+
left: 100, // offset the panel by 100 pixels to the left as well
156+
right: 150,
157+
bottom: 50,
158+
height: 50,
159+
width: 50,
160+
}),
161+
scrollIntoView: jest.fn(),
162+
} as any as HTMLDivElement;
163+
164+
// update the active panel event
165+
gridLayoutStateManager.activePanelEvent$.next({
166+
...(gridLayoutStateManager.activePanelEvent$.getValue() as ActivePanelEvent),
167+
panelDiv: gridLayoutStateManager.panelRefs.current.panel1!,
168+
});
169+
170+
// bring the mouse **way** to the right to try to make the panel as big as possible
171+
moveAction(
172+
new MouseEvent('pointerdown', { clientX: 0, clientY: 0 }),
173+
gridLayoutStateManager,
174+
{
175+
clientX: 10000,
176+
clientY: 0,
177+
},
178+
lastRequestedPanelPosition
179+
);
180+
181+
// the panel reaches the end of the layout
182+
const panel = gridLayoutStateManager.gridLayout$.getValue()['main-0'].panels.panel1;
183+
expect(panel.width).toBe(48);
184+
});
138185
});
139186
});
140187
});

src/platform/packages/private/kbn-grid-layout/grid/use_grid_layout_events/panel/state_manager_actions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,15 @@ export const moveAction = (
7676
const previewRect = (() => {
7777
if (isResize) {
7878
const { resizeOptions } = currentPanelData;
79+
const maxRight = gridLayoutElement
80+
? gridLayoutElement.getBoundingClientRect().right
81+
: window.innerWidth;
7982
return getResizePreviewRect({
8083
activePanel,
8184
pointerPixel,
8285
runtimeSettings,
8386
resizeOptions,
87+
maxRight,
8488
});
8589
} else {
8690
return getDragPreviewRect({ activePanel, pointerPixel });

src/platform/packages/private/kbn-grid-layout/grid/use_grid_layout_events/panel/utils.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@ export const getResizePreviewRect = ({
4646
pointerPixel,
4747
runtimeSettings,
4848
resizeOptions,
49+
maxRight,
4950
}: {
5051
pointerPixel: PointerPosition;
5152
activePanel: ActivePanelEvent;
5253
runtimeSettings: RuntimeGridSettings;
5354
resizeOptions: GridPanelData['resizeOptions'];
55+
maxRight: number;
5456
}) => {
5557
const panelRect = activePanel.panelDiv.getBoundingClientRect();
5658
const { minWidth, maxWidth, minHeight, maxHeight } = {
@@ -72,8 +74,7 @@ export const getResizePreviewRect = ({
7274
pointerPixel.clientX - activePanel.sensorOffsets.right, // actual width based on mouse position
7375
panelRect.left + getColumnCountInPixels({ columnCount: maxWidth, runtimeSettings }), // max width of panel
7476
// cannot extend width past the right edge of the grid layout
75-
getColumnCountInPixels({ columnCount: runtimeSettings.columnCount, runtimeSettings }) +
76-
runtimeSettings.gutterSize
77+
maxRight
7778
),
7879
panelRect.left + getColumnCountInPixels({ columnCount: minWidth, runtimeSettings }) // min width of panel
7980
),

0 commit comments

Comments
 (0)