import React from 'react'; import { connect } from 'react-redux'; import classnames from 'classnames'; import { trackAnalyticsEvent } from '../utils/tracking-utils'; import { searchMatchCountByTopologySelector } from '../selectors/search'; import { isResourceViewModeSelector } from '../selectors/topology'; import { clickTopology } from '../actions/request-actions'; function basicTopologyInfo(topology, searchMatchCount) { const info = [ `Nodes: ${topology.getIn(['stats', 'node_count'])}`, `Connections: ${topology.getIn(['stats', 'edge_count'])}` ]; if (searchMatchCount) { info.push(`Search Matches: ${searchMatchCount}`); } return info.join('\n'); } class Topologies extends React.Component { onTopologyClick = (ev, topology) => { ev.preventDefault(); trackAnalyticsEvent('scope.topology.selector.click', { parentTopologyId: topology.get('parentId'), topologyId: topology.get('id'), }); this.props.clickTopology(ev.currentTarget.getAttribute('rel')); } renderSubTopology(subTopology) { const topologyId = subTopology.get('id'); const isActive = subTopology === this.props.currentTopology; const searchMatchCount = this.props.searchMatchCountByTopology.get(topologyId) || 0; const title = basicTopologyInfo(subTopology, searchMatchCount); const className = classnames(`topologies-sub-item topologies-item-${topologyId}`, { 'topologies-sub-item-active': isActive, // Don't show matches in the resource view as searching is not supported there yet. 'topologies-sub-item-matched': !this.props.isResourceViewMode && searchMatchCount, }); return (