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

import _ from 'lodash';

const DEFAULT_MODELS = {
  users: {
    data: {},
    loading: false,
    loaded: false,
  },
  user: {},
  userDistricts: {
    data: {},
    loading: false,
  },
  currentUserDistricts: {
    data: {},
    loading: false,
  },

  favourites: {
    equipment: {},
    hiringReport: {},
    owner: {},
    ownersCoverage: {},
    project: {},
    rentalRequests: {},
    timeEntry: {},
    user: {},
  },

  equipmentList: {
    data: {},
    loading: false,
    loaded: false,
  },
  equipment: {},
  equipmentSeniorityHistory: {},
  equipmentNotes: {},
  equipmentAttachments: {},
  equipmentHistory: {},
  equipmentRentalAgreements: {
    data: {},
  },
  equipmentTransfer: {},

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

  projects: {
    data: {},
    loading: false,
    loaded: false,
  },
  project: {},
  projectEquipment: {
    data: {},
    loading: false,
    success: false,
  },
  projectTimeRecords: {
    data: {},
    loading: false,
    success: false,
  },
  projectNotes: {},
  projectAttachments: {},
  projectHistory: {},
  projectRentalAgreements: {
    data: {},
  },

  rentalRequests: {
    data: {},
    loading: false,
    loaded: false,
  },
  rentalRequest: {
    data: {},
    loading: false,
    success: false,
    error: false,
    errorMessage: '',
  },
  rentalRequestNotes: {},
  rentalRequestAttachments: {},
  rentalRequestHistory: {},
  rentalRequestRotationList: {
    data: {},
    loading: false,
    success: false,
  },

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

  timeEntries: {
    data: {},
    loading: false,
    loaded: false,
  },

  hiringResponses: {
    data: {},
    loading: false,
    loaded: false,
  },

  ownersCoverage: {
    data: {},
    loading: false,
    loaded: false,
  },

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

  contacts: {},
  contact: {},

  documents: {},
  document: {},

  history: {},

  timeRecord: {
    data: {},
  },

  business: {},
};

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

    case Action.UPDATE_USERS:
      return { ...state, users: { data: action.users, loading: false, loaded: true } };

    case Action.CLEAR_USERS:
      return { ...state, users: { data: {}, loading: false, loaded: false } };

    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 };

    case Action.USER_DISTRICTS:
      return { ...state, userDistricts: { data: action.userDistricts, loading: false } };

    case Action.CURRENT_USER_DISTRICTS:
      return { ...state, currentUserDistricts: { data: action.currentUserDistricts, loading: false } };

    // Favourites
    case Action.UPDATE_FAVOURITES:
      return { ...state, favourites: {...state.favourites, ...action.favourites } };

    case Action.ADD_FAVOURITE: case Action.UPDATE_FAVOURITE:
      return { ...state, favourites: { ...state.favourites, ...{ [action.favourite.type]: { ...state.favourites[action.favourite.type], [action.favourite.id]: action.favourite } } } };

    case Action.DELETE_FAVOURITE:
      return { ...state, favourites: { ...state.favourites, ...{ [action.favourite.type]: _.omit(state.favourites[action.favourite.type], [ action.favourite.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<commit_msg>HETS-1060 clean up reducer for favourites<commit_after>import * as Action from '../actionTypes';

import _ from 'lodash';

const DEFAULT_MODELS = {
  users: {
    data: {},
    loading: false,
    loaded: false,
  },
  user: {},
  userDistricts: {
    data: {},
    loading: false,
  },
  currentUserDistricts: {
    data: {},
    loading: false,
  },

  favourites: {
    equipment: {},
    hiringReport: {},
    owner: {},
    ownersCoverage: {},
    project: {},
    rentalRequests: {},
    timeEntry: {},
    user: {},
  },

  equipmentList: {
    data: {},
    loading: false,
    loaded: false,
  },
  equipment: {},
  equipmentSeniorityHistory: {},
  equipmentNotes: {},
  equipmentAttachments: {},
  equipmentHistory: {},
  equipmentRentalAgreements: {
    data: {},
  },
  equipmentTransfer: {},

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

  projects: {
    data: {},
    loading: false,
    loaded: false,
  },
  project: {},
  projectEquipment: {
    data: {},
    loading: false,
    success: false,
  },
  projectTimeRecords: {
    data: {},
    loading: false,
    success: false,
  },
  projectNotes: {},
  projectAttachments: {},
  projectHistory: {},
  projectRentalAgreements: {
    data: {},
  },

  rentalRequests: {
    data: {},
    loading: false,
    loaded: false,
  },
  rentalRequest: {
    data: {},
    loading: false,
    success: false,
    error: false,
    errorMessage: '',
  },
  rentalRequestNotes: {},
  rentalRequestAttachments: {},
  rentalRequestHistory: {},
  rentalRequestRotationList: {
    data: {},
    loading: false,
    success: false,
  },

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

  timeEntries: {
    data: {},
    loading: false,
    loaded: false,
  },

  hiringResponses: {
    data: {},
    loading: false,
    loaded: false,
  },

  ownersCoverage: {
    data: {},
    loading: false,
    loaded: false,
  },

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

  contacts: {},
  contact: {},

  documents: {},
  document: {},

  history: {},

  timeRecord: {
    data: {},
  },

  business: {},
};

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

    case Action.UPDATE_USERS:
      return { ...state, users: { data: action.users, loading: false, loaded: true } };

    case Action.CLEAR_USERS:
      return { ...state, users: { data: {}, loading: false, loaded: false } };

    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 };

    case Action.USER_DISTRICTS:
      return { ...state, userDistricts: { data: action.userDistricts, loading: false } };

    case Action.CURRENT_USER_DISTRICTS:
      return { ...state, currentUserDistricts: { data: action.currentUserDistricts, loading: false } };

    // Favourites
    case Action.UPDATE_FAVOURITES:
      return { ...state, favourites: { ...state.favourites, ...action.favourites } };

    case Action.ADD_FAVOURITE: case Action.UPDATE_FAVOURITE:
      return { ...state, favourites: { ...state.favourites, [action.favourite.type]: { ...state.favourites[action.favourite.type], [action.favourite.id]: action.favourite } } };

    case Action.DELETE_FAVOURITE:
      return { ...state, favourites: { ...state.favourites, [action.favourite.type]: _.omit(state.favourites[action.favourite.type], [ action.favourite.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
{'fraction_non_alphanumeric': 0.15969099504208464, 'fraction_numerical': 0.00046120142972443215, 'mean_word_length': 2.7291487532244196, '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': '1533625', 'n_tokens_mistral': 2876, 'n_tokens_neox': 2791, 'n_words': 572}