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

225 lines
5.5 KiB
React
Raw Normal View History

2017-05-16 13:34:00 +02:00
import _ from 'underscore'
import React from 'react'
import {connect} from 'react-redux'
import {loadRouteserverRoutes, loadRouteserverRoutesFiltered} from '../actions'
import {showBgpAttributes} from './bgp-attributes-modal-actions'
import LoadingIndicator
from 'components/loading-indicator/small'
2017-05-23 16:08:43 +02:00
import FilterReason
from 'components/routeservers/large-communities/filter-reason'
import NoexportReason
from 'components/routeservers/large-communities/noexport-reason'
2017-05-16 13:34:00 +02:00
function _filteredRoutes(routes, filter) {
let filtered = [];
if(filter == "") {
return routes; // nothing to do here
}
filter = filter.toLowerCase();
// Filter protocols
filtered = _.filter(routes, (r) => {
return (r.network.toLowerCase().indexOf(filter) != -1 ||
r.gateway.toLowerCase().indexOf(filter) != -1 ||
r.interface.toLowerCase().indexOf(filter) != -1);
});
return filtered;
}
2018-07-05 16:02:49 +02:00
// Helper: Lookup value in route path
const _lookup = (r, path) => {
const split = path.split(".").reduce((acc, elem) => acc[elem], r);
return split;
}
const ColDefault = function(props) {
return (
2018-07-05 17:03:02 +02:00
<td>
<span onClick={props.onClick}>{_lookup(props.route, props.column)}</span>
</td>
2018-07-05 16:02:49 +02:00
)
}
// Include filter and noexport reason in this column.
const ColNetwork = function(props) {
return (
2018-07-05 17:03:02 +02:00
<td>
<span onClick={props.onClick}>{props.route.network}</span>
2018-07-05 16:02:49 +02:00
{props.displayReasons == "filtered" && <FilterReason route={props.route} />}
{props.displayReasons == "noexport" && <NoexportReason route={props.route} />}
</td>
);
}
// Special AS Path Widget
const ColAsPath = function(props) {
const asns = _lookup(props.route, "bgp.as_path");
const baseUrl = "http://irrexplorer.nlnog.net/search/"
let asnLinks = asns.map((asn, i) => {
return (<a key={`${asn}_${i}`} href={baseUrl + asn} target="_blank">{asn} </a>);
});
return (
<td>
{asnLinks}
</td>
);
}
2018-07-05 16:02:49 +02:00
const RouteColumn = function(props) {
const widgets = {
"network": ColNetwork,
"bgp.as_path": ColAsPath,
"ASPath": ColAsPath,
2018-07-05 16:02:49 +02:00
};
let Widget = widgets[props.column] || ColDefault;
return (
<Widget column={props.column} route={props.route}
displayReasons={props.displayReasons}
onClick={props.onClick} />
2018-07-05 16:02:49 +02:00
);
}
2017-05-16 13:34:00 +02:00
class RoutesTable extends React.Component {
showAttributesModal(route) {
this.props.dispatch(
showBgpAttributes(route)
);
}
render() {
let routes = this.props.routes;
2018-07-05 10:49:52 +02:00
const routesColumns = this.props.routesColumns;
const routesColumnsOrder = this.props.routesColumnsOrder;
2017-05-16 13:34:00 +02:00
routes = _filteredRoutes(routes, this.props.filter);
if (!routes || !routes.length) {
return null;
}
let routesView = routes.map((r,i) => {
2017-05-16 13:34:00 +02:00
return (
2018-03-23 13:06:27 +01:00
<tr key={`${r.network}_${i}`}>
2018-07-05 16:02:49 +02:00
{routesColumnsOrder.map(col => (<RouteColumn key={col}
2018-07-05 16:39:31 +02:00
onClick={() => this.showAttributesModal(r)}
2018-07-05 16:02:49 +02:00
column={col}
route={r}
displayReasons={this.props.displayReasons} />)
)}
2017-05-16 13:34:00 +02:00
</tr>
);
});
return (
2018-07-16 19:49:54 +02:00
<table className="table table-striped table-routes">
<thead>
<tr>
{routesColumnsOrder.map(col => <th key={col}>{routesColumns[col]}</th>)}
</tr>
</thead>
<tbody>
{routesView}
</tbody>
</table>
2017-05-16 13:34:00 +02:00
);
}
}
2018-07-16 19:49:54 +02:00
/*
OLD ROUTES VIEW.
export default RoutesTable = connect(
2017-05-16 13:34:00 +02:00
(state) => {
return {
2018-07-05 10:49:52 +02:00
filter: state.routeservers.routesFilterValue,
routesColumns: state.config.routes_columns,
routesColumnsOrder: state.config.routes_columns_order,
2017-05-16 13:34:00 +02:00
}
}
)(RoutesTable);
class RoutesTables extends React.Component {
componentDidMount() {
this.props.dispatch(
loadRouteserverRoutes(this.props.routeserverId, this.props.protocolId)
);
}
render() {
if(this.props.isLoading) {
return (
<LoadingIndicator />
);
}
const routes = this.props.routes[this.props.protocolId];
const filtered = this.props.filtered[this.props.protocolId] || [];
const noexport = this.props.noexport[this.props.protocolId] || [];
2017-05-16 13:34:00 +02:00
if((!routes || routes.length == 0) &&
(!filtered || filtered.length == 0)) {
return(
<p className="help-block">
No routes matched your filter.
</p>
);
}
const received = routes.filter(r => filtered.indexOf(r) < 0);
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");
2017-05-16 13:34:00 +02:00
return (
<div>
2018-07-05 10:49:52 +02:00
<RoutesTable header={filtdHeader} routes={filtered} displayReasons="filtered"/>
<RoutesTable header={recvdHeader} routes={received} displayReasons={false}/>
<RoutesTable header={noexHeader} routes={noexport} displayReasons="noexport"/>
2017-05-16 13:34:00 +02:00
</div>
);
}
}
export default connect(
(state) => {
return {
isLoading: state.routeservers.routesAreLoading,
routes: state.routeservers.routes,
filtered: state.routeservers.filtered,
noexport: state.routeservers.noexport,
2017-05-16 13:34:00 +02:00
}
}
)(RoutesTables);
2018-07-16 19:49:54 +02:00
*/