Skip to content

Commit

Permalink
Addressed @foot's comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
fbarl committed Apr 27, 2017
1 parent cdb7a61 commit e77f396
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 37 deletions.
25 changes: 23 additions & 2 deletions client/app/scripts/components/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import debug from 'debug';
import React from 'react';
import { connect } from 'react-redux';
import { debounce } from 'lodash';

import Logo from './logo';
import Footer from './footer';
Expand All @@ -23,7 +24,8 @@ import {
setGraphView,
setTableView,
setResourceView,
shutdown
shutdown,
setViewportDimensions,
} from '../actions/app-actions';
import Details from './details';
import Nodes from './nodes';
Expand All @@ -39,6 +41,7 @@ import {
isTableViewModeSelector,
isGraphViewModeSelector,
} from '../selectors/topology';
import { VIEWPORT_RESIZE_DEBOUNCE_INTERVAL } from '../constants/timer';
import {
BACKSPACE_KEY_CODE,
ESC_KEY_CODE,
Expand All @@ -51,11 +54,17 @@ class App extends React.Component {
constructor(props, context) {
super(props, context);

this.setViewportDimensions = this.setViewportDimensions.bind(this);
this.handleResize = debounce(this.setViewportDimensions, VIEWPORT_RESIZE_DEBOUNCE_INTERVAL);

this.saveAppRef = this.saveAppRef.bind(this);
this.onKeyPress = this.onKeyPress.bind(this);
this.onKeyUp = this.onKeyUp.bind(this);
}

componentDidMount() {
this.setViewportDimensions();
window.addEventListener('resize', this.handleResize);
window.addEventListener('keypress', this.onKeyPress);
window.addEventListener('keyup', this.onKeyUp);

Expand All @@ -69,6 +78,7 @@ class App extends React.Component {
}

componentWillUnmount() {
window.addEventListener('resize', this.handleResize);
window.removeEventListener('keypress', this.onKeyPress);
window.removeEventListener('keyup', this.onKeyUp);
this.props.dispatch(shutdown());
Expand Down Expand Up @@ -141,13 +151,24 @@ class App extends React.Component {
});
}

setViewportDimensions() {
if (this.appRef) {
const { width, height } = this.appRef.getBoundingClientRect();
this.props.dispatch(setViewportDimensions(width, height));
}
}

saveAppRef(ref) {
this.appRef = ref;
}

render() {
const { isTableViewMode, isGraphViewMode, isResourceViewMode, showingDetails, showingHelp,
showingNetworkSelector, showingTroubleshootingMenu } = this.props;
const isIframe = window !== window.top;

return (
<div className="scope-app">
<div className="scope-app" ref={this.saveAppRef}>
{showingDebugToolbar() && <DebugToolbar />}

{showingHelp && <HelpPanel />}
Expand Down
35 changes: 1 addition & 34 deletions client/app/scripts/components/nodes.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { connect } from 'react-redux';
import { debounce } from 'lodash';

import NodesChart from '../charts/nodes-chart';
import NodesGrid from '../charts/nodes-grid';
Expand All @@ -9,15 +8,12 @@ import NodesError from '../charts/nodes-error';
import DelayedShow from '../utils/delayed-show';
import { Loading, getNodeType } from './loading';
import { isTopologyEmpty } from '../utils/topology-utils';
import { setViewportDimensions } from '../actions/app-actions';
import {
isGraphViewModeSelector,
isTableViewModeSelector,
isResourceViewModeSelector,
} from '../selectors/topology';

import { VIEWPORT_RESIZE_DEBOUNCE_INTERVAL } from '../constants/timer';


const EmptyTopologyError = show => (
<NodesError faIconClass="fa-circle-thin" hidden={!show}>
Expand All @@ -34,22 +30,6 @@ const EmptyTopologyError = show => (
);

class Nodes extends React.Component {
constructor(props, context) {
super(props, context);

this.setDimensions = this.setDimensions.bind(this);
this.handleResize = debounce(this.setDimensions, VIEWPORT_RESIZE_DEBOUNCE_INTERVAL);
}

componentDidMount() {
this.setDimensions();
window.addEventListener('resize', this.handleResize);
}

componentWillUnmount() {
window.removeEventListener('resize', this.handleResize);
}

render() {
const { topologyEmpty, topologiesLoaded, nodesLoaded, topologies, currentTopology,
isGraphViewMode, isTableViewMode, isResourceViewMode } = this.props;
Expand All @@ -71,18 +51,6 @@ class Nodes extends React.Component {
</div>
);
}

setDimensions() {
// Use the `scope-app` div to determine the viewport rectangle, because `window` gives
// wrong values for scope container inside Weave Cloud (on dev & prod), because of the
// top navigation toolbar that is counted in, even though it's not part of Scope.
const viewport = document.getElementsByClassName('scope-app')[0].getBoundingClientRect();
// Not sure why we need to subtract `left` and `top`, but that gives us correct values.
this.props.setViewportDimensions(
viewport.width - viewport.left,
viewport.height - viewport.top
);
}
}


Expand All @@ -101,6 +69,5 @@ function mapStateToProps(state) {


export default connect(
mapStateToProps,
{ setViewportDimensions }
mapStateToProps
)(Nodes);
2 changes: 1 addition & 1 deletion client/app/styles/_base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
color: $text-color;
font-family: $base-font;
font-size: 13px;
height: 100%;
height: auto;
left: 0;
line-height: 150%;
margin: 0;
Expand Down

0 comments on commit e77f396

Please sign in to comment.