Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React grid layout upgrade #3546

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

* Added additional layout support for `DockViews`

### 📚 Libraries

* react-grid-layout `1.3 -> 1.4`

## 59.4.0 - 2023-11-28

### 💥 Breaking Changes
Expand Down
12 changes: 2 additions & 10 deletions desktop/cmp/dash/canvas/DashCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
* Copyright © 2023 Extremely Heavy Industries Inc.
*/
import {ContextMenu} from '@blueprintjs/core';
import composeRefs from '@seznam/compose-react-refs';
import {div, vbox, vspacer} from '@xh/hoist/cmp/layout';
import {
elementFactory,
Expand All @@ -20,7 +19,6 @@ import {dashCanvasAddViewButton} from '@xh/hoist/desktop/cmp/button/DashCanvasAd
import '@xh/hoist/desktop/register';
import {Classes, overlay} from '@xh/hoist/kit/blueprint';
import {TEST_ID} from '@xh/hoist/utils/js';
import {useOnVisibleChange} from '@xh/hoist/utils/react';
import classNames from 'classnames';
import ReactGridLayout, {WidthProvider} from 'react-grid-layout';
import 'react-grid-layout/css/styles.css';
Expand All @@ -47,16 +45,10 @@ export const [DashCanvas, dashCanvas] = hoistCmp.withFactory<DashCanvasProps>({
className: 'xh-dash-canvas',
model: uses(DashCanvasModel),

render({className, model, testId}, ref) {
render({className, model, testId}) {
const isDraggable = !model.layoutLocked,
isResizable = !model.layoutLocked;

ref = composeRefs(
ref,
model.ref,
useOnVisibleChange(viz => model.onVisibleChange(viz))
);

return refreshContextView({
model: model.refreshContextModel,
item: div({
Expand All @@ -65,7 +57,7 @@ export const [DashCanvas, dashCanvas] = hoistCmp.withFactory<DashCanvasProps>({
isDraggable ? `${className}--draggable` : null,
isResizable ? `${className}--resizable` : null
),
ref,
ref: model.ref,
onContextMenu: e => onContextMenu(e, model),
items: [
reactGridLayout({
Expand Down
12 changes: 1 addition & 11 deletions desktop/cmp/dash/canvas/DashCanvasModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,6 @@ export class DashCanvasModel extends DashModel<
return model;
}

// Trigger window resize event when component becomes visible to ensure layout adjusted to
// current window size - fixes https://github.com/xh/hoist-react/issues/3215
onVisibleChange(visible: boolean) {
if (visible) this.fireWindowResizeEvent();
}

onRglLayoutChange(rglLayout) {
rglLayout = rglLayout.map(it => pick(it, ['i', 'x', 'y', 'w', 'h']));
this.setLayout(rglLayout);
Expand All @@ -403,7 +397,7 @@ export class DashCanvasModel extends DashModel<
if (!node) return;
const scrollbarVisible = node.offsetWidth > node.clientWidth;
if (scrollbarVisible !== this.scrollbarVisible) {
this.fireWindowResizeEvent();
window.dispatchEvent(new Event('resize'));
this.scrollbarVisible = scrollbarVisible;
}
}
Expand Down Expand Up @@ -529,8 +523,4 @@ export class DashCanvasModel extends DashModel<

return {x: defaultX, y: endY ?? rows};
}

private fireWindowResizeEvent() {
window.dispatchEvent(new Event('resize'));
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"@onsenui/fastclick": "~1.1.1",
"@popperjs/core": "~2.11.0",
"@seznam/compose-react-refs": "~1.0.5",
"@types/react-grid-layout": "^1.3.5",
"classnames": "~2.3.2",
"clipboard-copy": "~4.0.1",
"codemirror": "~5.65.0",
Expand All @@ -65,7 +66,7 @@
"react-beautiful-dnd": "~13.1.0",
"react-dates": "~21.8.0",
"react-dropzone": "~10.2.2",
"react-grid-layout": "^1.3.4",
"react-grid-layout": "~1.4.0",
"react-markdown": "^8.0.7",
"react-onsenui": "~1.13.2",
"react-popper": "~2.3.0",
Expand Down
Loading