Skip to content

Commit

Permalink
fix(tab): improve log and properties panel resize performance
Browse files Browse the repository at this point in the history
Closes #1081
  • Loading branch information
barmac committed Jan 9, 2019
1 parent 2c416a5 commit d74bebc
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 41 deletions.
56 changes: 34 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,8 @@ export default class Log extends Component {
this.state = {};

this.panelRef = React.createRef();

this.handleResize = throttle(this.handleResize, RESIZE_THROTTLE);
}

toggleLog = () => {
Expand Down Expand Up @@ -62,35 +70,37 @@ 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);
}

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

const height = (newExpanded ? newHeight : DEFAULT_HEIGHT);
const newHeight = this.originalHeight - y;

const {
expanded,
onToggle
} = this.props;
const newExpanded = newHeight > 25;

this.setState({
height
});
const height = (newExpanded ? newHeight : DEFAULT_HEIGHT);

if (expanded !== newExpanded) {
onToggle(newExpanded);
}
const {
expanded,
onToggle
} = this.props;

this.setState({
height
});

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

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

const logHeight = height || DEFAULT_HEIGHT;

this.currentHeight = logHeight;

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

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

Expand Down
58 changes: 39 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,12 @@ const DEFAULT_LAYOUT = {
*/
class PropertiesContainerWrapped extends Component {

constructor(props) {
super(props);

this.handleResize = throttle(this.handleResize, RESIZE_THROTTLE);
}

changeLayout = (newLayout) => {

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

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

return dragger((event, delta) => {
const {
x
} = delta;
this.originalWidth = this.currentWidth;

const newWidth = originalWidth - x;
onDragStart(event);
}

const open = newWidth > 25;
handleResize = (_, delta) => {
const {
x
} = delta;

const width = (open ? newWidth : DEFAULT_LAYOUT.width);
if (x === 0) {
return;
}

this.changeLayout({
propertiesPanel: {
open,
width
}
});
const newWidth = this.originalWidth - x;

const open = newWidth > 25;

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

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

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

this.currentWidth = width;

return (
<div
className={ classNames(
Expand All @@ -110,15 +130,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

0 comments on commit d74bebc

Please sign in to comment.