<commit_before>import { React, PropTypes, observer, observable, action, styled } from 'vendor';
import Loading from 'shared/components/loading-animation';
import ExerciseHelpers from '../../../helpers/exercise';
import ExerciseControls from './exercise-controls';
import ExerciseDetails from '../../../components/exercises/details';
import AddEditQuestionModal from '../../../components/add-edit-question';
import { DeleteExerciseModal } from '../../../components/add-edit-question/modals';
import ExerciseCards from './cards';
import TourRegion from '../../../components/tours/region';
import User from '../../../models/user';
import { Body } from '../builder';
import { colors } from '../../../theme';

const StyledBody = styled(Body)`
  background: ${colors.neutral.lighter};
`;

@observer
class ChooseExercises extends React.Component {
  static propTypes = {
    ux: PropTypes.object.isRequired,
  };

  constructor(props) {
    super(props);
    
  }

  @observable currentView = 'cards';
  @observable currentSection;
  @observable displayFeedback = true;
  @observable focusedExercise;
  @observable selectedExercise;
  @observable showAddEditQuestionModal = false;
  @observable showDeleteQuestionModal = false;

  @action.bound onShowDetailsViewClick() {
    this.currentView = 'details';
  }

  @action.bound onShowCardViewClick(ev, exercise) {
    this.currentView = 'cards';
    this.focusedExercise = exercise;
  }

  @action.bound onDisplayAddEditQuestionModal(show) {
    if(!show) {this.selectedExercise = null;}
    this.showAddEditQuestionModal = !!show;
  }

  @action.bound onEditExercise = (ev, exercise) => {
    this.selectedExercise = exercise.wrapper;
    this.onDisplayAddEditQuestionModal(ev, true);
  }

  @action.bound onDeleteExercise() {
    this.props.ux.exercises.deleteExercise(this.props.ux.course, this.selectedExercise);
    this.showDeleteQuestionModal = false;
  }

  getExerciseActions = (exercise) => {
    const { ux } = this.props;
    const isUserGeneratedQuestion = exercise.belongsToCurrentUserProfileId(User.profile_id);

    const actions = {};
    if (exercise.isSelected) {
      actions.exclude = {
        message: 'Remove question',
        handler: ux.onExerciseToggle,
      };
    } else {
      actions.include = {
        message: 'Add question',
        handler: ux.onExerciseToggle,
      };
    }
    if (this.currentView === 'details') {
      this.addDetailsActions(actions, exercise, isUserGeneratedQuestion);
    } else {
      this.addCardActions(actions, exercise);
    }
    return actions;
  };

  addDetailsActions = (actions, exercise, isUserGeneratedQuestion) => {
    if (this.displayFeedback) {
      actions['feedback-off'] = {
        message: 'Hide Feedback',
        handler: this.toggleFeedback,
      };
    } else {
      actions['feedback-on'] = {
        message: 'Preview Feedback',
        handler: this.toggleFeedback,
      };
    }

    if (isUserGeneratedQuestion) {
      actions.deleteExercise = {
        message: 'Delete question',
        handler: () => this.showDeleteQuestionModal = true,
      };
    }
    else {
      actions['report-error'] = {
        message: 'Suggest a correction',
        handler: this.reportError,
      };
    }
  };

  addCardActions = (actions, exercise) => {
    action.details = {
      message: 'Details',
      handler: this.showDetails,
    };
    if (exercise.canCopy) {
      const isUserGeneratedQuestion = exercise.belongsToCurrentUser(User);
      actions.copyEdit = {
        message: `${!isUserGeneratedQuestion ? 'Copy & Edit' : 'Edit'}`,
        handler: this.onEditExercise,
      };
    }<commit_msg>change new check for user generated question<commit_after>import { React, PropTypes, observer, observable, action, styled } from 'vendor';
import Loading from 'shared/components/loading-animation';
import ExerciseHelpers from '../../../helpers/exercise';
import ExerciseControls from './exercise-controls';
import ExerciseDetails from '../../../components/exercises/details';
import AddEditQuestionModal from '../../../components/add-edit-question';
import { DeleteExerciseModal } from '../../../components/add-edit-question/modals';
import ExerciseCards from './cards';
import TourRegion from '../../../components/tours/region';
import User from '../../../models/user';
import { Body } from '../builder';
import { colors } from '../../../theme';

const StyledBody = styled(Body)`
  background: ${colors.neutral.lighter};
`;

@observer
class ChooseExercises extends React.Component {
  static propTypes = {
    ux: PropTypes.object.isRequired,
  };

  constructor(props) {
    super(props);
    
  }

  @observable currentView = 'cards';
  @observable currentSection;
  @observable displayFeedback = true;
  @observable focusedExercise;
  @observable selectedExercise;
  @observable showAddEditQuestionModal = false;
  @observable showDeleteQuestionModal = false;

  @action.bound onShowDetailsViewClick() {
    this.currentView = 'details';
  }

  @action.bound onShowCardViewClick(ev, exercise) {
    this.currentView = 'cards';
    this.focusedExercise = exercise;
  }

  @action.bound onDisplayAddEditQuestionModal(show) {
    if(!show) {this.selectedExercise = null;}
    this.showAddEditQuestionModal = !!show;
  }

  @action.bound onEditExercise = (ev, exercise) => {
    this.selectedExercise = exercise.wrapper;
    this.onDisplayAddEditQuestionModal(ev, true);
  }

  @action.bound onDeleteExercise() {
    this.props.ux.exercises.deleteExercise(this.props.ux.course, this.selectedExercise);
    this.showDeleteQuestionModal = false;
  }

  getExerciseActions = (exercise) => {
    const { ux } = this.props;
    const isUserGeneratedQuestion = exercise.belongsToCurrentUser(User);

    const actions = {};
    if (exercise.isSelected) {
      actions.exclude = {
        message: 'Remove question',
        handler: ux.onExerciseToggle,
      };
    } else {
      actions.include = {
        message: 'Add question',
        handler: ux.onExerciseToggle,
      };
    }
    if (this.currentView === 'details') {
      this.addDetailsActions(actions, exercise, isUserGeneratedQuestion);
    } else {
      this.addCardActions(actions, exercise, isUserGeneratedQuestion);
    }
    return actions;
  };

  addDetailsActions = (actions, exercise, isUserGeneratedQuestion) => {
    if (this.displayFeedback) {
      actions['feedback-off'] = {
        message: 'Hide Feedback',
        handler: this.toggleFeedback,
      };
    } else {
      actions['feedback-on'] = {
        message: 'Preview Feedback',
        handler: this.toggleFeedback,
      };
    }

    if (isUserGeneratedQuestion) {
      actions.deleteExercise = {
        message: 'Delete question',
        handler: () => this.showDeleteQuestionModal = true,
      };
    }
    else {
      actions['report-error'] = {
        message: 'Suggest a correction',
        handler: this.reportError,
      };
    }
  };

  addCardActions = (actions, exercise, isUserGeneratedQuestion) => {
    action.details = {
      message: 'Details',
      handler: this.showDetails,
    };
    if (exercise.canCopy) {
      actions.copyEdit = {
        message: `${!isUserGeneratedQuestion ? 'Copy & Edit' : 'Edit'}`,
        handler: this.onEditExercise,
      };
    }
{'fraction_non_alphanumeric': 0.13503850385038504, 'fraction_numerical': 0.0, 'mean_word_length': 3.1206798866855525, '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': '6646820', 'n_tokens_mistral': 2121, 'n_tokens_neox': 2075, 'n_words': 429}