import React from 'react'; import { connect } from 'react-redux'; import moment from 'moment'; import Plugins from './plugins.js'; import { getUpdateBufferSize } from '../utils/update-buffer-utils'; import { contrastModeUrl, isContrastMode } from '../utils/contrast-utils'; import { clickDownloadGraph, clickForceRelayout, clickPauseUpdate, clickResumeUpdate, toggleHelp } from '../actions/app-actions'; import { basePathSlash } from '../utils/web-api-utils'; class Footer extends React.Component { render() { const { hostname, updatePausedAt, version, versionUpdate } = this.props; const contrastMode = isContrastMode(); // link url to switch contrast with current UI state const otherContrastModeUrl = contrastMode ? basePathSlash(window.location.pathname) : contrastModeUrl; const otherContrastModeTitle = contrastMode ? 'Switch to normal contrast' : 'Switch to high contrast'; const forceRelayoutTitle = 'Force re-layout (might reduce edge crossings, ' + 'but may shift nodes around)'; // pause button const isPaused = updatePausedAt !== null; const updateCount = getUpdateBufferSize(); const hasUpdates = updateCount > 0; const pausedAgo = moment(updatePausedAt).fromNow(); const pauseTitle = isPaused ? `Paused ${pausedAgo}` : 'Pause updates (freezes the nodes in their current layout)'; const pauseAction = isPaused ? this.props.clickResumeUpdate : this.props.clickPauseUpdate; const pauseClassName = isPaused ? 'footer-icon footer-icon-active' : 'footer-icon'; let pauseLabel = ''; if (hasUpdates && isPaused) { pauseLabel = `Paused +${updateCount}`; } else if (hasUpdates && !isPaused) { pauseLabel = `Resuming +${updateCount}`; } else if (!hasUpdates && isPaused) { pauseLabel = 'Paused'; } const versionUpdateTitle = versionUpdate ? `New version available: ${versionUpdate.version}. Click to download` : ''; return (
{versionUpdate && Update available: {versionUpdate.version} } Version {version} on {hostname}
{pauseLabel !== '' && {pauseLabel}}
); } } function mapStateToProps(state) { return { hostname: state.get('hostname'), updatePausedAt: state.get('updatePausedAt'), version: state.get('version'), versionUpdate: state.get('versionUpdate') }; } export default connect( mapStateToProps, { clickDownloadGraph, clickForceRelayout, clickPauseUpdate, clickResumeUpdate, toggleHelp } )(Footer);