<commit_before>import React from 'react';
import { browserHistory } from 'react-router';
import { connect } from 'react-redux';
import {
  Table,
  TableBody,
  TableHeader,
  TableHeaderColumn,
  TableRow,
  TableRowColumn
} from 'material-ui/Table';
import { Tabs, Tab } from 'material-ui/Tabs';
import FlatButton from 'material-ui/FlatButton';
import Navbar from './reusable/Navbar.component';
import Paginate from './reusable/Paginate.component';
import CustomDrawer from './CustomDrawer.component';
import DeleteDialog from './DeleteDialog.component';
import {
  getActiveUser,
  getAllUsers,
  updateUser,
  deleteUser,
  confirmDeleteUser,
  clearConfirmDeleteUser,
  confirmPromotion,
  clearConfirmPromotion
} from '../actions/users.action';
import { getAllDocs, deleteDoc, clearConfirmDeleteDoc, confirmDeleteDoc } from '../actions/document.action';
import getUserInfo from '../util/getUserInfo';
import paginate from '../util/paginate';

@connect(store => ({
  user: store.users,
  form: store.form,
  error: store.error.error,
  auth: store.auth,
  docs: store.documents,
  folder: store.folder,
  views: store.views
}))
/**
*
* Compoent to diplay and manage users
* @class ManageUser
*/
class ManageUser extends React.Component {

  constructor(props) {
    super(props);
    this.handleChange = this.handleChange.bind(this);
    this.handleUserPageChange = this.handleUserPageChange.bind(this);
    this.handleConfirmDeleteDoc = this.handleConfirmDeleteDoc.bind(this);
    this.clearDeleteConfirmation = this.clearDeleteConfirmation.bind(this);
    this.handleDeleteDoc = this.handleDeleteDoc.bind(this);
    this.clearDeleteUserConfirmation = this.clearDeleteUserConfirmation.bind(this);
    this.handleDeleteUser = this.handleDeleteUser.bind(this);
    this.handleConfirmDeleteUser = this.handleConfirmDeleteUser.bind(this);
    this.handleDocPageChange= this.handleDocPageChange.bind(this);
    this.confirmPromotion = this.confirmPromotion.bind(this);
    this.clearConfirmPromotion = this.clearConfirmPromotion.bind(this);
    this.handlePromoteUser = this.handlePromoteUser.bind(this);
    this.state = { value: 'users', user_page: 1, doc_page: 1 };
  }

  /**
   * componentDidMount
   * @return {void}
   */
  componentDidMount() {
    if (!window.localStorage.getItem('token')) {
      browserHistory.push('/app/login');
    } else {
      this.props.dispatch(getActiveUser());
      this.props.dispatch(getAllUsers(7, 0));
      this.props.dispatch(getAllDocs(7, 0));
    }
  }

  /**
   * componentWillReceiveProps
   * @param {object} nextProps - next properties the component will recieve
   * before render
   * @return {void}
   */
  componentWillReceiveProps(nextProps) {
    if (nextProps.user.details) {
      if (nextProps.user.details.roleId
        && nextProps.user.details.roleId !== 1) {
        browserHistory.push('/app/dashboard');
      }
    }
  }

  handlePromoteUser(id) {
    this.props.dispatch(updateUser(id, { roleId: 1 }));
  }

  handleDeleteUser(id) {
    this.props.dispatch(deleteUser(id));
  }

  handleChange(value) {
    this.setState({ value });
  }

   /**
    * handleConfirmDeleteUser - send an action to confirm user delete
    * @param {Object} values - information to pass to the delete dialog
    */
   handleConfirmDeleteUser(values) {
     this.props.dispatch(confirmDeleteUser(values));
   }

