<commit_before>import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import {
  Link
} from 'react-router-dom'

import block from '../../../helpers/bem-cn'
import isNoSearchResults from '../../../helpers/isNoSearchResults'

import PaginatedList from '../../PaginatedList/PaginatedList'
import Button from '../../../components/Button/Button'
import Icon from '../../../components/Icon/Icon'
import Control from '../../../components/Control/Control'
import Preloader from '../../../components/Preloader/Preloader'
import NoSearchResults from '../../../components/NoSearchResults/NoSearchResults'

import '../../Layout/Table/Table.css'

const propTypes = {
  apiList: PropTypes.arrayOf(PropTypes.object.isRequired).isRequired,
  currentPageIndex: PropTypes.number.isRequired,
  isAdmin: PropTypes.bool.isRequired,
  setCurrentPageIndex: PropTypes.func.isRequired,
  deleteEndpoint: PropTypes.func.isRequired,
  fetchEndpoints: PropTypes.func.isRequired,
  refreshEndpoints: PropTypes.func.isRequired,
  setSortingFilter: PropTypes.func.isRequired,
  searchQuery: PropTypes.string.isRequired
}

const table = block('j-table')

class ApiList extends PureComponent {
  componentDidMount () {
    this.props.fetchEndpoints()
  }

    isOauthEnabled = (plugins) => {
    // @TODO: find why
    // if (typeof this.isProtected !== 'undefined') {
    //   return this.isProtected;
    // }
      const oauth = plugins.find(plugin => plugin.name.indexOf('oauth2') > -1)

      return !!oauth && !!oauth.enabled
    }

    handleDelete = api => {
      this.props.deleteEndpoint(api)
    };

    renderRows = list => list.map((api, index) => (
      <div className={table('row')()} key={`${index}-${api.name}`}>
        <div className={table('td', {name: true})()}>{api.name}</div>
        <div className={table('td')()}>{api.proxy.listen_path}</div>
        <div className={table('td', {active: true})()}>
          {api.active ? <Icon type='checked' /> : null}
        </div>
        <div className={table('td').mix(table('controls'))()}>
          <Link to={`/${api.name}`} className={table('controls-item')()}>
            <Icon type='edit' ariaLabel='Edit' />
          </Link>
          <Link
            to={{
              pathname: '/new',
              state: {
                clone: api
              }
            }}
            className={table('controls-item')()}
          >
            <Icon type='copy' ariaLabel='Copy' />
          </Link>
          <Button
            mod='primary'
            type='button'
            size='small'
          >
            Copy as JSON
          </Button>
          {
            this.props.isAdmin &&
            <Control
              className={table('controls-item')()}
              icon='delete'
              onClick={() => {
                this.handleDelete(api)
              }}
            />
          }
        </div>
      </div>
    ))

    sortList = filter => {
      this.props.setSortingFilter(filter)
      this.props.setAscendingFilter()
    }

    renderTable = list => (
      <div className={table()}>
        <div className={table('head')()}>
          <div className={table('row')()}>
            <div
              className={table('th').mix('ascending-container')()}
              onClick={() => this.sortList('name')}<commit_msg>grab api which should be copied ot clipboard<commit_after>import React, { PureComponent } from 'react'
import PropTypes from 'prop-types'
import {
  Link
} from 'react-router-dom'

import block from '../../../helpers/bem-cn'
import isNoSearchResults from '../../../helpers/isNoSearchResults'

import PaginatedList from '../../PaginatedList/PaginatedList'
import Button from '../../../components/Button/Button'
import Icon from '../../../components/Icon/Icon'
import Control from '../../../components/Control/Control'
import Preloader from '../../../components/Preloader/Preloader'
import NoSearchResults from '../../../components/NoSearchResults/NoSearchResults'

import '../../Layout/Table/Table.css'

const propTypes = {
  apiList: PropTypes.arrayOf(PropTypes.object.isRequired).isRequired,
  currentPageIndex: PropTypes.number.isRequired,
  isAdmin: PropTypes.bool.isRequired,
  setCurrentPageIndex: PropTypes.func.isRequired,
  deleteEndpoint: PropTypes.func.isRequired,
  fetchEndpoints: PropTypes.func.isRequired,
  refreshEndpoints: PropTypes.func.isRequired,
  setSortingFilter: PropTypes.func.isRequired,
  searchQuery: PropTypes.string.isRequired
}

const table = block('j-table')

class ApiList extends PureComponent {
  componentDidMount () {
    this.props.fetchEndpoints()
  }

    isOauthEnabled = (plugins) => {
    // @TODO: find why
    // if (typeof this.isProtected !== 'undefined') {
    //   return this.isProtected;
    // }
      const oauth = plugins.find(plugin => plugin.name.indexOf('oauth2') > -1)

      return !!oauth && !!oauth.enabled
    }

    handleDelete = api => {
      this.props.deleteEndpoint(api)
    };

    handleCopyAsJSON = api => {
      console.log('Copy as JSON: ', api)
    }

    renderRows = list => list.map((api, index) => (
      <div className={table('row')()} key={`${index}-${api.name}`}>
        <div className={table('td', {name: true})()}>{api.name}</div>
        <div className={table('td')()}>{api.proxy.listen_path}</div>
        <div className={table('td', {active: true})()}>
          {api.active ? <Icon type='checked' /> : null}
        </div>
        <div className={table('td').mix(table('controls'))()}>
          <Link to={`/${api.name}`} className={table('controls-item')()}>
            <Icon type='edit' ariaLabel='Edit' />
          </Link>
          <Link
            to={{
              pathname: '/new',
              state: {
                clone: api
              }
            }}
            className={table('controls-item')()}
          >
            <Icon type='copy' ariaLabel='Copy' />
          </Link>
          <Button
            mod='primary'
            type='button'
            size='small'
            onClick={() => {
              this.handleCopyAsJSON(api)
            }}
          >
            Copy as JSON
          </Button>
          {
            this.props.isAdmin &&
            <Control
              className={table('controls-item')()}
              icon='delete'
              onClick={() => {
                this.handleDelete(api)
              }}
            />
          }
        </div>
      </div>
    ))

    sortList = filter => {
      this.props.setSortingFilter(filter)
      this.props.setAscendingFilter()
    }

    renderTable = list => (
      <div className={table()}>
        <div className={table('head')()}>
          <div className={table('row')()}>
            <div
              className={table('th').mix('ascending-container')()}
              onClick={() => this.sortList('name')}
{'fraction_non_alphanumeric': 0.1691004672897196, 'fraction_numerical': 0.0005841121495327102, 'mean_word_length': 2.1841004184100417, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 71, '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': '5616165', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1981, 'n_words': 360}