<commit_before>

import _ from 'underscore'

import React from 'react'
import {connect} from 'react-redux'

import {loadRouteserverProtocol}
  from 'components/routeservers/actions'

import {Link} from 'react-router'

import RelativeTime from 'components/relativetime'

import Spinner from 'react-spinkit'


function _filteredProtocols(protocols, filter) {
  let filtered = [];
  if(filter == "") {
    return protocols; // nothing to do here
  }

  filter = filter.toLowerCase();

  // Filter protocols
  filtered = _.filter(protocols, (p) => {
    return (p.neighbor_address.toLowerCase().indexOf(filter) != -1 ||
            p.description.toLowerCase().indexOf(filter) != -1);
  });

  return filtered;
}

class ProtocolTable extends React.Component {

  componentDidMount() {
    this.props.dispatch(
      loadRouteserverProtocol(parseInt(this.props.routeserverId))
    );
  }

  componentWillReceiveProps(nextProps) {
    if(this.props.routeserverId != nextProps.routeserverId) {
      this.props.dispatch(
        loadRouteserverProtocol(parseInt(nextProps.routeserverId))
      );
    }
  }

  render() {
    if(this.props.isLoading) {
      return (
        <div className="loading-indicator">
          <Spinner spinnerName="circle" />
        </div>
      );
    }


    let protocol = this.props.protocols[parseInt(this.props.routeserverId)];
    if(!protocol) {
      return null;
    }

    protocol = _filteredProtocols(protocol, this.props.filter);
    if(!protocol || protocol.length == 0) {
      return (
        <p className="help-block">
          No protocols could be found.
        </p>
      );
    }


    let neighbours = [];
    for (let id in protocol) {
      let n = protocol[id];

      let routesLink = `/routeservers/${this.props.routeserverId}/protocols/${n.protocol}/routes`;
      neighbours.push(
        <tr key={id}>
          <td>
            <Link to={routesLink}>
             {n.neighbor_address}
            </Link>
           </td>
          <td>{n.neighbor_as}</td>
          <td>{n.state}</td>
          <td>
            <RelativeTime value={n.state_changed} suffix={true} />
          </td>
          <td>
            <Link to={routesLink}>
              {n.description}
            </Link>
          </td>
          <td>
            <Link to={routesLink}>
              {n.routes.imported}
            </Link>
          </td>
        </tr>
      );
    }

    return (
      <div>
        <table className="table table-striped">
          <thead>
            <tr>
              <th>Neighbour</th>
              <th>ASN</th>
              <th>State</th>
              <th>Uptime</th>
              <th>Description</th>
              <th>Routes Recv.</th>
            </tr>
          </thead>
          <tbody>
            {neighbours}
          </tbody>
        </table>
      </div>
    );
  }
}




export default connect(
  (state) => {
    return {
      isLoading: state.routeservers.protocolsAreLoading,
      protocols: state.routeservers.protocols,
      filter: state.routeservers.protocolsFilterValue
    }
  }
)(ProtocolTable);
<commit_msg>added filtered routes to display (will only be displayed with birdwatcher, not inex birdseye)<commit_after>

import _ from 'underscore'

import React from 'react'
import {connect} from 'react-redux'

import {loadRouteserverProtocol}
  from 'components/routeservers/actions'

import {Link} from 'react-router'

import RelativeTime from 'components/relativetime'

import Spinner from 'react-spinkit'


function _filteredProtocols(protocols, filter) {
  let filtered = [];
  if(filter == "") {
    return protocols; // nothing to do here
  }

  filter = filter.toLowerCase();

  // Filter protocols
  filtered = _.filter(protocols, (p) => {
    return (p.neighbor_address.toLowerCase().indexOf(filter) != -1 ||
            p.description.toLowerCase().indexOf(filter) != -1);
  });

  return filtered;
}

class ProtocolTable extends React.Component {

  componentDidMount() {
    this.props.dispatch(
      loadRouteserverProtocol(parseInt(this.props.routeserverId))
    );
  }

  componentWillReceiveProps(nextProps) {
    if(this.props.routeserverId != nextProps.routeserverId) {
      this.props.dispatch(
        loadRouteserverProtocol(parseInt(nextProps.routeserverId))
      );
    }
  }

  render() {
    if(this.props.isLoading) {
      return (
        <div className="loading-indicator">
          <Spinner spinnerName="circle" />
        </div>
      );
    }


    let protocol = this.props.protocols[parseInt(this.props.routeserverId)];
    if(!protocol) {
      return null;
    }

    protocol = _filteredProtocols(protocol, this.props.filter);
    if(!protocol || protocol.length == 0) {
      return (
        <p className="help-block">
          No protocols could be found.
        </p>
      );
    }


    let neighbours = [];
    for (let id in protocol) {
      let n = protocol[id];

      let routesLink = `/routeservers/${this.props.routeserverId}/protocols/${n.protocol}/routes`;
      neighbours.push(
        <tr key={id}>
          <td>
            <Link to={routesLink}>
             {n.neighbor_address}
            </Link>
           </td>
          <td>{n.neighbor_as}</td>
          <td>{n.state}</td>
          <td>
            <RelativeTime value={n.state_changed} suffix={true} />
          </td>
          <td>
            <Link to={routesLink}>
              {n.description}
            </Link>
          </td>
          <td>
            <Link to={routesLink}>
              {n.routes.imported}
            </Link>
          </td>
        <td>
            <Link to={routesLink}>
              {n.routes.filtered}
            </Link>
          </td>
        </tr>
      );
    }

    return (
      <div>
        <table className="table table-striped">
          <thead>
            <tr>
              <th>Neighbour</th>
              <th>ASN</th>
              <th>State</th>
              <th>Uptime</th>
              <th>Description</th>
              <th>Routes Recv.</th>
              <th>Routes Filtered</th>
            </tr>
          </thead>
          <tbody>
            {neighbours}
          </tbody>
        </table>
      </div>
    );
  }
}




export default connect(
  (state) => {
    return {
      isLoading: state.routeservers.protocolsAreLoading,
      protocols: state.routeservers.protocols,
      filter: state.routeservers.protocolsFilterValue
    }
  }
)(ProtocolTable);

{'fraction_non_alphanumeric': 0.1343793692713997, 'fraction_numerical': 0.0009321112319403449, 'mean_word_length': 1.9039242219215156, 'pattern_counts': {'":': 0, '<': 105, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5101380', 'n_tokens_mistral': 2002, 'n_tokens_neox': 1976, 'n_words': 361}