Merge pull request #246 from weaveworks/cleanup-unused

Removed unused grouping and explorer code
This commit is contained in:
David
2015-06-23 17:45:06 +02:00
7 changed files with 4 additions and 183 deletions

View File

@@ -12,15 +12,6 @@ module.exports = {
RouterUtils.updateRoute();
},
clickGrouping: function(grouping) {
AppDispatcher.dispatch({
type: ActionTypes.CLICK_GROUPING,
grouping: grouping
});
RouterUtils.updateRoute();
WebapiUtils.getNodesDelta(AppStore.getCurrentTopologyUrl());
},
clickNode: function(nodeId) {
AppDispatcher.dispatch({
type: ActionTypes.CLICK_NODE,

View File

@@ -16,7 +16,6 @@ function getStateFromStores() {
return {
currentTopology: AppStore.getCurrentTopology(),
errorUrl: AppStore.getErrorUrl(),
currentGrouping: AppStore.getCurrentGrouping(),
highlightedEdgeIds: AppStore.getHighlightedEdgeIds(),
highlightedNodeIds: AppStore.getHighlightedNodeIds(),
selectedNodeId: AppStore.getSelectedNodeId(),

View File

@@ -1,87 +0,0 @@
const React = require('react');
const _ = require('lodash');
const NodesChart = require('../charts/nodes-chart');
const NodeDetails = require('./node-details');
const marginBottom = 64;
const marginTop = 64;
const marginLeft = 36;
const marginRight = 36;
const Explorer = React.createClass({
getInitialState: function() {
return {
layout: 'solar',
width: window.innerWidth - marginLeft - marginRight,
height: window.innerHeight - marginBottom - marginTop
};
},
componentDidMount: function() {
window.addEventListener('resize', this.handleResize);
},
componentWillUnmount: function() {
window.removeEventListener('resize', this.handleResize);
},
getSubTopology: function(topology) {
const subTopology = {};
const nodeSet = [];
_.each(this.props.expandedNodes, function(nodeId) {
if (topology[nodeId]) {
subTopology[nodeId] = topology[nodeId];
nodeSet = _.union(subTopology[nodeId].adjacency, nodeSet);
_.each(subTopology[nodeId].adjacency, function(adjacentId) {
const node = _.assign({}, topology[adjacentId]);
subTopology[adjacentId] = node;
});
}
});
// weed out edges
_.each(subTopology, function(node) {
node.adjacency = _.intersection(node.adjacency, nodeSet);
});
return subTopology;
},
render: function() {
const subTopology = this.getSubTopology(this.props.nodes);
return (
<div id="explorer">
<NodeDetails details={this.props.details} />
<div className="graph">
<NodesChart
layout={this.state.layout}
nodes={subTopology}
highlightedNodes={this.props.expandedNodes}
width={this.state.width}
height={this.state.height}
context="explorer"
/>
</div>
</div>
);
},
setDimensions: function() {
this.setState({
height: window.innerHeight - marginBottom - marginTop,
width: window.innerWidth - marginLeft - marginRight
});
},
handleResize: function() {
this.setDimensions();
}
});
module.exports = Explorer;

View File

@@ -1,65 +0,0 @@
const React = require('react');
const _ = require('lodash');
const AppActions = require('../actions/app-actions');
const GROUPINGS = [{
id: 'none',
iconClass: 'fa fa-th',
needsTopology: false
}, {
id: 'grouped',
iconClass: 'fa fa-th-large',
needsTopology: 'grouped_url'
}];
const Groupings = React.createClass({
onGroupingClick: function(ev) {
ev.preventDefault();
AppActions.clickGrouping(ev.currentTarget.getAttribute('rel'));
},
getGroupingsSupportedByTopology: function(topology) {
return _.filter(GROUPINGS, _.partial(this.isGroupingSupportedByTopology, topology));
},
renderGrouping: function(grouping, activeGroupingId) {
let className = 'groupings-item';
const isSupportedByTopology = this.isGroupingSupportedByTopology(this.props.currentTopology, grouping);
if (grouping.id === activeGroupingId) {
className += ' groupings-item-active';
} else if (!isSupportedByTopology) {
className += ' groupings-item-disabled';
} else {
className += ' groupings-item-default';
}
return (
<div className={className} key={grouping.id} rel={grouping.id} onClick={isSupportedByTopology && this.onGroupingClick}>
<span className={grouping.iconClass} />
</div>
);
},
render: function() {
const activeGrouping = this.props.active;
const isGroupingSupported = _.size(this.getGroupingsSupportedByTopology(this.props.currentTopology)) > 1;
return (
<div className="groupings">
{isGroupingSupported && GROUPINGS.map(function(grouping) {
return this.renderGrouping(grouping, activeGrouping);
}, this)}
</div>
);
},
isGroupingSupportedByTopology: function(topology, grouping) {
return !grouping.needsTopology || topology && topology[grouping.needsTopology];
}
});
module.exports = Groupings;

View File

@@ -2,7 +2,6 @@ const keymirror = require('keymirror');
module.exports = keymirror({
CLICK_CLOSE_DETAILS: null,
CLICK_GROUPING: null,
CLICK_NODE: null,
CLICK_TOPOLOGY: null,
CLOSE_WEBSOCKET: null,

View File

@@ -130,14 +130,14 @@ describe('AppStore', function() {
registeredCallback(ReceiveNodesDeltaAction);
expect(AppStore.getAppState())
.toEqual({"topologyId":"topo1","grouping":"none","selectedNodeId": null});
.toEqual({"topologyId":"topo1","selectedNodeId": null});
registeredCallback(ClickNodeAction);
expect(AppStore.getAppState())
.toEqual({"topologyId":"topo1","grouping":"none","selectedNodeId": 'n1'});
.toEqual({"topologyId":"topo1","selectedNodeId": 'n1'});
// go back in browsing
RouteAction.state = {"topologyId":"topo1","grouping":"none","selectedNodeId": null};
RouteAction.state = {"topologyId":"topo1","selectedNodeId": null};
registeredCallback(RouteAction);
expect(AppStore.getSelectedNodeId()).toBe(null);
expect(AppStore.getNodes()).toEqual(NODE_SET);

View File

@@ -29,7 +29,6 @@ function findCurrentTopology(subTree, topologyId) {
// Initial values
let currentGrouping = 'none';
let currentTopologyId = 'containers';
let errorUrl = null;
let version = '';
@@ -50,7 +49,6 @@ const AppStore = assign({}, EventEmitter.prototype, {
getAppState: function() {
return {
topologyId: currentTopologyId,
grouping: this.getCurrentGrouping(),
selectedNodeId: this.getSelectedNodeId()
};
},
@@ -67,10 +65,6 @@ const AppStore = assign({}, EventEmitter.prototype, {
}
},
getCurrentGrouping: function() {
return currentGrouping;
},
getErrorUrl: function() {
return errorUrl;
},
@@ -145,14 +139,6 @@ AppStore.registeredCallback = function(payload) {
AppStore.emit(AppStore.CHANGE_EVENT);
break;
case ActionTypes.CLICK_GROUPING:
if (payload.grouping !== currentGrouping) {
currentGrouping = payload.grouping;
nodes = {};
AppStore.emit(AppStore.CHANGE_EVENT);
}
break;
case ActionTypes.CLICK_NODE:
selectedNodeId = payload.nodeId;
AppStore.emit(AppStore.CHANGE_EVENT);
@@ -260,12 +246,10 @@ AppStore.registeredCallback = function(payload) {
break;
case ActionTypes.ROUTE_TOPOLOGY:
if (currentTopologyId !== payload.state.topologyId
|| currentGrouping !== payload.state.grouping) {
if (currentTopologyId !== payload.state.topologyId) {
nodes = {};
}
currentTopologyId = payload.state.topologyId;
currentGrouping = payload.state.grouping;
selectedNodeId = payload.state.selectedNodeId;
AppStore.emit(AppStore.CHANGE_EVENT);
break;