   /**<commit_msg>feature(paginate-table): fix redirect issuses on manage page[144919429]<commit_after>import React from 'react';
import { browserHistory } from 'react-router';
import { connect } from 'react-redux';
import {
  Table,
  TableBody,
  TableHeader,
  TableHeaderColumn,
  TableRow,
  TableRowColumn
} from 'material-ui/Table';
import { Tabs, Tab } from 'material-ui/Tabs';
import FlatButton from 'material-ui/FlatButton';
import Navbar from './reusable/Navbar.component';
import Paginate from './reusable/Paginate.component';
import CustomDrawer from './CustomDrawer.component';
import DeleteDialog from './DeleteDialog.component';
import {
  getActiveUser,
  getAllUsers,
  updateUser,
  deleteUser,
  confirmDeleteUser,
  clearConfirmDeleteUser,
  confirmPromotion,
  clearConfirmPromotion
} from '../actions/users.action';
import { getAllDocs, deleteDoc, clearConfirmDeleteDoc, confirmDeleteDoc } from '../actions/document.action';
import getUserInfo from '../util/getUserInfo';
import paginate from '../util/paginate';

@connect(store => ({
  user: store.users,
  form: store.form,
  error: store.error.error,
  auth: store.auth,
  docs: store.documents,
  folder: store.folder,
  views: store.views
}))
/**
*
* Compoent to diplay and manage users
* @class ManageUser
*/
class ManageUser extends React.Component {

  constructor(props) {
    super(props);
    this.handleChange = this.handleChange.bind(this);
    this.handleUserPageChange = this.handleUserPageChange.bind(this);
    this.handleConfirmDeleteDoc = this.handleConfirmDeleteDoc.bind(this);
    this.clearDeleteConfirmation = this.clearDeleteConfirmation.bind(this);
    this.handleDeleteDoc = this.handleDeleteDoc.bind(this);
    this.clearDeleteUserConfirmation = this.clearDeleteUserConfirmation.bind(this);
    this.handleDeleteUser = this.handleDeleteUser.bind(this);
    this.handleConfirmDeleteUser = this.handleConfirmDeleteUser.bind(this);
    this.handleDocPageChange= this.handleDocPageChange.bind(this);
    this.confirmPromotion = this.confirmPromotion.bind(this);
    this.clearConfirmPromotion = this.clearConfirmPromotion.bind(this);
    this.handlePromoteUser = this.handlePromoteUser.bind(this);
    this.state = { value: 'users', user_page: 1, doc_page: 1 };
  }

  /**
   * componentDidMount
   * @return {void}
   */
  componentDidMount() {
    if (!window.localStorage.getItem('token')) {
      browserHistory.push('/app/login');
    } else {
      this.props.dispatch(getActiveUser());
      this.props.dispatch(getAllUsers(7, 0));
      this.props.dispatch(getAllDocs(7, 0));
    }
  }

  /**
   * componentWillReceiveProps
   * @param {object} nextProps - next properties the component will recieve
   * before render
   * @return {void}
   */
  componentWillReceiveProps(nextProps) {
    if (nextProps.user.details) {
      if (nextProps.user.details.roleId
        && nextProps.user.details['Role.title'] !== 'admin') {
        browserHistory.push('/app/dashboard');
      }
    }
  }

  handlePromoteUser(id) {
    this.props.dispatch(updateUser(id, { roleId: 1 }));
  }

  handleDeleteUser(id) {
    this.props.dispatch(deleteUser(id));
  }

  handleChange(value) {
    this.setState({ value });
  }

   /**
    * handleConfirmDeleteUser - send an action to confirm user delete
    * @param {Object} values - information to pass to the delete dialog
    */
   handleConfirmDeleteUser(values) {
     this.props.dispatch(confirmDeleteUser(values));
   }

   /**
{'fraction_non_alphanumeric': 0.12651925611363304, 'fraction_numerical': 0.003514423780934251, 'mean_word_length': 4.036873156342183, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '520180', 'n_tokens_mistral': 2104, 'n_tokens_neox': 2065, 'n_words': 398}