<commit_before>import I18n from 'i18n-js';
import {
  RECEIVE_WIZARD_ASSIGNMENT_OPTIONS,
  RECEIVE_WIZARD_PANELS,
  SELECT_WIZARD_OPTION,
  // EXPAND_WIZARD_OPTION,
  WIZARD_ADVANCE,
  WIZARD_REWIND,
  WIZARD_GOTO,
  WIZARD_ENABLE_SUMMARY_MODE,
  WIZARD_DISABLE_SUMMARY_MODE,
  SINGLE_CHOICE_PANEL
  // WIZARD_RESET,
  // WIZARD_SUBMITTED
} from '../constants';

const assignmentsPanel = (options = []) => {
  return {
    title: I18n.t('wizard.assignment_type'),
    description: I18n.t('wizard.select_assignment'),
    options,
    type: 1,
    minimum: 1,
    key: 'index'
  };
};

const datesPanel = {
  title: I18n.t('wizard.course_dates'),
  description: '',
  options: [],
  type: -1,
  minimum: 0,
  key: 'dates'
};

const summaryPanel = {
  title: I18n.t('wizard.summary'),
  description: I18n.t('wizard.review_selections'),
  options: [],
  type: -1,
  minimum: 0,
  key: 'summary'
};

const panels = (assignmentOptions = [], extraPanels = []) => {
  return [
    datesPanel,
    assignmentsPanel(assignmentOptions),
    ...extraPanels,
    summaryPanel
  ];
};

const updatedPanelSelections = (oldPanels, panelIndex, optionIndex) => {
  const newPanels = [...oldPanels];
  const updatedPanel = { ...newPanels[panelIndex] };
  const updatedOptions = updatedPanel.options.map((option, index) => {
    const updatedOption = { ...option };
    if (index === optionIndex) {
      updatedOption.selected = !option.selected;
    } else if (updatedPanel.type === SINGLE_CHOICE_PANEL) {
      updatedOption.selected = false;
    }
    return updatedOption;
  });

  updatedPanel.options = updatedOptions;
  newPanels[panelIndex] = updatedPanel;
  return newPanels;
};

const initialState = {
  activeIndex: 0,
  summary: false,
  wizardKey: null,
  assignmentOptions: [],
  panels: panels()
};

export default function wizard(state = initialState, action) {
  switch (action.type) {
    case RECEIVE_WIZARD_ASSIGNMENT_OPTIONS: {
      const assignmentOptions = action.assignmentOptions;
      return { ...state, assignmentOptions, panels: panels(assignmentOptions) };
    }
    case RECEIVE_WIZARD_PANELS: {
      const extraPanels = action.extraPanels;
      return { ...state, panels: panels(state.assignmentOptions, extraPanels) };
    }
    case SELECT_WIZARD_OPTION: {
      return { ...state, panels: updatedPanelSelections(state.panels, action.panelIndex, action.optionIndex) };
    }
    case WIZARD_ADVANCE: {
      return { ...state, activeIndex: state.activeIndex + 1 };
    }
    case WIZARD_REWIND: {
      return { ...state, activeIndex: state.activeIndex - 1 };
    }
    case WIZARD_GOTO: {
      return { ...state, activeIndex: action.toPanelIndex };
    }
    case WIZARD_ENABLE_SUMMARY_MODE:
      return { ...state, summary: true };
    case WIZARD_DISABLE_SUMMARY_MODE:
      return { ...state, summary: false };
    default:
      return state;
  }
}
<commit_msg>Don't deselect re-clicked options for single-choice panels<commit_after>import I18n from 'i18n-js';
import {
  RECEIVE_WIZARD_ASSIGNMENT_OPTIONS,
  RECEIVE_WIZARD_PANELS,
  SELECT_WIZARD_OPTION,
  // EXPAND_WIZARD_OPTION,
  WIZARD_ADVANCE,
  WIZARD_REWIND,
  WIZARD_GOTO,
  WIZARD_ENABLE_SUMMARY_MODE,
  WIZARD_DISABLE_SUMMARY_MODE,
  SINGLE_CHOICE_PANEL
  // WIZARD_RESET,
  // WIZARD_SUBMITTED
} from '../constants';

const assignmentsPanel = (options = []) => {
  return {
    title: I18n.t('wizard.assignment_type'),
    description: I18n.t('wizard.select_assignment'),
    options,
    type: 1,
    minimum: 1,
    key: 'index'
  };
};

const datesPanel = {
  title: I18n.t('wizard.course_dates'),
  description: '',
  options: [],
  type: -1,
  minimum: 0,
  key: 'dates'
};

const summaryPanel = {
  title: I18n.t('wizard.summary'),
  description: I18n.t('wizard.review_selections'),
  options: [],
  type: -1,
  minimum: 0,
  key: 'summary'
};

const panels = (assignmentOptions = [], extraPanels = []) => {
  return [
    datesPanel,
    assignmentsPanel(assignmentOptions),
    ...extraPanels,
    summaryPanel
  ];
};

const updatedPanelSelections = (oldPanels, panelIndex, optionIndex) => {
  const newPanels = [...oldPanels];
  const updatedPanel = { ...newPanels[panelIndex] };
  const updatedOptions = updatedPanel.options.map((option, index) => {
    const updatedOption = { ...option };
    if (updatedPanel.type === SINGLE_CHOICE_PANEL) {
      updatedOption.selected = false;
    }
    if (index === optionIndex) {
      updatedOption.selected = !updatedOption.selected;
    }
    return updatedOption;
  });

  updatedPanel.options = updatedOptions;
  newPanels[panelIndex] = updatedPanel;
  return newPanels;
};

const initialState = {
  activeIndex: 0,
  summary: false,
  wizardKey: null,
  assignmentOptions: [],
  panels: panels()
};

export default function wizard(state = initialState, action) {
  switch (action.type) {
    case RECEIVE_WIZARD_ASSIGNMENT_OPTIONS: {
      const assignmentOptions = action.assignmentOptions;
      return { ...state, assignmentOptions, panels: panels(assignmentOptions) };
    }
    case RECEIVE_WIZARD_PANELS: {
      const extraPanels = action.extraPanels;
      return { ...state, panels: panels(state.assignmentOptions, extraPanels) };
    }
    case SELECT_WIZARD_OPTION: {
      return { ...state, panels: updatedPanelSelections(state.panels, action.panelIndex, action.optionIndex) };
    }
    case WIZARD_ADVANCE: {
      return { ...state, activeIndex: state.activeIndex + 1 };
    }
    case WIZARD_REWIND: {
      return { ...state, activeIndex: state.activeIndex - 1 };
    }
    case WIZARD_GOTO: {
      return { ...state, activeIndex: action.toPanelIndex };
    }
    case WIZARD_ENABLE_SUMMARY_MODE:
      return { ...state, summary: true };
    case WIZARD_DISABLE_SUMMARY_MODE:
      return { ...state, summary: false };
    default:
      return state;
  }
}

{'fraction_non_alphanumeric': 0.12824034334763948, 'fraction_numerical': 0.007896995708154506, 'mean_word_length': 3.4337899543378994, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5649243', 'n_tokens_mistral': 2047, 'n_tokens_neox': 1993, 'n_words': 379}