<commit_before>import {fromJS} from "immutable";
import {ADD_ENTITY} from "../action-types";

const initialState = fromJS({
  entities: {
    people: {},
    organisations: {},
    "government-offices": {},
  },
});

export const dataReducer = (state = initialState, action) => {
  let {type, entityType, id, data} = action;

  switch (type) {
    case ADD_ENTITY:
      if (!state.has(entityType)) {
        console.error(`Received ADD_ENTITY action with invalid entity type ${entityType}`);
        return state;
      }
      return state.mergeDeep({
        [entityType]: {
          [id]: data
        },
      });
    default:
      return state;

  }
}
<commit_msg>ui: fix bugs in dataReducer<commit_after>import {fromJS} from "immutable";
import {ADD_ENTITY} from "../action-types";

const initialState = fromJS({
  entities: {
    people: {},
    organisations: {},
    "government-offices": {},
  },
});

export const dataReducer = (state = initialState, action) => {
  let {type, entityType, id, data} = action;

  switch (type) {
    case ADD_ENTITY:
      if (!state.get("entities").has(entityType)) {
        console.error(`Received ADD_ENTITY action with invalid entity type ${entityType}`);
        return state;
      }
      return state.mergeDeep({
        entities: {
          [entityType]: {
            [id]: data
          },
        },
      });

    default:
      return state;
  }
}

{'fraction_non_alphanumeric': 0.14599574769666904, 'fraction_numerical': 0.0, 'mean_word_length': 2.521197007481297, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, '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': '1556061', 'n_tokens_mistral': 433, 'n_tokens_neox': 433, 'n_words': 107}