<commit_before>import { LOAD_SURVEY, CLEAR_SURVEY } from "actions/survey";
import {
  CHANGE,
  ADD_ITEM,
  ADD_ITEM_COMPLETE,
  REMOVE_ITEM
} from "actions/surveyItems";

import { merge, omit, includes, find } from "lodash";

const defaultState = {
  data_version: "0.0.1",
  description: "",
  groups: {},
  legal_basis: "StatisticsOfTradeAct",
  mime_type: "application/json/ons/eq",
  questionnaire_id: "0001",
  schema_version: "0.0.1",
  id: "000",
  theme: "default",
  title: "",
  blocks: {
    introduction: {
      type: "Introduction",
      id: "introduction",
      information_to_provide: []
    }
  },
  sections: {},
  questions: {},
  answers: {}
};

const surveyItemTypes = {
  sections: {
    description: "",
    questions: [],
    title: name
  },
  questions: {
    description: "",
    answers: [],
    guidance: [],
    type: "General",
    title: name
  },
  answers: {
    description: "",
    label: name,
    mandatory: false,
    q_code: "",
    type: ""
  }
};

const getItemByType = (type, name) => {
  return surveyItemTypes[type];
};

const survey = (state = defaultState, action) => {
  const { payload } = action;
  switch (action.type) {
    case LOAD_SURVEY:
      return {
        ...state,
        ...payload
      };

    case CLEAR_SURVEY:
      return defaultState;

    case CHANGE:
      return merge({}, state, {
        [payload.type]: {
          [payload.id]: {
            [payload.field]: payload.value
          }
        }
      });

    case ADD_ITEM:
      const emptyItem = {
        [payload.type]: {
          [payload.id]: {}
        }
      };

      if (payload.parentId) {<commit_msg>fixed bug in survey reducer<commit_after>import { LOAD_SURVEY, CLEAR_SURVEY } from "actions/survey";
import {
  CHANGE,
  ADD_ITEM,
  ADD_ITEM_COMPLETE,
  REMOVE_ITEM
} from "actions/surveyItems";

import { merge, omit, includes, find } from "lodash";

const defaultState = {
  data_version: "0.0.1",
  description: "",
  groups: {},
  legal_basis: "StatisticsOfTradeAct",
  mime_type: "application/json/ons/eq",
  questionnaire_id: "0001",
  schema_version: "0.0.1",
  id: "000",
  theme: "default",
  title: "",
  blocks: {
    introduction: {
      type: "Introduction",
      id: "introduction",
      information_to_provide: []
    }
  },
  sections: {},
  questions: {},
  answers: {}
};

const getItemByType = (type, name) => {
  return {
    sections: {
      description: "",
      questions: [],
      title: name
    },
    questions: {
      description: "",
      answers: [],
      guidance: [],
      type: "General",
      title: name
    },
    answers: {
      description: "",
      label: name,
      mandatory: false,
      q_code: "",
      type: ""
    }
  }[type];
};

const survey = (state = defaultState, action) => {
  const { payload } = action;
  switch (action.type) {
    case LOAD_SURVEY:
      return {
        ...state,
        ...payload
      };

    case CLEAR_SURVEY:
      return defaultState;

    case CHANGE:
      return merge({}, state, {
        [payload.type]: {
          [payload.id]: {
            [payload.field]: payload.value
          }
        }
      });

    case ADD_ITEM:
      const emptyItem = {
        [payload.type]: {
          [payload.id]: {}
        }
      };

      if (payload.parentId) {
{'fraction_non_alphanumeric': 0.15193704600484262, 'fraction_numerical': 0.007869249394673124, 'mean_word_length': 2.2025193798449614, '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': '6164087', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1105, 'n_words': 228}