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'
|
2017-06-26 16:42:07 +02:00
|
|
|
import {Link} from 'react-router'
|
2018-09-17 16:26:42 +02:00
|
|
|
import {replace} from 'react-router-redux'
|
2017-05-16 13:34:00 +02:00
|
|
|
|
2018-10-23 19:40:36 +02:00
|
|
|
import {filtersEqual} from 'components/filters/filter'
|
2018-10-18 23:14:50 +02:00
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
import FilterReason
|
2018-10-03 19:27:12 +02:00
|
|
|
from 'components/routeservers/communities/filter-reason'
|
2017-05-16 13:34:00 +02:00
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
import NoexportReason
|
2018-10-03 19:27:12 +02:00
|
|
|
from 'components/routeservers/communities/noexport-reason'
|
2017-05-16 13:34:00 +02:00
|
|
|
|
2017-06-26 16:42:07 +02:00
|
|
|
import BgpAttributesModal
|
|
|
|
from 'components/routeservers/routes/bgp-attributes-modal'
|
|
|
|
|
|
|
|
import LoadingIndicator
|
|
|
|
from 'components/loading-indicator/small'
|
|
|
|
|
2018-08-03 12:22:10 +02:00
|
|
|
import ResultsTable from './table'
|
2017-05-16 13:34:00 +02:00
|
|
|
|
2018-09-17 16:26:42 +02:00
|
|
|
import {loadResults, reset} from './actions'
|
|
|
|
|
2018-09-25 23:07:23 +02:00
|
|
|
import {RoutesPaginator,
|
|
|
|
RoutesPaginationInfo} from './pagination'
|
|
|
|
|
|
|
|
import {RoutesHeader}
|
|
|
|
from 'components/routeservers/routes/view'
|
|
|
|
|
|
|
|
|
2017-05-16 13:34:00 +02:00
|
|
|
|
2018-08-03 12:22:10 +02:00
|
|
|
const ResultsView = function(props) {
|
2018-10-18 17:13:39 +02:00
|
|
|
if(!props.routes) {
|
|
|
|
return null;
|
|
|
|
}
|
2018-08-03 12:22:10 +02:00
|
|
|
if(props.routes.length == 0) {
|
|
|
|
return null;
|
2017-06-26 15:35:54 +02:00
|
|
|
}
|
2017-05-16 13:34:00 +02:00
|
|
|
|
2018-09-25 23:07:23 +02:00
|
|
|
const type = props.type;
|
|
|
|
|
2018-08-03 12:22:10 +02:00
|
|
|
return (
|
2018-10-03 22:40:40 +02:00
|
|
|
<div className={`card routes-view routes-${type}`}>
|
2018-09-25 23:07:23 +02:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-md-6 routes-header-container">
|
|
|
|
<RoutesHeader type={type} />
|
|
|
|
</div>
|
|
|
|
<div className="col-md-6">
|
|
|
|
<RoutesPaginationInfo page={props.page}
|
|
|
|
pageSize={props.pageSize}
|
|
|
|
totalPages={props.totalPages}
|
|
|
|
totalResults={props.totalResults} />
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-08-03 12:22:10 +02:00
|
|
|
<ResultsTable routes={props.routes}
|
2018-09-17 01:29:56 +02:00
|
|
|
displayReasons={props.displayReasons} />
|
2018-09-25 23:07:23 +02:00
|
|
|
<center>
|
|
|
|
<RoutesPaginator page={props.page} totalPages={props.totalPages}
|
|
|
|
queryParam={props.query}
|
|
|
|
anchor={type} />
|
|
|
|
</center>
|
2018-08-03 12:22:10 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2017-06-26 22:48:02 +02:00
|
|
|
|
|
|
|
class NoResultsView extends React.Component {
|
|
|
|
render() {
|
|
|
|
if (!this.props.show) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<p className="lookup-no-results text-info card">
|
|
|
|
No prefixes could be found for <b>{this.props.query}</b>
|
|
|
|
</p>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-25 22:32:31 +02:00
|
|
|
const NoResultsFallback = connect(
|
2017-06-26 22:48:02 +02:00
|
|
|
(state) => {
|
2018-09-25 23:07:23 +02:00
|
|
|
let total = state.lookup.totalRoutes;
|
2017-06-26 22:48:02 +02:00
|
|
|
let query = state.lookup.query;
|
|
|
|
let isLoading = state.lookup.isLoading;
|
|
|
|
|
|
|
|
let show = false;
|
|
|
|
|
|
|
|
if (total == 0 && query != "" && isLoading == false) {
|
|
|
|
show = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
show: show,
|
|
|
|
query: state.lookup.query
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)(NoResultsView);
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
class LookupResults extends React.Component {
|
|
|
|
|
2018-10-01 19:10:46 +02:00
|
|
|
dispatchLookup() {
|
|
|
|
const query = this.props.query;
|
|
|
|
const pageImported = this.props.pagination.imported.page;
|
|
|
|
const pageFiltered = this.props.pagination.filtered.page;
|
2018-10-18 16:22:19 +02:00
|
|
|
const filters = this.props.filtersApplied;
|
2018-10-01 19:10:46 +02:00
|
|
|
|
2018-09-17 16:30:19 +02:00
|
|
|
if (query == "") {
|
|
|
|
// Dispatch reset and transition to main page
|
|
|
|
this.props.dispatch(reset());
|
|
|
|
this.props.dispatch(replace("/"));
|
|
|
|
} else {
|
|
|
|
this.props.dispatch(
|
2018-10-18 16:22:19 +02:00
|
|
|
loadResults(query, filters, pageImported, pageFiltered)
|
2018-09-17 16:30:19 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-17 16:26:42 +02:00
|
|
|
componentDidMount() {
|
|
|
|
// Dispatch query
|
2018-10-01 19:10:46 +02:00
|
|
|
this.dispatchLookup();
|
2018-09-17 16:26:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate(prevProps) {
|
2018-10-01 19:10:46 +02:00
|
|
|
if(this.props.query != prevProps.query ||
|
|
|
|
this.props.pagination.filtered.page != prevProps.pagination.filtered.page ||
|
2018-10-18 23:14:50 +02:00
|
|
|
this.props.pagination.imported.page != prevProps.pagination.imported.page ||
|
|
|
|
!filtersEqual(this.props.filtersApplied, prevProps.filtersApplied)) {
|
2018-10-01 19:10:46 +02:00
|
|
|
this.dispatchLookup();
|
2018-09-17 16:26:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
render() {
|
2017-06-26 16:42:07 +02:00
|
|
|
if(this.props.isLoading) {
|
2018-09-25 23:07:23 +02:00
|
|
|
return <LoadingIndicator />;
|
2017-06-26 16:42:07 +02:00
|
|
|
}
|
|
|
|
|
2018-10-01 19:10:46 +02:00
|
|
|
const ref = this.refs[this.props.anchor];
|
|
|
|
if(ref) {
|
|
|
|
ref.scrollIntoView();
|
|
|
|
}
|
|
|
|
|
2018-09-17 16:26:42 +02:00
|
|
|
const filteredRoutes = this.props.routes.filtered;
|
|
|
|
const importedRoutes = this.props.routes.imported;
|
2017-06-26 15:35:54 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="lookup-results">
|
2017-06-26 16:42:07 +02:00
|
|
|
<BgpAttributesModal />
|
|
|
|
|
2018-09-25 22:32:31 +02:00
|
|
|
<NoResultsFallback />
|
2017-06-26 22:48:02 +02:00
|
|
|
|
2018-10-01 19:10:46 +02:00
|
|
|
<a ref="filtered" name="routes-filtered" />
|
2018-09-25 23:07:23 +02:00
|
|
|
<ResultsView type="filtered"
|
2018-08-03 12:22:10 +02:00
|
|
|
routes={filteredRoutes}
|
2018-09-25 23:07:23 +02:00
|
|
|
|
|
|
|
page={this.props.pagination.filtered.page}
|
|
|
|
pageSize={this.props.pagination.filtered.pageSize}
|
|
|
|
totalPages={this.props.pagination.filtered.totalPages}
|
|
|
|
totalResults={this.props.pagination.filtered.totalResults}
|
|
|
|
|
|
|
|
query={this.props.query}
|
|
|
|
|
2018-09-17 01:29:56 +02:00
|
|
|
displayReasons="filtered" />
|
|
|
|
|
2018-10-01 19:10:46 +02:00
|
|
|
<a ref="received" name="routes-received" />
|
2018-09-25 23:07:23 +02:00
|
|
|
<ResultsView type="received"
|
|
|
|
|
|
|
|
page={this.props.pagination.imported.page}
|
|
|
|
pageSize={this.props.pagination.imported.pageSize}
|
|
|
|
totalPages={this.props.pagination.imported.totalPages}
|
|
|
|
totalResults={this.props.pagination.imported.totalResults}
|
2018-10-18 23:14:50 +02:00
|
|
|
|
2018-09-25 23:07:23 +02:00
|
|
|
query={this.props.query}
|
|
|
|
|
2018-08-03 12:22:10 +02:00
|
|
|
routes={importedRoutes} />
|
2017-06-26 15:35:54 +02:00
|
|
|
</div>
|
2018-10-01 19:10:46 +02:00
|
|
|
);
|
2017-06-26 15:35:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(
|
|
|
|
(state) => {
|
2018-09-25 22:32:31 +02:00
|
|
|
const filteredRoutes = state.lookup.routesFiltered;
|
2018-10-18 23:14:50 +02:00
|
|
|
const importedRoutes = state.lookup.routesImported;
|
2018-09-25 22:32:31 +02:00
|
|
|
|
2017-06-26 15:35:54 +02:00
|
|
|
return {
|
2018-10-01 19:10:46 +02:00
|
|
|
anchor: state.lookup.anchor,
|
2017-06-26 15:35:54 +02:00
|
|
|
routes: {
|
|
|
|
filtered: filteredRoutes,
|
|
|
|
imported: importedRoutes
|
2017-06-26 22:48:02 +02:00
|
|
|
},
|
2018-09-25 22:32:31 +02:00
|
|
|
pagination: {
|
|
|
|
filtered: {
|
|
|
|
page: state.lookup.pageFiltered,
|
2018-09-25 23:07:23 +02:00
|
|
|
pageSize: state.lookup.pageSizeFiltered,
|
2018-09-25 22:32:31 +02:00
|
|
|
totalPages: state.lookup.totalPagesFiltered,
|
2018-09-25 23:07:23 +02:00
|
|
|
totalResults: state.lookup.totalRoutesFiltered,
|
2018-09-25 22:32:31 +02:00
|
|
|
},
|
|
|
|
imported: {
|
|
|
|
page: state.lookup.pageImported,
|
2018-09-25 23:07:23 +02:00
|
|
|
pageSize: state.lookup.pageSizeImported,
|
2018-09-25 22:32:31 +02:00
|
|
|
totalPages: state.lookup.totalPagesImported,
|
2018-09-25 23:07:23 +02:00
|
|
|
totalResults: state.lookup.totalRoutesImported,
|
2018-09-25 22:32:31 +02:00
|
|
|
}
|
|
|
|
},
|
2018-09-17 16:26:42 +02:00
|
|
|
isLoading: state.lookup.isLoading,
|
|
|
|
query: state.lookup.query,
|
2018-10-18 16:22:19 +02:00
|
|
|
filtersApplied: state.lookup.filtersApplied,
|
2017-06-26 15:35:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)(LookupResults);
|
2017-05-16 13:34:00 +02:00
|
|
|
|