<commit_before>import classNames from 'classnames';
import {Confirm, Table} from 'reactjs-components';
import mixin from 'reactjs-mixin';
/* eslint-disable no-unused-vars */
import React from 'react';
/* eslint-enable no-unused-vars */
import {StoreMixin} from 'mesosphere-shared-reactjs';

import Config from '../config/Config';
import CosmosPackagesStore from '../stores/CosmosPackagesStore';
import List from '../structs/List';
import RepositoriesTableHeaderLabels from '../constants/RepositoriesTableHeaderLabels';
import ResourceTableUtil from '../utils/ResourceTableUtil';
import TableUtil from '../utils/TableUtil';

const METHODS_TO_BIND = [
  'getHeadline',
  'getRemoveButton',
  'handleOpenConfirm',
  'handleDeleteCancel',
  'handleDeleteRepository'
];

class RepositoriesTable extends mixin(StoreMixin) {
  constructor() {
    super();

    this.state = {
      repositoryToRemove: null,
      repositoryRemoveError: null,
      pendingRequest: false
    };

    this.store_listeners = [{
      name: 'cosmosPackages',
      events: ['repositoryDeleteError', 'repositoryDeleteSuccess'],
      unmountWhen: function () {
        return true;
      },
      listenAlways: true
    }];

    METHODS_TO_BIND.forEach((method) => {
      this[method] = this[method].bind(this);
    });
  }

  onCosmosPackagesStoreRepositoryDeleteError(error) {
    this.setState({repositoryRemoveError: error, pendingRequest: false});
  }

  onCosmosPackagesStoreRepositoryDeleteSuccess() {
    this.setState({
      repositoryToRemove: null,
      repositoryRemoveError: null,
      pendingRequest: false
    });
    CosmosPackagesStore.fetchRepositories();
  }

  handleOpenConfirm(repositoryToRemove) {
    this.setState({repositoryToRemove});
  }

  handleDeleteCancel() {
    this.setState({repositoryToRemove: null});
  }

  handleDeleteRepository() {
    let {repositoryToRemove} = this.state;
    CosmosPackagesStore.deleteRepository(
      repositoryToRemove.get('name'),
      repositoryToRemove.get('url')
    );

    this.setState({pendingRequest: true});
  }

  getClassName(prop, sortBy, row) {
    return classNames({
      'highlight': prop === sortBy.prop,
      'clickable': row == null // this is a header
    });
  }

  getColumns() {
    let getClassName = this.getClassName;
    let heading = ResourceTableUtil
      .renderHeading(RepositoriesTableHeaderLabels);
    let sortFunction = TableUtil.getSortFunction('uri', function (item, prop) {
      return item.get(prop);
    });

    return [
      {
        className: getClassName,
        headerClassName: getClassName,
        heading,
        prop: 'name',
        render: this.getHeadline,
        sortable: true,
        sortFunction
      },
      {
        className: getClassName,
        headerClassName: getClassName,
        heading,
        prop: 'uri',
        render: this.getUri,
        sortable: true,
        sortFunction
      },
      {
        className: getClassName,
        headerClassName: getClassName,
        heading: function () {},
        prop: 'removed',
        render: this.getRemoveButton,
        sortable: false
      }
    ];
  }

  getColGroup() {
    return (
      <colgroup>
        <col style={{width: '30%'}} />
        <col />
        <col style={{width: '120px'}} />
      </colgroup>
    );
  }

  getUri(prop, repository) {
    return (
      <div className="flex-box table-cell-flex-box">
        <span className="text-overflow-break-word" title={repository.get('uri')}>
          {repository.get('uri')}
        </span>
      </div>
    );
  }

  getHeadline(prop, repository) {
    return (
      <div className="flex-box flex-box-align-vertical-center table-cell-flex-box">
        <span className="text-overflow">
          {repository.get('name')}
        </span>
      </div>
    );
  }

