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

Calculate viewport dimensions from the scope-app div #2473

Merged
merged 2 commits into from
Apr 27, 2017
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
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
27 changes: 1 addition & 26 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);
this.setDimensions();
}

componentDidMount() {
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,10 +51,6 @@ class Nodes extends React.Component {
</div>
);
}

setDimensions() {
this.props.setViewportDimensions(window.innerWidth, window.innerHeight);
}
}


Expand All @@ -93,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