Skip to content

Commit

Permalink
Remove resize event workaround (see react-grid-layout/react-grid-layo…
Browse files Browse the repository at this point in the history
  • Loading branch information
ghsolomon committed Dec 30, 2024
1 parent 4a6ec28 commit 81e12dd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 41 deletions.
9 changes: 1 addition & 8 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 @@ -52,12 +51,6 @@ export const [DashCanvas, dashCanvas] = hoistCmp.withFactory<DashCanvasProps>({
isResizable = !model.layoutLocked,
[padX, padY] = model.containerPadding ?? [10, 10];

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

return refreshContextView({
model: model.refreshContextModel,
item: div({
Expand All @@ -67,7 +60,7 @@ export const [DashCanvas, dashCanvas] = hoistCmp.withFactory<DashCanvasProps>({
isResizable ? `${className}--resizable` : null
),
style: {padding: `${padY}px ${padX}px`},
ref,
ref: composeRefs(ref, model.ref),
onContextMenu: e => onContextMenu(e, model),
items: [
reactGridLayout({
Expand Down
37 changes: 4 additions & 33 deletions desktop/cmp/dash/canvas/DashCanvasModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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 @@ -194,19 +193,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 +375,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 +388,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 +505,4 @@ export class DashCanvasModel

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

private fireWindowResizeEvent() {
window.dispatchEvent(new Event('resize'));
}
}

0 comments on commit 81e12dd

Please sign in to comment.