<commit_before>import React from 'react';
import classNames from 'classnames';
import BootstrapMixin from './BootstrapMixin';
import PaginationButton from './PaginationButton';

const Pagination = React.createClass({
  mixins: [BootstrapMixin],

  propTypes: {
    activePage: React.PropTypes.number,
    items: React.PropTypes.number,
    maxButtons: React.PropTypes.number,
    ellipsis: React.PropTypes.bool,
    first: React.PropTypes.bool,
    last: React.PropTypes.bool,
    prev: React.PropTypes.bool,
    next: React.PropTypes.bool,
    onSelect: React.PropTypes.func
  },

  getDefaultProps() {
    return {
      activePage: 1,
      items: 1,
      maxButtons: 0,
      first: false,
      last: false,
      prev: false,
      next: false,
      ellipsis: true,
      bsClass: 'pagination'
    };
  },

  renderPageButtons() {
    let pageButtons = [];
    let startPage, endPage, hasHiddenPagesAfter;
    let {
      maxButtons,
      activePage,
      items,
      onSelect,
      ellipsis
    } = this.props;

    if(maxButtons){
      let hiddenPagesBefore = activePage - parseInt(maxButtons / 2);
      startPage = hiddenPagesBefore > 1 ? hiddenPagesBefore : 1;
      hasHiddenPagesAfter = startPage + maxButtons <= items;

      if(!hasHiddenPagesAfter){
        endPage = items;
        startPage = items - maxButtons + 1;
        if(startPage < 1){
          startPage = 1;
        }
      } else {
        endPage = startPage + maxButtons - 1;
      }
    } else {
      startPage = 1;
      endPage = items;
    }

    for(let pagenumber = startPage; pagenumber <= endPage; pagenumber++){
      pageButtons.push(
        <PaginationButton
          key={pagenumber}
          eventKey={pagenumber}
          active={pagenumber === activePage}
          onSelect={onSelect}>
          {pagenumber}
        </PaginationButton>
      );
    }

    if(maxButtons && hasHiddenPagesAfter && ellipsis){
      pageButtons.push(
        <PaginationButton
          key='ellipsis'
          disabled>
          <span aria-label='More'>...</span>
        </PaginationButton>
      );
    }

    return pageButtons;
  },

  renderPrev() {
    if(!this.props.prev){
      return null;
    }

    return (
      <PaginationButton
        key='prev'
        eventKey={this.props.activePage - 1}
        disabled={this.props.activePage === 1}
        onSelect={this.props.onSelect}>
        <span aria-label='Previous'>&lsaquo;</span>
      </PaginationButton>
    );
  },

  renderNext() {
    if(!this.props.next){
      return null;
    }

    return (
      <PaginationButton
        key='next'
        eventKey={this.props.activePage + 1}
        disabled={this.props.activePage === this.props.items}
        onSelect={this.props.onSelect}>
        <span aria-label='Next'>&rsaquo;</span>
      </PaginationButton>
    );
  },

  renderFirst() {
    if(!this.props.first){
      return null;
    }

    return (
      <PaginationButton
        key='first'
        eventKey={1}
        disabled={this.props.activePage === 1 }
        onSelect={this.props.onSelect}>
        <span aria-label='First'>&laquo;</span>
      </PaginationButton>
    );
  },

  renderLast() {
    if(!this.props.last){
      return null;
    }

    return (
      <PaginationButton
        key='last'
        eventKey={this.props.items}
        disabled={this.props.activePage === this.props.items}
        onSelect={this.props.onSelect}>
        <span aria-label='Last'>&raquo;</span>
      </PaginationButton>
    );
  },

  render() {
    return (
      <ul
        {...this.props}
        className={classNames(this.props.className, this.getBsClassSet())}>
        {this.renderFirst()}
        {this.renderPrev()}
        {this.renderPageButtons()}
        {this.renderNext()}
        {this.renderLast()}
      </ul>
    );
  }
});

export default Pagination;<commit_msg>[fixed] Active Next and Last button in Pagination when ellipsis=true and items=0<commit_after>import React from 'react';
import classNames from 'classnames';
import BootstrapMixin from './BootstrapMixin';
import PaginationButton from './PaginationButton';

