<commit_before>import set from 'lodash/fp/set';

import { makeField } from '../../common/model/fields';

import {
  ADD_COMPOSE_ATTACHMENTS,
  DELETE_COMPOSE_ATTACHMENT,
  DELETE_COMPOSE_MESSAGE,
  FETCH_RECIPIENTS_SUCCESS,
  FETCH_RECIPIENTS_FAILURE,
  RESET_MESSAGE_OBJECT,
  SET_MESSAGE_FIELD,
} from '../utils/constants';

const initialState = {
  message: {
    attachments: [],
    body: makeField(''),
    category: makeField(''),
    recipient: makeField(''),
    subject: makeField('')
  },
  // List of potential recipients
  recipients: []
};

/*
* Take the recipients object returned during the fetch operation
* and one return {label, value} object for each object in the
* action.recipients.data array.
* That's all we need.
*/
function getRecipients(recipients) {
  return recipients.map((item) => {
    return {
      label: item.attributes.name,
      value: item.attributes.triageTeamId
    };
  });
}

const resetMessage = (state) => {
  let msg = set('message.category', initialState.message.category, state);
  msg = set('message.recipient', initialState.message.recipient, msg);
  msg = set('message.subject', initialState.message.subject, msg);
  msg = set('message.attachments', initialState.message.attachments, msg);
  msg = set('message.body', initialState.message.body, msg);
  return msg;
};

export default function compose(state = initialState, action) {
  switch (action.type) {
    case ADD_COMPOSE_ATTACHMENTS:
      return set('message.attachments', [
        ...state.message.attachments,
        ...action.files
      ], state);
    case DELETE_COMPOSE_ATTACHMENT:
      // Remove the attachment at the requested index.
      state.message.attachments.splice(action.index, 1);
      return set('message.attachments', state.message.attachments, state);
    case DELETE_COMPOSE_MESSAGE:
      return initialState;
    case FETCH_RECIPIENTS_SUCCESS:
      return set('recipients', getRecipients(action.recipients.data), state);
    case RESET_MESSAGE_OBJECT:
      return resetMessage(state);
    case SET_MESSAGE_FIELD:
      return set(action.path, action.field, state);
    case FETCH_RECIPIENTS_FAILURE:
    default:
      return state;
  }
}<commit_msg>Removed failure case for fetching recipients from compose reducer.<commit_after>import set from 'lodash/fp/set';

import { makeField } from '../../common/model/fields';

import {
  ADD_COMPOSE_ATTACHMENTS,
  DELETE_COMPOSE_ATTACHMENT,
  DELETE_COMPOSE_MESSAGE,
  FETCH_RECIPIENTS_SUCCESS,
  RESET_MESSAGE_OBJECT,
  SET_MESSAGE_FIELD,
} from '../utils/constants';

const initialState = {
  message: {
    attachments: [],
    body: makeField(''),
    category: makeField(''),
    recipient: makeField(''),
    subject: makeField('')
  },
  // List of potential recipients
  recipients: []
};

/*
* Take the recipients object returned during the fetch operation
* and one return {label, value} object for each object in the
* action.recipients.data array.
* That's all we need.
*/
function getRecipients(recipients) {
  return recipients.map((item) => {
    return {
      label: item.attributes.name,
      value: item.attributes.triageTeamId
    };
  });
}

const resetMessage = (state) => {
  let msg = set('message.category', initialState.message.category, state);
  msg = set('message.recipient', initialState.message.recipient, msg);
  msg = set('message.subject', initialState.message.subject, msg);
  msg = set('message.attachments', initialState.message.attachments, msg);
  msg = set('message.body', initialState.message.body, msg);
  return msg;
};

export default function compose(state = initialState, action) {
  switch (action.type) {
    case ADD_COMPOSE_ATTACHMENTS:
      return set('message.attachments', [
        ...state.message.attachments,
        ...action.files
      ], state);
    case DELETE_COMPOSE_ATTACHMENT:
      // Remove the attachment at the requested index.
      state.message.attachments.splice(action.index, 1);
      return set('message.attachments', state.message.attachments, state);
    case DELETE_COMPOSE_MESSAGE:
      return initialState;
    case FETCH_RECIPIENTS_SUCCESS:
      return set('recipients', getRecipients(action.recipients.data), state);
    case RESET_MESSAGE_OBJECT:
      return resetMessage(state);
    case SET_MESSAGE_FIELD:
      return set(action.path, action.field, state);
    default:
      return state;
  }
}
{'fraction_non_alphanumeric': 0.12048468221307727, 'fraction_numerical': 0.0004572473708276177, 'mean_word_length': 3.8024149286498354, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '5814607', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1310, 'n_words': 307}