<commit_before>import { NAME_ACTIONS } from '../../actions/Entities';
import { WIZARD_ACTIONS } from '../../actions/WizardActions';

const initialState = () => ({
  editing: undefined,
  isAscending: true,
  searchParameters: {
    firstName: '', // string
    lastName: '', // string
    dateOfBirth: undefined, // Date
  },
  sortKey: 'firstName',
});

export const NameReducer = (state = initialState(), action) => {
  const { type } = action;

  switch (type) {
    case WIZARD_ACTIONS.SWITCH_TAB: {
      const { payload } = action;
      const { tab } = payload;

      if (tab === 0) return initialState();

      return state;
    }

    case NAME_ACTIONS.RESET:
    case 'Navigation/BACK': {
      // reset if heading back
      return initialState();
    }

    case NAME_ACTIONS.CREATE: {
      const { payload } = action;
      const { name } = payload;

      return { ...state, editing: name };
    }

    case NAME_ACTIONS.SELECT: {
      const { payload } = action;
      const { name } = payload;

      return { ...state, editing: name.toJSON() };
    }

    case NAME_ACTIONS.UPDATE: {
      const { editing: oldName } = state;
      const { payload } = action;
      const { field, value } = payload;

      const newName = { ...oldName, [field]: value };

      return { ...state, editing: newName };
    }

    case NAME_ACTIONS.FILTER: {
      const { searchParameters: oldParameters } = state;
      const { payload } = action;
      const { key, value } = payload;
      const searchParameters = { ...oldParameters, [key]: value };

      return { ...state, searchParameters };
    }

    case NAME_ACTIONS.SORT: {
      const { payload } = action;
      const { sortKey } = payload;

      return { ...state, sortKey };
    }
    default: {
      return state;
    }<commit_msg>Add accounting for plain objects being passed to be editted in NameReducer<commit_after>import { NAME_ACTIONS } from '../../actions/Entities';
import { WIZARD_ACTIONS } from '../../actions/WizardActions';

const initialState = () => ({
  editing: undefined,
  isAscending: true,
  searchParameters: {
    firstName: '', // string
    lastName: '', // string
    dateOfBirth: undefined, // Date
  },
  sortKey: 'firstName',
});

export const NameReducer = (state = initialState(), action) => {
  const { type } = action;

  switch (type) {
    case WIZARD_ACTIONS.SWITCH_TAB: {
      const { payload } = action;
      const { tab } = payload;

      if (tab === 0) return initialState();

      return state;
    }

    case NAME_ACTIONS.RESET:
    case 'Navigation/BACK': {
      // reset if heading back
      return initialState();
    }

    case NAME_ACTIONS.CREATE: {
      const { payload } = action;
      const { name } = payload;

      return { ...state, editing: name };
    }

    case NAME_ACTIONS.SELECT: {
      const { payload } = action;
      const { name } = payload;

      // A name can be either a realm object, or a plain object if looked up through the
      // patient API.
      const asPlainObject = name.toJSON ? name.toJSON() : name;

      return { ...state, editing: asPlainObject };
    }

    case NAME_ACTIONS.UPDATE: {
      const { editing: oldName } = state;
      const { payload } = action;
      const { field, value } = payload;

      const newName = { ...oldName, [field]: value };

      return { ...state, editing: newName };
    }

    case NAME_ACTIONS.FILTER: {
      const { searchParameters: oldParameters } = state;
      const { payload } = action;
      const { key, value } = payload;
      const searchParameters = { ...oldParameters, [key]: value };

      return { ...state, searchParameters };
    }

    case NAME_ACTIONS.SORT: {
      const { payload } = action;
      const { sortKey } = payload;

      return { ...state, sortKey };
    }
    default: {
      return state;
    }
{'fraction_non_alphanumeric': 0.13550065019505853, 'fraction_numerical': 0.0005201560468140442, 'mean_word_length': 2.248310810810811, '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': '7232285', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1120, 'n_words': 317}