<commit_before>import React from "react";
import Sidebar from "components/Sidebar";
import {Link} from "react-router";
import {connect} from "react-redux";
import {fetchCountry} from '../actions/countryActions';
import {fetchProducts} from '../actions/productsActions';
import {fetchTradesByCountry} from "../actions/tradesActions";
import {fetchCaTradesByCountry} from "../actions/tradesActions";
import {Card} from "../components/Card.jsx";
import "./Detailed.css";
import "../components/Dropdown.css";
import Select from "react-select";
import Dropdown from "../components/Dropdown";
import {fetchData} from "datawheel-canon";
import {url} from "../api";
import CountryHeader from "../components/CountryHeader"

class CountryWithId extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedOption: "all",
      product: {
        label: "All",
        value: "all"
      }
    };
  }

  componentWillMount() {
    const id = this.props.params.countryWithId;
    this.props.fetchProducts();
    this.props.fetchCountry(id);
    this.props.fetchTradesByCountry(id);
  }

  componentWillReceiveProps(newProps) {
    if (newProps.params.countryWithId !== this.props.params.countryWithId) {
      const id = newProps.params.countryWithId
      this.props.fetchProducts();
      this.props.fetchTradesByCountry(id);
      this.props.fetchCountry(id);
      this.removeSelection();
    }
  }

  handleOptionChange = selectedOption => {
    this.setState({selectedOption});
  }

  arrowRenderer = () => {
    return (
      <span className="chevron bottom"></span>
    );
  }

  filterCompanies(trades) {
    const seen = [];
    const filteredResult = [];
    for (let i = 0; i < trades.length; i++) {
      const trade = trades[i];
      let unique = true;


      //if it is NOT a connectamericas company
      if(trade.id.toString().slice(0, 3) !== "ca_") {
        unique = !seen.includes(trade.company_id);
      }



      const tradeFlow = this.state.selectedOption === "all" ||  trade.trade_flow === `${this.state.selectedOption}`;
      const product = this.state.product.value === "all" || (trade.product_id ? this.state.product.value === trade.product_id.slice(0,4) : false);

      if (tradeFlow && product && unique) {
        console.log(trade);
        if(trade.company_id) {seen.push(trade.company_id);}
        filteredResult.push(trade);
      }
    }
    console.log(filteredResult)
    return filteredResult;
  }

  compare(a, b, attr) {
      if (a[attr] < b[attr]) {
        return -1;
      }
      if (a[attr] > b[attr]) {
        return 1;
      }
      return 0;
    }


  removeSelection = () => {
    this.setState({
      product: {
        label: "All",
        value: "all"
      },
      selectedOption: "all"
    });
  }

  selectDropDown = item => {
    this.setState({product: item});
  }

  render() {
    const {loading, error, products, trades, caTrades, tradesLoading, caTradesLoading} = this.props;
    const {country, countryData, importData, exportData} = this.props.data;
<commit_msg>removed duplicate filter from country page<commit_after>import React from "react";
import Sidebar from "components/Sidebar";
import {Link} from "react-router";
import {connect} from "react-redux";
import {fetchCountry} from '../actions/countryActions';
import {fetchProducts} from '../actions/productsActions';
import {fetchTradesByCountry} from "../actions/tradesActions";
import {fetchCaTradesByCountry} from "../actions/tradesActions";
import {Card} from "../components/Card.jsx";
import "./Detailed.css";
import "../components/Dropdown.css";
import Select from "react-select";
import Dropdown from "../components/Dropdown";
import {fetchData} from "datawheel-canon";
import {url} from "../api";
import CountryHeader from "../components/CountryHeader"

class CountryWithId extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      selectedOption: "all",
      product: {
        label: "All",
        value: "all"
      }
    };
  }

  componentWillMount() {
    const id = this.props.params.countryWithId;
    this.props.fetchProducts();
    this.props.fetchCountry(id);
    this.props.fetchTradesByCountry(id);
  }

  componentWillReceiveProps(newProps) {
    if (newProps.params.countryWithId !== this.props.params.countryWithId) {
      const id = newProps.params.countryWithId
      this.props.fetchProducts();
      this.props.fetchTradesByCountry(id);
      this.props.fetchCountry(id);
      this.removeSelection();
    }
  }

  handleOptionChange = selectedOption => {
    this.setState({selectedOption});
  }

  arrowRenderer = () => {
    return (
      <span className="chevron bottom"></span>
    );
  }


  compare(a, b, attr) {
      if (a[attr] < b[attr]) {
        return -1;
      }
      if (a[attr] > b[attr]) {
        return 1;
      }
      return 0;
    }


  removeSelection = () => {
    this.setState({
      product: {
        label: "All",
        value: "all"
      },
      selectedOption: "all"
    });
  }

  selectDropDown = item => {
    this.setState({product: item});
  }

  render() {
    const {loading, error, products, trades, caTrades, tradesLoading, caTradesLoading} = this.props;
    const {country, countryData, importData, exportData} = this.props.data;

{'fraction_non_alphanumeric': 0.14692568841946435, 'fraction_numerical': 0.002074688796680498, 'mean_word_length': 3.0296352583586628, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 17, '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': '1850534', 'n_tokens_mistral': 1653, 'n_tokens_neox': 1600, 'n_words': 348}