import _ from 'underscore'
import {debounce} from "underscore"
import React from 'react'
import {connect} from 'react-redux'
import {Link} from 'react-router'
import {push, replace} from 'react-router-redux'
import Details from '../details'
import Status from '../status'
import PageHeader from 'components/page-header'
import {apiCacheStatus} from 'components/api-status/cache'
import ProtocolName
from 'components/routeservers/protocols/name'
import SearchInput from 'components/search-input'
import RoutesView from './view'
import QuickLinks from './quick-links'
import RelatedPeers from './related-peers'
import BgpAttributesModal
from './bgp-attributes-modal'
import RoutesLoadingIndicator from './loading-indicator'
// Actions
import {setFilterQueryValue}
from './actions'
import {loadRouteserverProtocol}
from 'components/routeservers/actions'
// Constants
import {ROUTES_RECEIVED,
ROUTES_FILTERED,
ROUTES_NOT_EXPORTED} from './actions';
const makeQueryLinkProps = function(routing, query, loadNotExported) {
// Load not exported routes flag
const ne = loadNotExported ? 1 : 0;
// As we need to reset the pagination, we can just
// ommit these other parameters and just use pathname + query + ne
return {
pathname: routing.pathname,
search: `?ne=${ne}&q=${query}`
};
}
/*
* Check if the routes view is empty, (while nothing is,
* loading) and show info screen.
*/
const RoutesViewEmpty = (props) => {
const isLoading = props.routes.received.loading ||
props.routes.filtered.loading ||
props.routes.notExported.loading;
if (isLoading) {
return null; // We are not a loading indicator.
}
if (!props.loadNotExported) {
return null; // There may be routes matching the query in there!
}
const hasContent = props.routes.received.totalResults > 0 ||
props.routes.filtered.totalResults > 0 ||
props.routes.notExported.totalResults > 0;
if (hasContent) {
return null; // Nothing to do then.
}
// Show info screen
return (
No routes found matching your query.
Please check if your query is too restrictive.
);
}
class RoutesPage extends React.Component {
constructor(props) {
super(props);
// Create debounced dispatch, as we don't want to flood
// the server with API queries
this.debouncedDispatch = debounce(this.props.dispatch, 350);
}
setFilter(value) {
this.props.dispatch(
setFilterQueryValue(value)
);
this.debouncedDispatch(replace(makeQueryLinkProps(
this.props.routing, value, this.props.loadNotExported
)));
}
componentDidMount() {
// Assert neighbors for RS are loaded
this.props.dispatch(
loadRouteserverProtocol(parseInt(this.props.params.routeserverId))
);
}
render() {
let cacheStatus = apiCacheStatus(this.props.routes.received.apiStatus);
if (this.props.anyLoading) {
cacheStatus = null;
}
// We have to shift the layout a bit, to make room for
// the related peers tabs
let pageClass = "routeservers-page";
if (this.props.relatedPeers.length > 1) {
pageClass += " has-related-peers";
}
return(