Skip to content

Commit 6982b97

Browse files
committed
[FIX] dashboard: properly handle grid resize in dashboard mode
Before this commit: - The canvas size was computed from the grid, which caused visible white margins after a snappy resize (commit 3c8df4b). - Some unused props were being passed, creating unnecessary code clutter. After this commit: - The dashboard canvas size is now computed as the min of the grid bounds and the end of getColDimension. - Shows only visible parts and avoids extra canvas processing. Task: 5223156
1 parent 2a23ddd commit 6982b97

File tree

6 files changed

+41
-45
lines changed

6 files changed

+41
-45
lines changed

src/components/dashboard/dashboard.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ import { Popover } from "../popover/popover";
2121
import { HorizontalScrollBar, VerticalScrollBar } from "../scrollbar/";
2222
import { ClickableCell, ClickableCellsStore } from "./clickable_cell_store";
2323

24-
interface Props {}
24+
interface Props {
25+
getGridSize: () => DOMDimension;
26+
}
2527

2628
css/* scss */ `
2729
.o-dashboard-clickable-cell {
@@ -70,10 +72,8 @@ export class SpreadsheetDashboard extends Component<Props, SpreadsheetChildEnv>
7072
}
7173

7274
get gridContainer() {
73-
const sheetId = this.env.model.getters.getActiveSheetId();
74-
const { right } = this.env.model.getters.getSheetZone(sheetId);
75-
const { end } = this.env.model.getters.getColDimensions(sheetId, right);
76-
return cssPropertiesToCss({ "max-width": `${end}px` });
75+
const maxWidth = this.getMaxSheetWidth();
76+
return cssPropertiesToCss({ "max-width": `${maxWidth}px` });
7777
}
7878

7979
get gridOverlayDimensions() {
@@ -111,10 +111,12 @@ export class SpreadsheetDashboard extends Component<Props, SpreadsheetChildEnv>
111111
this.cellPopovers.close();
112112
}
113113

114-
onGridResized({ height, width }: DOMDimension) {
114+
onGridResized() {
115+
const { height, width } = this.props.getGridSize();
116+
const maxWidth = this.getMaxSheetWidth();
115117
this.env.model.dispatch("RESIZE_SHEETVIEW", {
116-
width: width,
117-
height: height,
118+
width: Math.min(maxWidth, width),
119+
height,
118120
gridOffsetX: 0,
119121
gridOffsetY: 0,
120122
});
@@ -134,4 +136,10 @@ export class SpreadsheetDashboard extends Component<Props, SpreadsheetChildEnv>
134136
...this.env.model.getters.getSheetViewDimensionWithHeaders(),
135137
};
136138
}
139+
140+
private getMaxSheetWidth(): Pixel {
141+
const sheetId = this.env.model.getters.getActiveSheetId();
142+
const { right } = this.env.model.getters.getSheetZone(sheetId);
143+
return this.env.model.getters.getColDimensions(sheetId, right).end;
144+
}
137145
}

src/components/dashboard/dashboard.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
<GridOverlay
66
onGridResized.bind="onGridResized"
77
onGridMoved.bind="moveCanvas"
8-
gridOverlayDimensions="gridOverlayDimensions"
9-
getGridSize="props.getGridSize">
8+
gridOverlayDimensions="gridOverlayDimensions">
109
<div
1110
t-foreach="getClickableCells()"
1211
t-as="clickableCell"

src/components/grid/grid.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,8 @@ export class Grid extends Component<Props, SpreadsheetChildEnv> {
450450
return !(rect.width === 0 || rect.height === 0);
451451
}
452452

453-
onGridResized({ height, width }: DOMDimension) {
453+
onGridResized() {
454+
const { height, width } = this.props.getGridSize();
454455
this.env.model.dispatch("RESIZE_SHEETVIEW", {
455456
width: width - HEADER_WIDTH,
456457
height: height - HEADER_HEIGHT,

src/components/grid/grid.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
onGridMoved.bind="moveCanvas"
1717
gridOverlayDimensions="gridOverlayDimensions"
1818
onFigureDeleted.bind="focusDefaultElement"
19-
getGridSize="props.getGridSize"
2019
/>
2120
<HeadersOverlay onOpenContextMenu="(type, x, y) => this.toggleContextMenu(type, x, y)"/>
2221
<GridComposer

src/components/grid_overlay/grid_overlay.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
HeaderIndex,
99
Pixel,
1010
Position,
11-
Rect,
1211
Ref,
1312
SpreadsheetChildEnv,
1413
} from "../../types";
@@ -151,11 +150,10 @@ interface Props {
151150
ev: PointerEvent | MouseEvent
152151
) => void;
153152
onCellRightClicked: (col: HeaderIndex, row: HeaderIndex, coordinates: DOMCoordinates) => void;
154-
onGridResized: (dimension: Rect) => void;
153+
onGridResized: () => void;
155154
onGridMoved: (deltaX: Pixel, deltaY: Pixel) => void;
156155
gridOverlayDimensions: string;
157156
onFigureDeleted: () => void;
158-
getGridSize: () => { width: number; height: number };
159157
}
160158

161159
export class GridOverlay extends Component<Props, SpreadsheetChildEnv> {
@@ -169,7 +167,6 @@ export class GridOverlay extends Component<Props, SpreadsheetChildEnv> {
169167
onGridMoved: Function,
170168
gridOverlayDimensions: String,
171169
slots: { type: Object, optional: true },
172-
getGridSize: Function,
173170
};
174171
static components = {
175172
FiguresContainer,
@@ -190,14 +187,7 @@ export class GridOverlay extends Component<Props, SpreadsheetChildEnv> {
190187
setup() {
191188
useCellHovered(this.env, this.gridOverlay);
192189
const resizeObserver = new ResizeObserver(() => {
193-
const boundingRect = this.gridOverlayEl.getBoundingClientRect();
194-
const { width, height } = this.props.getGridSize();
195-
this.props.onGridResized({
196-
x: boundingRect.left,
197-
y: boundingRect.top,
198-
height: height,
199-
width: width,
200-
});
190+
this.props.onGridResized();
201191
});
202192
onMounted(() => {
203193
resizeObserver.observe(this.gridOverlayEl);

src/components/spreadsheet/spreadsheet.ts

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -547,26 +547,25 @@ export class Spreadsheet extends Component<SpreadsheetProps, SpreadsheetChildEnv
547547
}
548548

549549
getGridSize() {
550-
const topBarHeight =
551-
this.spreadsheetRef.el
552-
?.querySelector(".o-spreadsheet-topbar-wrapper")
553-
?.getBoundingClientRect().height || 0;
554-
const bottomBarHeight =
555-
this.spreadsheetRef.el
556-
?.querySelector(".o-spreadsheet-bottombar-wrapper")
557-
?.getBoundingClientRect().height || 0;
558-
559-
const gridWidth =
560-
this.spreadsheetRef.el?.querySelector(".o-grid")?.getBoundingClientRect().width || 0;
561-
const gridHeight =
562-
(this.spreadsheetRef.el?.getBoundingClientRect().height || 0) -
563-
(this.spreadsheetRef.el?.querySelector(".o-column-groups")?.getBoundingClientRect().height ||
564-
0) -
565-
topBarHeight -
566-
bottomBarHeight;
567-
return {
568-
width: Math.max(gridWidth - SCROLLBAR_WIDTH, 0),
569-
height: Math.max(gridHeight - SCROLLBAR_WIDTH, 0),
570-
};
550+
const el = this.spreadsheetRef.el;
551+
if (!el) {
552+
return { width: 0, height: 0 };
553+
}
554+
const getHeight = (selector) => el.querySelector(selector)?.getBoundingClientRect().height || 0;
555+
const getWidth = (selector) => el.querySelector(selector)?.getBoundingClientRect().width || 0;
556+
557+
const rect = el.getBoundingClientRect();
558+
const topBarHeight = getHeight(".o-spreadsheet-topbar-wrapper");
559+
const bottomBarHeight = getHeight(".o-spreadsheet-bottombar-wrapper");
560+
const colGroupHeight = getHeight(".o-column-groups");
561+
const gridWidth = getWidth(".o-grid");
562+
563+
const width = Math.max(gridWidth - SCROLLBAR_WIDTH, 0);
564+
const height = Math.max(
565+
rect.height - topBarHeight - bottomBarHeight - colGroupHeight - SCROLLBAR_WIDTH,
566+
0
567+
);
568+
569+
return { width, height };
571570
}
572571
}

0 commit comments

Comments
 (0)