<commit_before>import { SENSOR_ACTIONS } from '../../actions/Entities/SensorActions';
import { UIDatabase } from '../../database';
import { ROUTES } from '../../navigation/index';

const initialState = () => ({
  byId: UIDatabase.objects('Sensor').reduce(
    (acc, sensor) => ({
      ...acc,
      [sensor.id]: sensor,
    }),
    {}
  ),
  newId: '',
  editingId: '',
});

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

  switch (type) {
    case 'Navigation/NAVIGATE': {
      const { params, routeName } = action;

      if (routeName !== ROUTES.SENSOR_EDIT) return state;
      const { sensor } = params;
      const { id } = sensor;

      return { ...state, editingId: id };
    }

    case SENSOR_ACTIONS.CREATE: {
      const { byId } = state;
      const { payload } = action;
      const { id } = payload;

      return { ...state, byId: { ...byId, [id]: payload }, newId: id };
    }

    case SENSOR_ACTIONS.RESET_NEW: {
      const { byId, newId } = state;
      const newById = { ...byId, [newId]: null };
      return { ...state, byId: newById, newId: '' };
    }

    case SENSOR_ACTIONS.UPDATE: {
      const { byId } = state;
      const { payload } = action;
      const { id, field, value } = payload;

      if (field === 'name' && value?.length > 50) return state;
      if (field === 'code' && value?.length > 10) return state;

      const newSensorState = { ...byId[id], [field]: value };
      const newById = { ...byId, [id]: newSensorState };

      return { ...state, byId: newById };
    }

    default: {
      return state;
    }
  }
};<commit_msg>Add update to sensor reducer to handle saving a sensor<commit_after>import { SENSOR_ACTIONS } from '../../actions/Entities/SensorActions';
import { UIDatabase } from '../../database';
import { ROUTES } from '../../navigation/index';

const initialState = () => ({
  byId: UIDatabase.objects('Sensor').reduce(
    (acc, sensor) => ({
      ...acc,
      [sensor.id]: sensor,
    }),
    {}
  ),
  newId: '',
  editingId: '',
});

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

  switch (type) {
    case 'Navigation/NAVIGATE': {
      const { params, routeName } = action;

      if (routeName !== ROUTES.SENSOR_EDIT) return state;
      const { sensor } = params;
      const { id } = sensor;

      return { ...state, editingId: id };
    }

    case SENSOR_ACTIONS.CREATE: {
      const { byId } = state;
      const { payload } = action;
      const { id } = payload;

      return { ...state, byId: { ...byId, [id]: payload }, newId: id };
    }

    case SENSOR_ACTIONS.RESET_NEW: {
      const { byId, newId } = state;
      const newById = { ...byId, [newId]: null };
      return { ...state, byId: newById, newId: '' };
    }

    case SENSOR_ACTIONS.SAVE_NEW: {
      const { byId } = state;
      const { payload } = action;
      const { sensor } = payload;
      const { id } = sensor;

      const newById = { ...byId, [id]: sensor };

      return { ...state, byId: newById, newId: '' };
    }

    case SENSOR_ACTIONS.UPDATE: {
      const { byId } = state;
      const { payload } = action;
      const { id, field, value } = payload;

      if (field === 'name' && value?.length > 50) return state;
      if (field === 'code' && value?.length > 10) return state;

      const newSensorState = { ...byId[id], [field]: value };
      const newById = { ...byId, [id]: newSensorState };

      return { ...state, byId: newById };
    }

    default: {
      return state;
    }
  }
};
{'fraction_non_alphanumeric': 0.1737062937062937, 'fraction_numerical': 0.0022377622377622378, 'mean_word_length': 2.2100538599640935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '807987', 'n_tokens_mistral': 1182, 'n_tokens_neox': 1164, 'n_words': 301}