Skip to content

Commit

Permalink
Merge pull request #3349 from weaveworks/3348-on-route-change-hook
Browse files Browse the repository at this point in the history
Add onRouteChange hook to Scope app
  • Loading branch information
fbarl authored Sep 17, 2018
2 parents 69d1c6e + eb767ed commit 39530aa
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions client/app/scripts/components/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { connect } from 'react-redux';
import { debounce } from 'lodash';
import { debounce, isEqual } from 'lodash';

import { ThemeProvider } from 'styled-components';
import theme from 'weaveworks-ui-components/lib/theme';
Expand Down Expand Up @@ -67,6 +67,7 @@ class App extends React.Component {

this.setViewportDimensions = this.setViewportDimensions.bind(this);
this.handleResize = debounce(this.setViewportDimensions, VIEWPORT_RESIZE_DEBOUNCE_INTERVAL);
this.handleRouteChange = debounce(props.onRouteChange, 50);

this.saveAppRef = this.saveAppRef.bind(this);
this.onKeyPress = this.onKeyPress.bind(this);
Expand Down Expand Up @@ -105,6 +106,10 @@ class App extends React.Component {
if (nextProps.disableStoreViewState !== this.props.disableStoreViewState) {
this.props.dispatch(setStoreViewState(!nextProps.disableStoreViewState));
}
// Debounce-notify about the route change if the URL state changes its content.
if (!isEqual(nextProps.urlState, this.props.urlState)) {
this.handleRouteChange(nextProps.urlState);
}
}

onKeyUp(ev) {
Expand Down Expand Up @@ -241,7 +246,6 @@ class App extends React.Component {
}
}


function mapStateToProps(state) {
return {
currentTopology: state.get('currentTopology'),
Expand All @@ -267,13 +271,15 @@ function mapStateToProps(state) {
App.propTypes = {
renderTimeTravel: PropTypes.func,
renderNodeDetailsExtras: PropTypes.func,
onRouteChange: PropTypes.func,
monitor: PropTypes.bool,
disableStoreViewState: PropTypes.bool,
};

App.defaultProps = {
renderTimeTravel: () => <TimeTravelWrapper />,
renderNodeDetailsExtras: () => null,
onRouteChange: () => null,
monitor: false,
disableStoreViewState: false,
};
Expand Down

0 comments on commit 39530aa

Please sign in to comment.