<commit_before>import Table from "./index";
import orgNamesFetching from "../../orgnames-fetching";
import {pluckImm} from "../../tools";

class FrequentTenderers extends orgNamesFetching(Table){
  constructor(...args){
    super(...args);
    this.state = this.state || {};
    this.state.showAll = false;
  }

  row(entry, index){
    return <tr key={index}>
      <td>{this.getOrgName(entry.getIn(['id', 'tendererId1']))}</td>
      <td>{this.getOrgName(entry.getIn(['id', 'tendererId2']))}</td>
      <td>{entry.getIn(['value', 'pairCount'])}</td>
      <td>{entry.getIn(['value', 'winner1Count'])}</td>
      <td>{entry.getIn(['value', 'winner2Count'])}</td>
    </tr>
  }

  maybeSlice(flag, list){
    return flag ? list.slice(0, 10) : list;
  }

  getOrgsWithoutNamesIds(){
    if(!this.props.data) return [];
    return this.props.data.map(pluckImm('id')).flatten().filter(id => !this.state.orgNames[id]).toJS();
  }

  render(){
    if(!this.props.data) return null;
    const {showAll} = this.state;
    return <table className="table table-stripped trable-hover frequent-supplier-bidder-table">
      <thead>
      <tr>
        <th>{this.t('tables:frequentTenderers:supplier')} #1</th>
        <th>{this.t('tables:frequentTenderers:supplier')} #2</th>
        <th>{this.t('tables:frequentTenderers:nrITB')}</th>
        <th>{this.t('tables:frequentTenderers:supplier1wins')}</th>
        <th>{this.t('tables:frequentTenderers:supplier2wins')}</th>
      </tr>
      </thead>
      <tbody>
      {this.maybeSlice(!showAll, this.props.data).map(this.row.bind(this))}
      {!showAll && this.props.data.count() > 10 && <tr>
        <td colSpan="5">
          <button className="btn btn-info btn-danger btn-block" onClick={_ => this.setState({showAll: true})}>
            {this.t('tables:showAll')}
          </button>
        </td>
      </tr>}
      </tbody>
    </table>
  }
}

FrequentTenderers.getName = t => t('tables:frequentTenderers:title');
FrequentTenderers.endpoint = 'frequentTenderers';

export default FrequentTenderers;<commit_msg>OCUA-16 Frontend changes following EP changes<commit_after>import Table from "./index";
import orgNamesFetching from "../../orgnames-fetching";
import {pluckImm, fetchJson} from "../../tools";
import translatable from '../../translatable';

class WinCount extends translatable(React.Component){
  constructor(...args){
    super(...args);
    this.state = {
      cnt: this.t("general:loading")
    }
  }

  componentDidMount(){
    const {id} = this.props;
    fetchJson(`/api/activeAwardsCount?supplierId=${id}`)
      .then(response => this.setState({
        cnt: response[0].cnt
      }))
  }

  render(){
    const {id} = this.props;
    const {cnt} = this.state;
    return <td>{cnt}</td>
  }
}

class FrequentTenderers extends orgNamesFetching(Table){
  constructor(...args){
    super(...args);
    this.state = this.state || {};
    this.state.showAll = false;
  }

  row(entry, index){
    const {translations} = this.props;
    const id1 = entry.get('tendererId1');
    const id2 = entry.get('tendererId2');
    return <tr key={index}>
      <td>{this.getOrgName(id1)}</td>
      <td>{this.getOrgName(id2)}</td>
      <td>{entry.get('pairCount')}</td>
      <WinCount id={id1} translations={translations}/>
      <WinCount id={id2} translations={translations}/>
    </tr>
  }

  maybeSlice(flag, list){
    return flag ? list.slice(0, 10) : list;
  }

  getOrgsWithoutNamesIds(){
    const {data} = this.props;
    if(!data) return [];
    return data.map(datum => List([datum.get('tendererId1'), datum.get('tendererId2')]))
      .flatten()
      .filter(id => !this.state.orgNames[id]).toJS();
  }

  render(){
    if(!this.props.data) return null;
    const {showAll} = this.state;
    return <table className="table table-stripped trable-hover frequent-supplier-bidder-table">
      <thead>
      <tr>
        <th>{this.t('tables:frequentTenderers:supplier')} #1</th>
        <th>{this.t('tables:frequentTenderers:supplier')} #2</th>
        <th>{this.t('tables:frequentTenderers:nrITB')}</th>
        <th>{this.t('tables:frequentTenderers:supplier1wins')}</th>
        <th>{this.t('tables:frequentTenderers:supplier2wins')}</th>
      </tr>
      </thead>
      <tbody>
      {this.maybeSlice(!showAll, this.props.data).map(this.row.bind(this))}
      {!showAll && this.props.data.count() > 10 && <tr>
        <td colSpan="5">
          <button className="btn btn-info btn-danger btn-block" onClick={_ => this.setState({showAll: true})}>
            {this.t('tables:showAll')}
          </button>
        </td>
      </tr>}
      </tbody>
    </table>
  }
}

FrequentTenderers.getName = t => t('tables:frequentTenderers:title');
FrequentTenderers.endpoint = 'frequentTenderers';

export default FrequentTenderers;

{'fraction_non_alphanumeric': 0.19197827449341967, 'fraction_numerical': 0.007729266764152914, 'mean_word_length': 3.263579697239537, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 85, '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': '2885888', 'n_tokens_mistral': 1711, 'n_tokens_neox': 1666, 'n_words': 263}