<commit_before>import PropTypes from 'prop-types';
import React from 'react';
import { injectIntl, FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { formValueSelector } from 'redux-form';
import { Grid, Row } from 'react-flexbox-grid/lib';
import withAsyncFetch from '../hocs/AsyncContainer';
import withPaging from '../hocs/PagedContainer';
import { fetchSystemUsers, deleteSystemUser } from '../../../actions/systemActions';
import { notEmptyString } from '../../../lib/formValidators';
import UserTable from '../UserTable';
import UserSearchForm from './form/UserSearchForm';


const formSelector = formValueSelector('userSearchForm');

const localMessages = {
  userTitle: { id: 'user.all.title', defaultMessage: 'Users' },
};

const ManageUsersContainer = props => (
  <Grid>
    <h1>
      <FormattedMessage {...localMessages.userTitle} />
    </h1>
    <Row><UserSearchForm onSearch={searchStr => props.fetchData(searchStr)} /></Row>
    <br /><br />
    <Row>
      <UserTable users={props.users} onDeleteUser={userId => props.handleDeleteUser(userId)} />
      <Row>{props.previousButton}{props.nextButton}</Row>
    </Row>
  </Grid>
);

ManageUsersContainer.propTypes = {
  // from Hoc
  intl: PropTypes.object.isRequired,
  previousButton: PropTypes.node,
  nextButton: PropTypes.node,
  // from state
  fetchStatus: PropTypes.string,
  users: PropTypes.array,
  fetchData: PropTypes.func.isRequired,
  handleDeleteUser: PropTypes.func.isRequired,
};

const mapStateToProps = state => ({
  fetchStatus: state.system.users.allUsers.fetchStatus,
  users: state.system.users.allUsers.users,
  links: state.system.users.allUsers.link_ids,
  searchStr: formSelector(state, 'searchStr'),
});

const mapDispatchToProps = (dispatch, ownProps) => ({
  fetchData: (searchStr) => {
    if (notEmptyString(Object.values(searchStr)[0])) {
      return dispatch(fetchSystemUsers(searchStr));
    }
    return dispatch(fetchSystemUsers());
  },
  asyncFetch: () => {
    if (ownProps.location.query !== undefined) {
      return dispatch(fetchSystemUsers(ownProps.location.query));
    }
    return dispatch(fetchSystemUsers());
  },
  fetchPagedData: (props, linkId) => {
    if (notEmptyString(ownProps.params.searchStr)) {
      return dispatch(fetchSystemUsers({ searchStr: ownProps.params.searchStr, linkId }));
    }
    return dispatch(fetchSystemUsers({ linkId }));
  },
  handleDeleteUser: userId => dispatch(deleteSystemUser(userId)),<commit_msg>#1407 feedback on delete<commit_after>import PropTypes from 'prop-types';
import React from 'react';
import { injectIntl, FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { formValueSelector } from 'redux-form';
import { Grid, Row } from 'react-flexbox-grid/lib';
import withAsyncFetch from '../hocs/AsyncContainer';
import withPaging from '../hocs/PagedContainer';
import { fetchSystemUsers, deleteSystemUser } from '../../../actions/systemActions';
import { notEmptyString } from '../../../lib/formValidators';
import { updateFeedback } from '../../../actions/appActions';
import UserTable from '../UserTable';
import UserSearchForm from './form/UserSearchForm';


const formSelector = formValueSelector('userSearchForm');

const localMessages = {
  userTitle: { id: 'user.all.title', defaultMessage: 'Users' },
  feedback: { id: 'user.all.user.delete.feedback', defaultMessage: 'Successfully deleted user.' },
};

const ManageUsersContainer = props => (
  <Grid>
    <h1>
      <FormattedMessage {...localMessages.userTitle} />
    </h1>
    <Row><UserSearchForm onSearch={searchStr => props.fetchData(searchStr)} /></Row>
    <br /><br />
    <Row>
      <UserTable users={props.users} onDeleteUser={userId => props.handleDeleteUser(userId)} />
      <Row>{props.previousButton}{props.nextButton}</Row>
    </Row>
  </Grid>
);

ManageUsersContainer.propTypes = {
  // from Hoc
  intl: PropTypes.object.isRequired,
  previousButton: PropTypes.node,
  nextButton: PropTypes.node,
  // from state
  fetchStatus: PropTypes.string,
  users: PropTypes.array,
  fetchData: PropTypes.func.isRequired,
  handleDeleteUser: PropTypes.func.isRequired,
};

const mapStateToProps = state => ({
  fetchStatus: state.system.users.allUsers.fetchStatus,
  users: state.system.users.allUsers.users,
  links: state.system.users.allUsers.link_ids,
  searchStr: formSelector(state, 'searchStr'),
});

const mapDispatchToProps = (dispatch, ownProps) => ({
  fetchData: (searchStr) => {
    if (notEmptyString(Object.values(searchStr)[0])) {
      return dispatch(fetchSystemUsers(searchStr));
    }
    return dispatch(fetchSystemUsers());
  },
  asyncFetch: () => {
    if (ownProps.location.query !== undefined) {
      return dispatch(fetchSystemUsers(ownProps.location.query));
    }
    return dispatch(fetchSystemUsers());
  },
  fetchPagedData: (props, linkId) => {
    if (notEmptyString(ownProps.params.searchStr)) {
      return dispatch(fetchSystemUsers({ searchStr: ownProps.params.searchStr, linkId }));
    }
    return dispatch(fetchSystemUsers({ linkId }));
  },
  handleDeleteUser: (userId) => {
    dispatch(deleteSystemUser(userId))
      .then((result) => {
        if (result.success) {
          // let them know it worked
          dispatch(updateFeedback({ classes: 'info-notice', open: true, message: ownProps.intl.formatMessage(localMessages.feedback) }));
          // need to fetch it again because something may have changed
          dispatch(fetchSystemUsers());
        }
      });
  },
{'fraction_non_alphanumeric': 0.14885910901847157, 'fraction_numerical': 0.0018109380659181455, 'mean_word_length': 4.181050656660413, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 52, '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': '366878', 'n_tokens_mistral': 1630, 'n_tokens_neox': 1649, 'n_words': 339}