<commit_before>import {
  FETCH_ADMIN_USER_SUCCESS,
  FETCH_ADMIN_USER_ERROR
} from '../../actions/admin/adminProfileActions';

import {
  ADMINISTRATOR_DELETED,
  GROUP_TRANSFERRED,
  FETCH_ALL_STUDENTS_GROUP_EXCEPT_FETCHED,
  STUDENTS_GROUP_FETCHED,
  STUDENTS_TRANSFERRED
} from '../../actions/admin/adminDashboardActions';

const initialState = {
  adminUser: null,
  school: null,
  teachers: [],
  admins: [],
  groups: [],
  users: {}
};

function updateAdmins(currentAdmins, idAdminDeleted) {
  return currentAdmins.filter(admin => admin.id !== idAdminDeleted);
}

function updateGroups(currentGroups, _group) {
  return currentGroups.filter(group => group.id !== _group.id).concat(_group);
}

function updateGroupsStudents(groups, groupWithStudents) {
  const updatedGroups = groups.map(group => {
    const studentsForGroup = groupWithStudents.find(groupWithStudent => groupWithStudent.id === group.id);
    if (studentsForGroup) {
      group.students = studentsForGroup.students;
    }

    group.students = (group.students) ? group.students : [];
  });

  return groups;
}

function updateGroupsAfterTransfer(groups, updatedData) {
  const { group, students } = updatedData;
  const studentsToRemoveFromOtherGroups = students.map(student => student.user_id);

  const groupsWithRemovedStudents = groups.map(currentGroup => {
    const updatedStudents = currentGroup.students.filter(student => studentsToRemoveFromOtherGroups.filter(
      id => id === student.id)
    .length === 0);
    return Object.assign({}, currentGroup, {students: updatedStudents});
  });

  const groupsWithNewlyUpdateGroupRemoved = groupsWithRemovedStudents.filter(currentGroup => currentGroup.id !== group.id).concat(group);

  return groupsWithNewlyUpdateGroupRemoved;
}

export default function signupReducer(state = initialState, action) {
  switch (action.type) {
    case FETCH_ADMIN_USER_SUCCESS:
      const { admin, groups, teachers, school, admins } = action.payload;
      return Object.assign({}, initialState, { adminUser: admin, groups, teachers, school, admins });

    case ADMINISTRATOR_DELETED:
      // fix consistency
      return Object.assign({}, initialState, {
        admins: updateAdmins(state.admins, action.data.idAdminDeleted)
      });

    case GROUP_TRANSFERRED:
      return Object.assign({}, initialState, {
        groups: updateGroups(state.groups, action.data.group)
      });

    case FETCH_ALL_STUDENTS_GROUP_EXCEPT_FETCHED:
    case STUDENTS_GROUP_FETCHED:
      return Object.assign({}, initialState, {
        groups: updateGroupsStudents(state.groups, action.data)
      });

    case STUDENTS_TRANSFERRED:
      return Object.assign({}, initialState, {
        groups: updateGroupsAfterTransfer(state.groups, action.data)
      });

    default:
      return state;
  }
}
<commit_msg>rename reducer<commit_after>import {
  FETCH_ADMIN_USER_SUCCESS,
  FETCH_ADMIN_USER_ERROR
} from '../../actions/admin/adminProfileActions';

import {
  ADMINISTRATOR_DELETED,
  GROUP_TRANSFERRED,
  FETCH_ALL_STUDENTS_GROUP_EXCEPT_FETCHED,
  STUDENTS_GROUP_FETCHED,
  STUDENTS_TRANSFERRED
} from '../../actions/admin/adminDashboardActions';

const initialState = {
  adminUser: null,
  school: null,
  teachers: [],
  admins: [],
  groups: [],
  users: {}
};

function updateAdmins(currentAdmins, idAdminDeleted) {
  return currentAdmins.filter(admin => admin.id !== idAdminDeleted);
}

function updateGroups(currentGroups, _group) {
  return currentGroups.filter(group => group.id !== _group.id).concat(_group);
}

function updateGroupsStudents(groups, groupWithStudents) {
  const updatedGroups = groups.map(group => {
    const studentsForGroup = groupWithStudents.find(groupWithStudent => groupWithStudent.id === group.id);
    if (studentsForGroup) {
      group.students = studentsForGroup.students;
    }

    group.students = (group.students) ? group.students : [];
  });

  return groups;
}

function updateGroupsAfterTransfer(groups, updatedData) {
  const { group, students } = updatedData;
  const studentsToRemoveFromOtherGroups = students.map(student => student.user_id);

  const groupsWithRemovedStudents = groups.map(currentGroup => {
    const updatedStudents = currentGroup.students.filter(student => studentsToRemoveFromOtherGroups.filter(
      id => id === student.id)
    .length === 0);
    return Object.assign({}, currentGroup, {students: updatedStudents});
  });

  const groupsWithNewlyUpdateGroupRemoved = groupsWithRemovedStudents.filter(currentGroup => currentGroup.id !== group.id).concat(group);

  return groupsWithNewlyUpdateGroupRemoved;
}

export default function adminReducer(state = initialState, action) {
  switch (action.type) {
    case FETCH_ADMIN_USER_SUCCESS:
      const { admin, groups, teachers, school, admins } = action.payload;
      return Object.assign({}, initialState, { adminUser: admin, groups, teachers, school, admins });

    case ADMINISTRATOR_DELETED:
      // fix consistency
      return Object.assign({}, initialState, {
        admins: updateAdmins(state.admins, action.data.idAdminDeleted)
      });

    case GROUP_TRANSFERRED:
      return Object.assign({}, initialState, {
        groups: updateGroups(state.groups, action.data.group)
      });

    case FETCH_ALL_STUDENTS_GROUP_EXCEPT_FETCHED:
    case STUDENTS_GROUP_FETCHED:
      return Object.assign({}, initialState, {
        groups: updateGroupsStudents(state.groups, action.data)
      });

    case STUDENTS_TRANSFERRED:
      return Object.assign({}, initialState, {
        groups: updateGroupsAfterTransfer(state.groups, action.data)
      });

    default:
      return state;
  }
}

{'fraction_non_alphanumeric': 0.11462029808374734, 'fraction_numerical': 0.00035486160397445, 'mean_word_length': 4.2682242990654204, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3012457', 'n_tokens_mistral': 1764, 'n_tokens_neox': 1702, 'n_words': 315}