Skip to content

react-grid-layout 1.4.3 -> 1.5.0 #3880

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

Merged
merged 3 commits into from
Dec 30, 2024
Merged
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 @@ -54,6 +54,10 @@
provided by FontAwesome.
* Improved accuracy of `PersistOptions.type` enum.

### 📚 Libraries

* react-grid-layout `1.4.3 → 1.5.0`

## v70.0.0 - 2024-11-15

### 💥 Breaking Changes (upgrade difficulty: 🟢 LOW - changes to advanced persistence APIs)
Expand Down
15 changes: 5 additions & 10 deletions desktop/cmp/dash/canvas/DashCanvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,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 {DashCanvasModel} from './DashCanvasModel';
Expand Down Expand Up @@ -49,13 +48,8 @@ export const [DashCanvas, dashCanvas] = hoistCmp.withFactory<DashCanvasProps>({

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

ref = composeRefs(
ref,
model.ref,
useOnVisibleChange(viz => model.onVisibleChange(viz))
);
isResizable = !model.layoutLocked,
[padX, padY] = model.containerPadding;

return refreshContextView({
model: model.refreshContextModel,
Expand All @@ -65,7 +59,8 @@ export const [DashCanvas, dashCanvas] = hoistCmp.withFactory<DashCanvasProps>({
isDraggable ? `${className}--draggable` : null,
isResizable ? `${className}--resizable` : null
),
ref,
style: {padding: `${padY}px ${padX}px`},
ref: composeRefs(ref, model.ref),
onContextMenu: e => onContextMenu(e, model),
items: [
reactGridLayout({
Expand All @@ -77,7 +72,7 @@ export const [DashCanvas, dashCanvas] = hoistCmp.withFactory<DashCanvasProps>({
compactType: model.compact ? 'vertical' : null,
margin: model.margin,
maxRows: model.maxRows,
containerPadding: model.containerPadding,
containerPadding: [0, 0], // Workaround for https://github.com/react-grid-layout/react-grid-layout/issues/1990
autoSize: true,
isBounded: true,
draggableHandle:
Expand Down
57 changes: 17 additions & 40 deletions desktop/cmp/dash/canvas/DashCanvasModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,28 @@ import {
} from 'lodash';

export interface DashCanvasConfig extends DashConfig<DashCanvasViewSpec, DashCanvasItemState> {
/** Total number of columns (x coordinates for views correspond with column numbers). */
/**
* Total number of columns (x coordinates for views correspond with column numbers).
* Default `12`.
*/
columns?: number;

/** Height of each row in pixels (y coordinates for views correspond with row numbers). */
/**
* Height of each row in pixels (y coordinates for views correspond with row numbers).
* Default `50`.
*/
rowHeight?: number;

/** Whether views should "compact" vertically to condense vertical space. */
/** Whether views should "compact" vertically to condense vertical space. Default `true`. */
compact?: boolean;

/** Between items [x,y] in pixels. */
/** Between items [x,y] in pixels. Default `[10, 10]`. */
margin?: [number, number];

/** Maximum number of rows permitted for this container. */
/** Maximum number of rows permitted for this container. Default `Infinity`. */
maxRows?: number;

/** Padding inside the container [x, y] in pixels. */
/** Padding inside the container [x, y] in pixels. Defaults to same as `margin`. */
containerPadding?: [number, number];
}

Expand Down Expand Up @@ -97,7 +103,6 @@ export class DashCanvasModel
@observable.ref layout: any[] = [];
ref = createObservableRef<HTMLElement>();
isResizing: boolean;
private scrollbarVisible: boolean;
private isLoadingState: boolean;

get rglLayout() {
Expand Down Expand Up @@ -131,7 +136,7 @@ export class DashCanvasModel
compact = true,
margin = [10, 10],
maxRows = Infinity,
containerPadding = null,
containerPadding = margin,
extraMenuItems
}: DashCanvasConfig) {
super();
Expand Down Expand Up @@ -194,19 +199,10 @@ export class DashCanvasModel
});
}

this.addReaction(
{
track: () => this.viewState,
run: () => (this.state = this.buildState())
},
{
when: () => !!this.ref.current,
run: () => {
const {current: node} = this.ref;
this.scrollbarVisible = node.offsetWidth > node.clientWidth;
}
}
);
this.addReaction({
track: () => this.viewState,
run: () => (this.state = this.buildState())
});
}

/** Removes all views from the canvas */
Expand Down Expand Up @@ -385,12 +381,6 @@ export class DashCanvasModel
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 @@ -404,15 +394,6 @@ export class DashCanvasModel

this.layout = layout;
if (!this.isLoadingState) this.state = this.buildState();

// Check if scrollbar visibility has changed, and force resize event if so
const node = this.ref.current;
if (!node) return;
const scrollbarVisible = node.offsetWidth > node.clientWidth;
if (scrollbarVisible !== this.scrollbarVisible) {
this.fireWindowResizeEvent();
this.scrollbarVisible = scrollbarVisible;
}
}

@action
Expand Down Expand Up @@ -530,8 +511,4 @@ export class DashCanvasModel

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

private fireWindowResizeEvent() {
window.dispatchEvent(new Event('resize'));
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"react-beautiful-dnd": "~13.1.0",
"react-dates": "~21.8.0",
"react-dropzone": "~10.2.2",
"react-grid-layout": "1.4.3",
"react-grid-layout": "1.5.0",
"react-markdown": "~9.0.1",
"react-onsenui": "~1.13.2",
"react-popper": "~2.3.0",
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6427,10 +6427,10 @@ react-fast-compare@^3.0.1:
resolved "https://registry.yarnpkg.com/react-fast-compare/-/react-fast-compare-3.2.2.tgz#929a97a532304ce9fee4bcae44234f1ce2c21d49"
integrity sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ==

react-grid-layout@1.4.3:
version "1.4.3"
resolved "https://registry.yarnpkg.com/react-grid-layout/-/react-grid-layout-1.4.3.tgz#9622c4dbdbc863bf1a29a50ed5c35c4c52922d3a"
integrity sha512-maZJfspM5aDmO/1kJj1U13HQ44rh6svcV7VQPOU9c2UfZhh8Z5AuZb+iVrzETWjsisHBYD3e2zckVovUnqvGHA==
react-grid-layout@1.5.0:
version "1.5.0"
resolved "https://registry.yarnpkg.com/react-grid-layout/-/react-grid-layout-1.5.0.tgz#b6cc9412b58cf8226aebc0df7673d6fa782bdee2"
integrity sha512-WBKX7w/LsTfI99WskSu6nX2nbJAUD7GD6nIXcwYLyPpnslojtmql2oD3I2g5C3AK8hrxIarYT8awhuDIp7iQ5w==
dependencies:
clsx "^2.0.0"
fast-equals "^4.0.3"
Expand Down
Loading