  getRemoveButton(prop, repositoryToRemove) {
    return (<commit_msg>Setting 'Remove' column to width of largest size<commit_after>import classNames from 'classnames';
import {Confirm, Table} from 'reactjs-components';
import mixin from 'reactjs-mixin';
/* eslint-disable no-unused-vars */
import React from 'react';
/* eslint-enable no-unused-vars */
import {StoreMixin} from 'mesosphere-shared-reactjs';

import Config from '../config/Config';
import CosmosPackagesStore from '../stores/CosmosPackagesStore';
import List from '../structs/List';
import RepositoriesTableHeaderLabels from '../constants/RepositoriesTableHeaderLabels';
import ResourceTableUtil from '../utils/ResourceTableUtil';
import TableUtil from '../utils/TableUtil';

const METHODS_TO_BIND = [
  'getHeadline',
  'getRemoveButton',
  'handleOpenConfirm',
  'handleDeleteCancel',
  'handleDeleteRepository'
];

class RepositoriesTable extends mixin(StoreMixin) {
  constructor() {
    super();

    this.state = {
      repositoryToRemove: null,
      repositoryRemoveError: null,
      pendingRequest: false
    };

    this.store_listeners = [{
      name: 'cosmosPackages',
      events: ['repositoryDeleteError', 'repositoryDeleteSuccess'],
      unmountWhen: function () {
        return true;
      },
      listenAlways: true
    }];

    METHODS_TO_BIND.forEach((method) => {
      this[method] = this[method].bind(this);
    });
  }

  onCosmosPackagesStoreRepositoryDeleteError(error) {
    this.setState({repositoryRemoveError: error, pendingRequest: false});
  }

  onCosmosPackagesStoreRepositoryDeleteSuccess() {
    this.setState({
      repositoryToRemove: null,
      repositoryRemoveError: null,
      pendingRequest: false
    });
    CosmosPackagesStore.fetchRepositories();
  }

  handleOpenConfirm(repositoryToRemove) {
    this.setState({repositoryToRemove});
  }

  handleDeleteCancel() {
    this.setState({repositoryToRemove: null});
  }

  handleDeleteRepository() {
    let {repositoryToRemove} = this.state;
    CosmosPackagesStore.deleteRepository(
      repositoryToRemove.get('name'),
      repositoryToRemove.get('url')
    );

    this.setState({pendingRequest: true});
  }

  getClassName(prop, sortBy, row) {
    return classNames({
      'highlight': prop === sortBy.prop,
      'clickable': row == null // this is a header
    });
  }

  getColumns() {
    let getClassName = this.getClassName;
    let heading = ResourceTableUtil
      .renderHeading(RepositoriesTableHeaderLabels);
    let sortFunction = TableUtil.getSortFunction('uri', function (item, prop) {
      return item.get(prop);
    });

    return [
      {
        className: getClassName,
        headerClassName: getClassName,
        heading,
        prop: 'name',
        render: this.getHeadline,
        sortable: true,
        sortFunction
      },
      {
        className: getClassName,
        headerClassName: getClassName,
        heading,
        prop: 'uri',
        render: this.getUri,
        sortable: true,
        sortFunction
      },
      {
        className: getClassName,
        headerClassName: getClassName,
        heading: function () {},
        prop: 'removed',
        render: this.getRemoveButton,
        sortable: false
      }
    ];
  }

  getColGroup() {
    return (
      <colgroup>
        <col style={{width: '30%'}} />
        <col />
        <col style={{width: '85px'}} />
      </colgroup>
    );
  }

  getUri(prop, repository) {
    return (
      <div className="flex-box table-cell-flex-box">
        <span className="text-overflow-break-word" title={repository.get('uri')}>
          {repository.get('uri')}
        </span>
      </div>
    );
  }

  getHeadline(prop, repository) {
    return (
      <div className="flex-box flex-box-align-vertical-center table-cell-flex-box">
        <span className="text-overflow">
          {repository.get('name')}
        </span>
      </div>
    );
  }

  getRemoveButton(prop, repositoryToRemove) {
    return (
{'fraction_non_alphanumeric': 0.12676417757249167, 'fraction_numerical': 0.0011547344110854503, 'mean_word_length': 2.847482724580454, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 31, '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': '2124007', 'n_tokens_mistral': 2287, 'n_tokens_neox': 2250, 'n_words': 443}