1
0
mirror of https://github.com/alice-lg/alice-lg.git synced 2024-05-11 05:55:03 +00:00

144 lines
3.6 KiB
React
Raw Normal View History

2017-05-16 13:34:00 +02:00
2017-06-26 15:35:54 +02:00
import _ from 'underscore'
2017-05-16 13:34:00 +02:00
import React from 'react'
2017-06-26 15:35:54 +02:00
import {connect} from 'react-redux'
import {Link} from 'react-router'
2017-05-16 13:34:00 +02:00
2017-06-26 15:35:54 +02:00
import FilterReason
from 'components/routeservers/large-communities/filter-reason'
2017-05-16 13:34:00 +02:00
2017-06-26 15:35:54 +02:00
import NoexportReason
from 'components/routeservers/large-communities/noexport-reason'
2017-05-16 13:34:00 +02:00
import {showBgpAttributes}
from 'components/routeservers/routes/bgp-attributes-modal-actions'
2017-05-16 13:34:00 +02:00
import BgpAttributesModal
from 'components/routeservers/routes/bgp-attributes-modal'
import LoadingIndicator
from 'components/loading-indicator/small'
class ResultsTableView extends React.Component {
showAttributesModal(route) {
this.props.dispatch(
showBgpAttributes(route)
);
}
2017-06-26 15:35:54 +02:00
render() {
if (this.props.routes.length == 0) {
return null;
2017-05-16 13:34:00 +02:00
}
2017-06-26 15:35:54 +02:00
const routes = this.props.routes.map((route) => (
2017-06-26 16:06:05 +02:00
<tr key={route.id + '_' + route.neighbour.id + '_' + route.routeserver.id}>
<td onClick={() => this.showAttributesModal(route)}>{route.network}
2017-06-26 16:15:10 +02:00
{this.props.display_reasons == "filtered" && <FilterReason route={route} />}
</td>
<td onClick={() => this.showAttributesModal(route)}>{route.bgp.as_path.join(" ")}</td>
<td onClick={() => this.showAttributesModal(route)}>
{route.gateway}
</td>
<td>
<Link to={`/routeservers/${route.routeserver.id}/protocols/${route.neighbour.id}/routes`}>
{route.neighbour.description}
</Link>
</td>
<td>
<Link to={`/routeservers/${route.routeserver.id}/protocols/${route.neighbour.id}/routes`}>
{route.neighbour.asn}
</Link>
</td>
<td>
<Link to={`/routeservers/${route.routeserver.id}`}>
{route.routeserver.name}
</Link>
</td>
2017-06-26 15:35:54 +02:00
</tr>
));
2017-05-16 13:34:00 +02:00
2017-06-26 15:35:54 +02:00
return (
<div className="card">
{this.props.header}
<table className="table table-striped table-routes">
<thead>
<tr>
<th>Network</th>
<th>AS Path</th>
<th>Gateway</th>
<th>Neighbour</th>
<th>ASN</th>
<th>RS</th>
</tr>
</thead>
<tbody>
{routes}
</tbody>
</table>
</div>
);
}
}
2017-05-16 13:34:00 +02:00
const ResultsTable = connect()(ResultsTableView);
2017-05-16 13:34:00 +02:00
2017-06-26 15:35:54 +02:00
class LookupResults extends React.Component {
render() {
if(this.props.isLoading) {
return (
<LoadingIndicator />
);
}
2017-06-26 15:35:54 +02:00
const mkHeader = (color, action) => (
<p style={{"color": color, "textTransform": "uppercase"}}>
Routes {action}
</p>
);
const filtdHeader = mkHeader("orange", "filtered");
const recvdHeader = mkHeader("green", "accepted");
const noexHeader = mkHeader("red", "not exported");
let filteredRoutes = this.props.routes.filtered;
let importedRoutes = this.props.routes.imported;
return (
<div className="lookup-results">
<BgpAttributesModal />
2017-06-26 16:15:10 +02:00
<ResultsTable header={filtdHeader}
routes={filteredRoutes}
display_reasons="filtered" />
<ResultsTable header={recvdHeader}
routes={importedRoutes} />
2017-06-26 15:35:54 +02:00
</div>
)
}
}
function selectRoutes(routes, state) {
return _.where(routes, {state: state});
2017-05-16 13:34:00 +02:00
}
2017-06-26 15:35:54 +02:00
export default connect(
(state) => {
let routes = state.lookup.results;
let filteredRoutes = selectRoutes(routes, 'filtered');
let importedRoutes = selectRoutes(routes, 'imported');
return {
routes: {
filtered: filteredRoutes,
imported: importedRoutes
}
}
}
)(LookupResults);
2017-05-16 13:34:00 +02:00