const Pagination = React.createClass({
  mixins: [BootstrapMixin],

  propTypes: {
    activePage: React.PropTypes.number,
    items: React.PropTypes.number,
    maxButtons: React.PropTypes.number,
    ellipsis: React.PropTypes.bool,
    first: React.PropTypes.bool,
    last: React.PropTypes.bool,
    prev: React.PropTypes.bool,
    next: React.PropTypes.bool,
    onSelect: React.PropTypes.func
  },

  getDefaultProps() {
    return {
      activePage: 1,
      items: 1,
      maxButtons: 0,
      first: false,
      last: false,
      prev: false,
      next: false,
      ellipsis: true,
      bsClass: 'pagination'
    };
  },

  renderPageButtons() {
    let pageButtons = [];
    let startPage, endPage, hasHiddenPagesAfter;
    let {
      maxButtons,
      activePage,
      items,
      onSelect,
      ellipsis
    } = this.props;

    if(maxButtons){
      let hiddenPagesBefore = activePage - parseInt(maxButtons / 2);
      startPage = hiddenPagesBefore > 1 ? hiddenPagesBefore : 1;
      hasHiddenPagesAfter = startPage + maxButtons <= items;

      if(!hasHiddenPagesAfter){
        endPage = items;
        startPage = items - maxButtons + 1;
        if(startPage < 1){
          startPage = 1;
        }
      } else {
        endPage = startPage + maxButtons - 1;
      }
    } else {
      startPage = 1;
      endPage = items;
    }

    for(let pagenumber = startPage; pagenumber <= endPage; pagenumber++){
      pageButtons.push(
        <PaginationButton
          key={pagenumber}
          eventKey={pagenumber}
          active={pagenumber === activePage}
          onSelect={onSelect}>
          {pagenumber}
        </PaginationButton>
      );
    }

    if(maxButtons && hasHiddenPagesAfter && ellipsis){
      pageButtons.push(
        <PaginationButton
          key='ellipsis'
          disabled>
          <span aria-label='More'>...</span>
        </PaginationButton>
      );
    }

    return pageButtons;
  },

  renderPrev() {
    if(!this.props.prev){
      return null;
    }

    return (
      <PaginationButton
        key='prev'
        eventKey={this.props.activePage - 1}
        disabled={this.props.activePage === 1}
        onSelect={this.props.onSelect}>
        <span aria-label='Previous'>&lsaquo;</span>
      </PaginationButton>
    );
  },

  renderNext() {
    if(!this.props.next){
      return null;
    }

    return (
      <PaginationButton
        key='next'
        eventKey={this.props.activePage + 1}
        disabled={this.props.activePage >= this.props.items}
        onSelect={this.props.onSelect}>
        <span aria-label='Next'>&rsaquo;</span>
      </PaginationButton>
    );
  },

  renderFirst() {
    if(!this.props.first){
      return null;
    }

    return (
      <PaginationButton
        key='first'
        eventKey={1}
        disabled={this.props.activePage === 1 }
        onSelect={this.props.onSelect}>
        <span aria-label='First'>&laquo;</span>
      </PaginationButton>
    );
  },

  renderLast() {
    if(!this.props.last){
      return null;
    }

    return (
      <PaginationButton
        key='last'
        eventKey={this.props.items}
        disabled={this.props.activePage >= this.props.items}
        onSelect={this.props.onSelect}>
        <span aria-label='Last'>&raquo;</span>
      </PaginationButton>
    );
  },

  render() {
    return (
      <ul
        {...this.props}
        className={classNames(this.props.className, this.getBsClassSet())}>
        {this.renderFirst()}
        {this.renderPrev()}
        {this.renderPageButtons()}
        {this.renderNext()}
        {this.renderLast()}
      </ul>
    );
  }
});

export default Pagination;
{'fraction_non_alphanumeric': 0.1306971369880601, 'fraction_numerical': 0.004236744126332007, 'mean_word_length': 2.1666666666666665, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 55, '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': '6672835', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2432, 'n_words': 430}