Files
weave-scope/client/app/scripts/components/topologies.js
Filip Barl 69fd397217 Initial version of the resource view (#2296)
* Added resource view selector button

* Showing resource boxes in the resource view

* Crude CPU resource view prototype

* Improved the viewMode state logic

* Extracted zooming into a separate wrapper component

* Split the layout selectors between graph-view and resource-view

* Proper zooming logic for the resource view

* Moved all node networks utils to selectors

* Improved the zoom caching logic

* Further refactoring of selectors

* Added sticky labels to the resource boxes

* Added panning translation limits in the resource view

* Renamed GridModeSelector -> ViewModeSelector

* Polished the topology resource view selection logic

* Search bar hidden in the resource view

* Added per-layer topology names to the resource view

* Made metric selectors work for the resource view

* Adjusted the viewport selectors

* Renamed viewport selector to canvas (+ maximal zoom fix)

* Showing more useful metric info in the resource box labels

* Fetching only necessary nodes for the resource view

* Refactored the resource view layer component

* Addressed first batch UI comments (from the Scope meeting)

* Switch to deep zooming transform in the resource view to avoid SVG precision errors

* Renamed and moved resource view components

* Polished all the resource view components

* Changing the available metrics selection

* Improved and polished the state transition logic for the resource view

* Separated zoom limits from the zoom active state

* Renaming and bunch of comments

* Addressed all the UI comments (@davkal + @fons)

* Made graph view selectors independent from resource view selectors
2017-03-24 14:51:53 +01:00

105 lines
3.4 KiB
JavaScript

import React from 'react';
import { connect } from 'react-redux';
import classnames from 'classnames';
import { searchMatchCountByTopologySelector } from '../selectors/search';
import { isResourceViewModeSelector } from '../selectors/topology';
import { clickTopology } from '../actions/app-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 {
constructor(props, context) {
super(props, context);
this.onTopologyClick = this.onTopologyClick.bind(this);
}
onTopologyClick(ev) {
ev.preventDefault();
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', {
// Don't show matches in the resource view as searching is not supported there yet.
'topologies-sub-item-matched': !this.props.isResourceViewMode && searchMatchCount,
'topologies-sub-item-active': isActive,
});
return (
<div
className={className} title={title} key={topologyId} rel={topologyId}
onClick={this.onTopologyClick}>
<div className="topologies-sub-item-label">
{subTopology.get('name')}
</div>
</div>
);
}
renderTopology(topology) {
const isActive = topology === this.props.currentTopology;
const searchMatchCount = this.props.searchMatchCountByTopology.get(topology.get('id')) || 0;
const className = classnames('topologies-item-main', {
// Don't show matches in the resource view as searching is not supported there yet.
'topologies-item-main-matched': !this.props.isResourceViewMode && searchMatchCount,
'topologies-item-main-active': isActive,
});
const topologyId = topology.get('id');
const title = basicTopologyInfo(topology, searchMatchCount);
return (
<div className="topologies-item" key={topologyId}>
<div className={className} title={title} rel={topologyId} onClick={this.onTopologyClick}>
<div className="topologies-item-label">
{topology.get('name')}
</div>
</div>
<div className="topologies-sub">
{topology.has('sub_topologies')
&& topology.get('sub_topologies').map(subTop => this.renderSubTopology(subTop))}
</div>
</div>
);
}
render() {
return (
<div className="topologies">
{this.props.currentTopology && this.props.topologies.map(
topology => this.renderTopology(topology)
)}
</div>
);
}
}
function mapStateToProps(state) {
return {
topologies: state.get('topologies'),
currentTopology: state.get('currentTopology'),
searchMatchCountByTopology: searchMatchCountByTopologySelector(state),
isResourceViewMode: isResourceViewModeSelector(state),
};
}
export default connect(
mapStateToProps,
{ clickTopology }
)(Topologies);