<commit_before>import * as Action from '../actionTypes';

import _ from 'lodash';

const DEFAULT_MODELS = {
  users: {},
  user: {},

  favourites: {
    data: {},
    loading: false,
    success: false,
  },

  equipmentList: {
    data: {}, 
    loading: false,
    success: false,
  },
  equipment: {},
  equipmentPhysicalAttachments: {},
  equipmentSeniorityHistory: {},
  equipmentNotes: {},
  equipmentAttachments: {},
  equipmentHistory: {},

  owners: {
    data: {},
    loading: false,
  },
  owner: {},
  ownerNotes: {},
  ownerAttachments: {},
  ownerHistory: {},

  projects: {
    data: {},
    loading: false, 
    success: false,
  },
  project: {},
  projectNotes: {},
  projectAttachments: {},
  projectHistory: {},

  rentalRequests: {
    data: {},
    loading: false,
    success: false,
  },
  rentalRequest: {},
  rentalRequestNotes: {},
  rentalRequestAttachments: {},
  rentalRequestHistory: {},
  rentalRequestRotationList: {},

  rentalAgreement: {},
  rentalAgreementNotes: {},
  rentalAgreementHistory: {},
  rentalRate: {},
  rentalCondition: {},

  roles: {},
  role: {},
  rolePermissions: {},

  contacts: {},
  contact: {},

  documents: {},
  document: {},

  history: {},
};

export default function modelsReducer(state = DEFAULT_MODELS, action) {
  switch(action.type) {
    // Users
    case Action.UPDATE_USERS:
      return { ...state, users: action.users };

    case Action.UPDATE_USER:
      return { ...state, user: action.user };

    case Action.ADD_USER:
      return { ...state, user: action.user };

    case Action.DELETE_USER:
      return { ...state, user: action.user };

    // Favourites
    case Action.FAVOURITES_REQUEST:
      return { ...state, favourites: { ...state.favourites, loading: true } };

    case Action.UPDATE_FAVOURITES:
      return { ...state, favourites: { data: action.favourites, loading: false, success: true } };

    case Action.ADD_FAVOURITE: case Action.UPDATE_FAVOURITE:
      return { ...state, favourites: { ...state.favourites, ...action.favourite } };

    case Action.DELETE_FAVOURITE:
      return { ...state, favourites: _.omit(state.favourites, [ action.id ]) };

    // Contacts
    case Action.UPDATE_CONTACTS:
      return { ...state, contacts: action.contacts };

    case Action.ADD_CONTACT:
      return { ...state, contact: action.contact };

    case Action.UPDATE_CONTACT:
      return { ...state, contact: action.contact };

    case Action.DELETE_CONTACT:
      return { ...state, contact: action.contact };

    // Documents
    case Action.UPDATE_DOCUMENTS:
      return { ...state, documents: action.documents };

    case Action.ADD_DOCUMENT:
      return { ...state, document: action.document };

    case Action.UPDATE_DOCUMENT:
      return { ...state, document: action.document };

    case Action.DELETE_DOCUMENT:
      return { ...state, document: action.document };<commit_msg>HETS-420. Updated add and update favourites reducer<commit_after>import * as Action from '../actionTypes';

import _ from 'lodash';

const DEFAULT_MODELS = {
  users: {},
  user: {},

  favourites: {
    data: {},
    loading: false,
    success: false,
  },

  equipmentList: {
    data: {}, 
    loading: false,
    success: false,
  },
  equipment: {},
  equipmentPhysicalAttachments: {},
  equipmentSeniorityHistory: {},
  equipmentNotes: {},
  equipmentAttachments: {},
  equipmentHistory: {},

  owners: {
    data: {},
    loading: false,
  },
  owner: {},
  ownerNotes: {},
  ownerAttachments: {},
  ownerHistory: {},

  projects: {
    data: {},
    loading: false, 
    success: false,
  },
  project: {},
  projectNotes: {},
  projectAttachments: {},
  projectHistory: {},

  rentalRequests: {
    data: {},
    loading: false,
    success: false,
  },
  rentalRequest: {},
  rentalRequestNotes: {},
  rentalRequestAttachments: {},
  rentalRequestHistory: {},
  rentalRequestRotationList: {},

  rentalAgreement: {},
  rentalAgreementNotes: {},
  rentalAgreementHistory: {},
  rentalRate: {},
  rentalCondition: {},

  roles: {},
  role: {},
  rolePermissions: {},

  contacts: {},
  contact: {},

  documents: {},
  document: {},

  history: {},
};

export default function modelsReducer(state = DEFAULT_MODELS, action) {
  switch(action.type) {
    // Users
    case Action.UPDATE_USERS:
      return { ...state, users: action.users };

    case Action.UPDATE_USER:
      return { ...state, user: action.user };

    case Action.ADD_USER:
      return { ...state, user: action.user };

    case Action.DELETE_USER:
      return { ...state, user: action.user };

    // Favourites
    case Action.FAVOURITES_REQUEST:
      return { ...state, favourites: { ...state.favourites, loading: true } };

    case Action.UPDATE_FAVOURITES:
      return { ...state, favourites: { data: action.favourites, loading: false, success: true } };

    case Action.ADD_FAVOURITE: case Action.UPDATE_FAVOURITE:
      return { ...state, favourites: { data: { ...state.favourites.data, ...action.favourite } } };

    case Action.DELETE_FAVOURITE:
      return { ...state, favourites: _.omit(state.favourites, [ action.id ]) };

    // Contacts
    case Action.UPDATE_CONTACTS:
      return { ...state, contacts: action.contacts };

    case Action.ADD_CONTACT:
      return { ...state, contact: action.contact };

    case Action.UPDATE_CONTACT:
      return { ...state, contact: action.contact };

    case Action.DELETE_CONTACT:
      return { ...state, contact: action.contact };

    // Documents
    case Action.UPDATE_DOCUMENTS:
      return { ...state, documents: action.documents };

    case Action.ADD_DOCUMENT:
      return { ...state, document: action.document };

    case Action.UPDATE_DOCUMENT:
      return { ...state, document: action.document };

    case Action.DELETE_DOCUMENT:
      return { ...state, document: action.document };
{'fraction_non_alphanumeric': 0.15081405312767782, 'fraction_numerical': 0.0005141388174807198, 'mean_word_length': 2.8725945587259454, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2340582', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1792, 'n_words': 387}