import React from 'react'; import { connect } from 'react-redux'; import { Map as makeMap } from 'immutable'; import { clickCloseDetails, clickShowTopologyForNode } from '../actions/app-actions'; import { brightenColor, getNeutralColor, getNodeColorDark } from '../utils/color-utils'; import { resetDocumentTitle, setDocumentTitle } from '../utils/title-utils'; import MatchedText from './matched-text'; import NodeDetailsControls from './node-details/node-details-controls'; import NodeDetailsHealth from './node-details/node-details-health'; import NodeDetailsInfo from './node-details/node-details-info'; import NodeDetailsLabels from './node-details/node-details-labels'; import NodeDetailsRelatives from './node-details/node-details-relatives'; import NodeDetailsTable from './node-details/node-details-table'; import Warning from './warning'; function getTruncationText(count) { return 'This section was too long to be handled efficiently and has been truncated' + ` (${count} extra entries not included). We are working to remove this limitation.`; } export class NodeDetails extends React.Component { constructor(props, context) { super(props, context); this.handleClickClose = this.handleClickClose.bind(this); this.handleShowTopologyForNode = this.handleShowTopologyForNode.bind(this); } handleClickClose(ev) { ev.preventDefault(); this.props.clickCloseDetails(this.props.nodeId); } handleShowTopologyForNode(ev) { ev.preventDefault(); this.props.clickShowTopologyForNode(this.props.topologyId, this.props.nodeId); } componentDidMount() { this.updateTitle(); } componentWillUnmount() { resetDocumentTitle(); } renderTools() { const showSwitchTopology = this.props.nodeId !== this.props.selectedNodeId; const topologyTitle = `View ${this.props.label} in ${this.props.topologyId}`; return (
{showSwitchTopology && Show in {this.props.topologyId.replace(/-/g, ' ')} }
); } renderLoading() { const node = this.props.nodes.get(this.props.nodeId); const label = node ? node.get('label') : this.props.label; const nodeColor = (node ? getNodeColorDark(node.get('rank'), label, node.get('pseudo')) : getNeutralColor()); const tools = this.renderTools(); const styles = { header: { backgroundColor: nodeColor } }; return (
{tools}

{label}

Loading...
); } renderNotAvailable() { const tools = this.renderTools(); return (
{tools}

{this.props.label}

n/a

{this.props.label} is not visible to Scope when it is not communicating. Details will become available here when it communicates again.

); } render() { if (this.props.notFound) { return this.renderNotAvailable(); } if (this.props.details) { return this.renderDetails(); } return this.renderLoading(); } renderDetails() { const { details, nodeControlStatus, nodeMatches = makeMap() } = this.props; const showControls = details.controls && details.controls.length > 0; const nodeColor = getNodeColorDark(details.rank, details.label, details.pseudo); const {error, pending} = nodeControlStatus ? nodeControlStatus.toJS() : {}; const tools = this.renderTools(); const styles = { controls: { backgroundColor: brightenColor(nodeColor) }, header: { backgroundColor: nodeColor } }; return (
{tools}

{details.parents && }
{showControls &&
}
{details.metrics &&
Status
} {details.metadata &&
Info
} {details.connections && details.connections.map(connections =>
)} {details.children && details.children.map(children =>
)} {details.tables && details.tables.length > 0 && details.tables.map(table => { if (table.rows.length > 0) { return (
{table.label} {table.truncationCount > 0 && }
); } return null; })}
); } componentDidUpdate() { this.updateTitle(); } updateTitle() { setDocumentTitle(this.props.details && this.props.details.label); } } function mapStateToProps(state, ownProps) { const currentTopologyId = state.get('currentTopologyId'); return { nodeMatches: state.getIn(['searchNodeMatches', currentTopologyId, ownProps.id]), nodes: state.get('nodes'), selectedNodeId: state.get('selectedNodeId'), }; } export default connect( mapStateToProps, { clickCloseDetails, clickShowTopologyForNode } )(NodeDetails);