Files
weave-scope/client/app/scripts/components/status.js
Simon Howe 7d14a787be Adds a loading indicator for the initial node-load
- Sometimes can take a second to get the initial nodes
- Not doing the transition between topos atm as its a bit distracting
  popping up and down.
2016-07-28 16:28:12 +02:00

56 lines
1.7 KiB
JavaScript

import React from 'react';
import { connect } from 'react-redux';
class Status extends React.Component {
render() {
const {errorUrl, topologiesLoaded, filteredNodeCount, topology, websocketClosed} = this.props;
let title = '';
let text = 'Trying to reconnect...';
let showWarningIcon = false;
let classNames = 'status sidebar-item';
if (errorUrl) {
title = `Cannot reach Scope. Make sure the following URL is reachable: ${errorUrl}`;
classNames += ' status-loading';
showWarningIcon = true;
} else if (!topologiesLoaded) {
text = 'Connecting to Scope...';
classNames += ' status-loading';
showWarningIcon = true;
} else if (websocketClosed) {
classNames += ' status-loading';
showWarningIcon = true;
} else if (topology) {
const stats = topology.get('stats');
text = `${stats.get('node_count') - filteredNodeCount} nodes`;
if (stats.get('filtered_nodes')) {
text = `${text} (${stats.get('filtered_nodes') + filteredNodeCount} filtered)`;
}
classNames += ' status-stats';
showWarningIcon = false;
}
return (
<div className={classNames}>
{showWarningIcon && <span className="status-icon fa fa-exclamation-circle" />}
<span className="status-label" title={title}>{text}</span>
</div>
);
}
}
function mapStateToProps(state) {
return {
errorUrl: state.get('errorUrl'),
filteredNodeCount: state.get('nodes').filter(node => node.get('filtered')).size,
topologiesLoaded: state.get('topologiesLoaded'),
topology: state.get('currentTopology'),
websocketClosed: state.get('websocketClosed')
};
}
export default connect(
mapStateToProps
)(Status);