From 0c89171efd1a87bf799671d135ff2d543bcc8668 Mon Sep 17 00:00:00 2001 From: Filip Barl Date: Wed, 11 Oct 2017 22:48:20 +0200 Subject: [PATCH] Made two time travel component parts independent of global state. --- .../components/time-travel-component.js | 66 +++---------------- .../components/time-travel-timeline.js | 18 +---- client/app/scripts/components/time-travel.js | 62 +++++++++++++++-- 3 files changed, 68 insertions(+), 78 deletions(-) diff --git a/client/app/scripts/components/time-travel-component.js b/client/app/scripts/components/time-travel-component.js index a962eb7b0e..3281ece00a 100644 --- a/client/app/scripts/components/time-travel-component.js +++ b/client/app/scripts/components/time-travel-component.js @@ -1,17 +1,10 @@ import React from 'react'; import moment from 'moment'; import classNames from 'classnames'; -import { connect } from 'react-redux'; import { debounce } from 'lodash'; import TimeTravelTimeline from './time-travel-timeline'; -import { trackAnalyticsEvent } from '../utils/tracking-utils'; import { clampToNowInSecondsPrecision } from '../utils/time-utils'; -import { - jumpToTime, - resumeTime, - timeTravelStartTransition, -} from '../actions/app-actions'; import { TIMELINE_DEBOUNCE_INTERVAL } from '../constants/timer'; @@ -23,7 +16,7 @@ const getTimestampStates = (timestamp) => { }; }; -class TimeTravelComponent extends React.Component { +export default class TimeTravelComponent extends React.Component { constructor(props, context) { super(props, context); @@ -34,10 +27,6 @@ class TimeTravelComponent extends React.Component { this.handleTimelinePanEnd = this.handleTimelinePanEnd.bind(this); this.handleInstantJump = this.handleInstantJump.bind(this); - this.trackTimestampEdit = this.trackTimestampEdit.bind(this); - this.trackTimelineClick = this.trackTimelineClick.bind(this); - this.trackTimelinePan = this.trackTimelinePan.bind(this); - this.instantUpdateTimestamp = this.instantUpdateTimestamp.bind(this); this.debouncedUpdateTimestamp = debounce( this.instantUpdateTimestamp.bind(this), TIMELINE_DEBOUNCE_INTERVAL); @@ -53,7 +42,7 @@ class TimeTravelComponent extends React.Component { if (timestamp.isValid()) { const clampedTimestamp = clampToNowInSecondsPrecision(timestamp); - this.instantUpdateTimestamp(clampedTimestamp, this.trackTimestampEdit); + this.instantUpdateTimestamp(clampedTimestamp, this.props.trackTimestampEdit); } } @@ -63,55 +52,32 @@ class TimeTravelComponent extends React.Component { } handleTimelinePanEnd(timestamp) { - this.instantUpdateTimestamp(timestamp, this.trackTimelinePan); + this.instantUpdateTimestamp(timestamp, this.props.trackTimelinePan); } handleInstantJump(timestamp) { - this.instantUpdateTimestamp(timestamp, this.trackTimelineClick); + this.instantUpdateTimestamp(timestamp, this.props.trackTimelineClick); } instantUpdateTimestamp(timestamp, callback) { if (!timestamp.isSame(this.props.timestamp)) { this.debouncedUpdateTimestamp.cancel(); this.setState(getTimestampStates(timestamp)); - this.props.timeTravelStartTransition(); - this.props.jumpToTime(moment(timestamp)); + this.props.changeTimestamp(moment(timestamp)); // Used for tracking. if (callback) callback(); } } - trackTimestampEdit() { - trackAnalyticsEvent('scope.time.timestamp.edit', { - layout: this.props.topologyViewMode, - topologyId: this.props.currentTopology.get('id'), - parentTopologyId: this.props.currentTopology.get('parentId'), - }); - } - - trackTimelineClick() { - trackAnalyticsEvent('scope.time.timeline.click', { - layout: this.props.topologyViewMode, - topologyId: this.props.currentTopology.get('id'), - parentTopologyId: this.props.currentTopology.get('parentId'), - }); - } - - trackTimelinePan() { - trackAnalyticsEvent('scope.time.timeline.pan', { - layout: this.props.topologyViewMode, - topologyId: this.props.currentTopology.get('id'), - parentTopologyId: this.props.currentTopology.get('parentId'), - }); - } - render() { - const { visible } = this.props; + const { visible, timestamp, viewportWidth } = this.props; return (
); } @@ -20,10 +67,15 @@ class TimeTravel extends React.Component { function mapStateToProps(state) { return { visible: state.get('showingTimeTravel'), - // topologyViewMode: state.get('topologyViewMode'), - // currentTopology: state.get('currentTopology'), + topologyViewMode: state.get('topologyViewMode'), + currentTopology: state.get('currentTopology'), timestamp: state.get('pausedAt'), + // Used only to trigger recalculations on window resize. + viewportWidth: state.getIn(['viewport', 'width']), }; } -export default connect(mapStateToProps)(TimeTravel); +export default connect( + mapStateToProps, + { jumpToTime, timeTravelStartTransition }, +)(TimeTravel);