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

Improve properties panel resize performance #1091

Merged
merged 4 commits into from
Jan 11, 2019
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
6 changes: 3 additions & 3 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"form-data": "^2.3.1",
"glob": "^7.0.3",
"inherits": "^2.0.1",
"min-dash": "^3.2.0",
"min-dash": "^3.4.0",
"node-fetch": "^2.1.2",
"parents": "^1.0.1"
},
Expand Down
6 changes: 3 additions & 3 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"drag-tabs": "^1.0.2",
"formik": "^1.3.2",
"ids": "^0.2.2",
"min-dash": "^3.2.0",
"min-dash": "^3.4.0",
"p-defer": "^1.0.0",
"p-series": "^1.1.0",
"react": "^16.5.2",
Expand Down
62 changes: 40 additions & 22 deletions client/src/app/Log.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import classNames from 'classnames';

import dragger from '../util/dom/dragger';

import {
throttle
} from 'min-dash';


const DEFAULT_HEIGHT = 130;

const RESIZE_THROTTLE = 10;

/**
* A log component
*
Expand All @@ -27,6 +33,10 @@ export default class Log extends Component {
this.state = {};

this.panelRef = React.createRef();

if (process.env.NODE_ENV !== 'test') {
this.handleResize = throttle(this.handleResize, RESIZE_THROTTLE);
}
}

toggleLog = () => {
Expand Down Expand Up @@ -62,35 +72,41 @@ export default class Log extends Component {
});
}

/**
* Returns dragger with cached properties panel width.
*/
handleResize = (originalHeight) => {
handleResizeStart = event => {
const onDragStart = dragger(this.handleResize);

return dragger((event, delta) => {
const {
y
} = delta;
this.originalHeight = this.currentHeight;

const newHeight = originalHeight - y;
onDragStart(event);
}

handleResize = (_, delta) => {
const {
y
} = delta;

if (y === 0) {
return;
}

const newExpanded = newHeight > 25;
const newHeight = this.originalHeight - y;

const height = (newExpanded ? newHeight : DEFAULT_HEIGHT);
const newExpanded = newHeight > 25;

const {
expanded,
onToggle
} = this.props;
const height = (newExpanded ? newHeight : DEFAULT_HEIGHT);

this.setState({
height
});
const {
expanded,
onToggle
} = this.props;

if (expanded !== newExpanded) {
onToggle(newExpanded);
}
this.setState({
height
});

if (expanded !== newExpanded) {
onToggle(newExpanded);
}
}

checkFocus = () => {
Expand Down Expand Up @@ -175,6 +191,8 @@ export default class Log extends Component {

const logHeight = height || DEFAULT_HEIGHT;

this.currentHeight = logHeight;

return (
<div
className={ classNames(
Expand All @@ -194,7 +212,7 @@ export default class Log extends Component {

<div
className="resizer"
onDragStart={ this.handleResize(logHeight) }
onDragStart={ this.handleResizeStart }
draggable
></div>

Expand Down
36 changes: 36 additions & 0 deletions client/src/app/__tests__/LogSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,42 @@ describe('<Log>', function() {
});


describe('resize', function() {

it('should handle resize', function() {
// given
const {
instance
} = createLog();

instance.originalHeight = 100;

// when
instance.handleResize(null, { y: -10 });

// then
expect(instance.state.height).to.eql(110);
});


it('should ignore delta y = 0', function() {
// given
const {
instance
} = createLog();

const originalState = instance.state;

// when
instance.handleResize(null, { y: 0 });

// then
expect(instance.state).to.eql(originalState);
});

});


});


Expand Down
20 changes: 17 additions & 3 deletions client/src/app/primitives/TabLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import React, { Component } from 'react';

import classNames from 'classnames';

import {
debounce
} from 'min-dash';

import css from './Tabbed.less';

import {
Expand All @@ -26,8 +30,12 @@ const TABS_OPTS = {


export default class TabLinks extends Component {
constructor() {
super();
constructor(props) {
super(props);

if (process.env.NODE_ENV !== 'test') {
this.updateScroller = debounce(this.updateScroller, 300);
}

this.tabLinksRef = React.createRef();
}
Expand All @@ -50,15 +58,21 @@ export default class TabLinks extends Component {
componentWillUnmount() {
if (this.scroller) {
removeScroller(this.scroller);

this.scroller = null;
}
}

componentDidUpdate() {
updateScroller() {
if (this.scroller) {
this.scroller.update();
}
}

componentDidUpdate() {
this.updateScroller();
}

handleScroll = (node) => {
const {
onSelect,
Expand Down
60 changes: 41 additions & 19 deletions client/src/app/tabs/PropertiesContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import classNames from 'classnames';

import dragger from '../../util/dom/dragger';

import {
throttle
} from 'min-dash';

import css from './PropertiesContainer.less';


Expand All @@ -12,6 +16,8 @@ const DEFAULT_LAYOUT = {
width: 250
};

const RESIZE_THROTTLE = 10;


/**
* A generic container to hold our editors properties panels.
Expand All @@ -20,6 +26,14 @@ const DEFAULT_LAYOUT = {
*/
class PropertiesContainerWrapped extends Component {

constructor(props) {
super(props);

if (process.env.NODE_ENV !== 'test') {
this.handleResize = throttle(this.handleResize, RESIZE_THROTTLE);
}
}

changeLayout = (newLayout) => {

const {
Expand Down Expand Up @@ -53,28 +67,34 @@ class PropertiesContainerWrapped extends Component {
});
}

/**
* Returns dragger with cached properties panel width.
*/
handleResize = (originalWidth) => {
handleResizeStart = event => {
const onDragStart = dragger(this.handleResize);

this.originalWidth = this.currentWidth;

onDragStart(event);
}

return dragger((event, delta) => {
const {
x
} = delta;
handleResize = (_, delta) => {
const {
x
} = delta;

const newWidth = originalWidth - x;
if (x === 0) {
return;
}

const open = newWidth > 25;
const newWidth = this.originalWidth - x;

const width = (open ? newWidth : DEFAULT_LAYOUT.width);
const open = newWidth > 25;

this.changeLayout({
propertiesPanel: {
open,
width
}
});
const width = (open ? newWidth : DEFAULT_LAYOUT.width);

this.changeLayout({
propertiesPanel: {
open,
width
}
});
}

Expand All @@ -96,6 +116,8 @@ class PropertiesContainerWrapped extends Component {
width
};

this.currentWidth = width;

return (
<div
className={ classNames(
Expand All @@ -110,15 +132,15 @@ class PropertiesContainerWrapped extends Component {
className="toggle"
onClick={ this.handleToggle }
draggable
onDragStart={ this.handleResize(width) }
onDragStart={ this.handleResizeStart }
>Properties Panel</div>
}
{
(open) &&
<div
className="resize-handle"
draggable
onDragStart={ this.handleResize(width) }
onDragStart={ this.handleResizeStart }
></div>
}
<div className="properties-container" ref={ forwardedRef }></div>
Expand Down
Loading