<commit_before>import React from "react";
import { Map } from "immutable";
import { connect } from "react-redux";
import { updateQuestionFeedback, updateQuestionFeedbackSettings } from "../../../actions/index";
import { QuestionLevelFeedbackStudentRows } from "../../../components/portal-dashboard/feedback/question-level-feedback-student-rows";
import { FeedbackQuestionRows } from "../../../components/portal-dashboard/feedback/feedback-question-rows";
import { FeedbackLevel, ListViewMode } from "../../../util/misc";

interface IProps {
  activity: Map<string, any>;
  activityIndex: number;
  answers: Map<any, any>;
  autoScores: any;
  computedMaxScore: number;
  currentQuestion: Map<any, any>;
  currentStudentId: string | null;
  feedbacks: Map<any, any>;
  feedbackLevel: FeedbackLevel;
  feedbacksNeedingReview: Map<any, any>;
  isAnonymous: boolean;
  listViewMode: ListViewMode;
  questionFeedbacks: Map<any, any>;
  settings: any;
  students: Map<any, any>;
  updateQuestionFeedback: (answerId: string, feedback: any) => void;
  updateQuestionFeedbackSettings: (embeddableKey: string, feedbackFlags: any) => void;
}

class QuestionFeedbackPanel extends React.PureComponent<IProps> {
  constructor(props: IProps) {
    super(props);
  }

  componentDidMount() {
    this.updateQuestionFeedbackSettings();
  }

  componentDidUpdate(prevProps: IProps) {
    if (prevProps.activity?.get("id") !== this.props.activity?.get("id")) {
      this.updateQuestionFeedbackSettings();
    }
  }

  render() {
    const { activity, activityIndex, answers, currentQuestion, currentStudentId, feedbacksNeedingReview,
            isAnonymous, listViewMode, questionFeedbacks, students } = this.props;
    const currentActivityId = activity?.get("id");

    return (
      <div>
        { listViewMode === "Student"
          ? <QuestionLevelFeedbackStudentRows
              activityId={currentActivityId}
              activityIndex={activityIndex}
              answers={answers}
              currentQuestion={currentQuestion}
              feedbacks={questionFeedbacks}
              feedbacksNeedingReview={feedbacksNeedingReview}
              isAnonymous={isAnonymous}
              students={students}
              updateQuestionFeedback={this.props.updateQuestionFeedback}
            />
          : <FeedbackQuestionRows
              answers={answers}
              currentActivity={activity}
              currentStudentId={currentStudentId}
              feedbacks={questionFeedbacks}
              students={students}
              updateQuestionFeedback={this.props.updateQuestionFeedback}
            />
        }
      </div>
    );
  }

  private updateQuestionFeedbackSettings = () => {
    const questions = this.props.activity.get("questions");
    questions.forEach((question: any) => {
      const questionId = question.get("id");
      if (!this.props.settings.get("questionSettings")?.get(questionId)?.get("feedbackEnabled")) {
        this.props.updateQuestionFeedbackSettings(questionId, { feedbackEnabled: true });
      }
      this.props.updateQuestionFeedbackSettings(questionId, { feedbackEnabled: true });
    });
  }
}

function mapStateToProps(state: any, ownProps: any): Partial<IProps> {
  return {
      questionFeedbacks: state.getIn(["feedback", "questionFeedbacks"]),
      settings: state.getIn(["feedback", "settings"])
  };
}

const mapDispatchToProps = (dispatch: any, ownProps: any): Partial<IProps> => {
  return {
    updateQuestionFeedback: (answerId, feedback) => dispatch(updateQuestionFeedback(answerId, feedback)),
    updateQuestionFeedbackSettings: (embeddableKey, feedbackFlags) => dispatch(updateQuestionFeedbackSettings(embeddableKey, feedbackFlags)),
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(QuestionFeedbackPanel);<commit_msg>Remove redundant code<commit_after>import React from "react";
import { Map } from "immutable";
import { connect } from "react-redux";
import { updateQuestionFeedback, updateQuestionFeedbackSettings } from "../../../actions/index";
import { QuestionLevelFeedbackStudentRows } from "../../../components/portal-dashboard/feedback/question-level-feedback-student-rows";
import { FeedbackQuestionRows } from "../../../components/portal-dashboard/feedback/feedback-question-rows";
import { FeedbackLevel, ListViewMode } from "../../../util/misc";

interface IProps {
  activity: Map<string, any>;
  activityIndex: number;
  answers: Map<any, any>;
  autoScores: any;
  computedMaxScore: number;
  currentQuestion: Map<any, any>;
  currentStudentId: string | null;
  feedbacks: Map<any, any>;
  feedbackLevel: FeedbackLevel;
  feedbacksNeedingReview: Map<any, any>;
  isAnonymous: boolean;
  listViewMode: ListViewMode;
  questionFeedbacks: Map<any, any>;
  settings: any;
  students: Map<any, any>;
  updateQuestionFeedback: (answerId: string, feedback: any) => void;
  updateQuestionFeedbackSettings: (embeddableKey: string, feedbackFlags: any) => void;
}

class QuestionFeedbackPanel extends React.PureComponent<IProps> {
  constructor(props: IProps) {
    super(props);
  }

  componentDidMount() {
    this.updateQuestionFeedbackSettings();
  }

  componentDidUpdate(prevProps: IProps) {
    if (prevProps.activity?.get("id") !== this.props.activity?.get("id")) {
      this.updateQuestionFeedbackSettings();
    }
  }

  render() {
    const { activity, activityIndex, answers, currentQuestion, currentStudentId, feedbacksNeedingReview,
            isAnonymous, listViewMode, questionFeedbacks, students } = this.props;
    const currentActivityId = activity?.get("id");

    return (
      <div>
        { listViewMode === "Student"
          ? <QuestionLevelFeedbackStudentRows
              activityId={currentActivityId}
              activityIndex={activityIndex}
              answers={answers}
              currentQuestion={currentQuestion}
              feedbacks={questionFeedbacks}
              feedbacksNeedingReview={feedbacksNeedingReview}
              isAnonymous={isAnonymous}
              students={students}
              updateQuestionFeedback={this.props.updateQuestionFeedback}
            />
          : <FeedbackQuestionRows
              answers={answers}
              currentActivity={activity}
              currentStudentId={currentStudentId}
              feedbacks={questionFeedbacks}
              students={students}
              updateQuestionFeedback={this.props.updateQuestionFeedback}
            />
        }
      </div>
    );
  }

  private updateQuestionFeedbackSettings = () => {
    const questions = this.props.activity.get("questions");
    questions.forEach((question: any) => {
      const questionId = question.get("id");
      if (!this.props.settings.get("questionSettings")?.get(questionId)?.get("feedbackEnabled")) {
        this.props.updateQuestionFeedbackSettings(questionId, { feedbackEnabled: true });
      }
    });
  }
}

function mapStateToProps(state: any, ownProps: any): Partial<IProps> {
  return {
      questionFeedbacks: state.getIn(["feedback", "questionFeedbacks"]),
      settings: state.getIn(["feedback", "settings"])
  };
}

const mapDispatchToProps = (dispatch: any, ownProps: any): Partial<IProps> => {
  return {
    updateQuestionFeedback: (answerId, feedback) => dispatch(updateQuestionFeedback(answerId, feedback)),
    updateQuestionFeedbackSettings: (embeddableKey, feedbackFlags) => dispatch(updateQuestionFeedbackSettings(embeddableKey, feedbackFlags)),
  };
};

export default connect(mapStateToProps, mapDispatchToProps)(QuestionFeedbackPanel);
{'fraction_non_alphanumeric': 0.12337662337662338, 'fraction_numerical': 0.0, 'mean_word_length': 3.6759603469640645, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 45, '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': '982060', 'n_tokens_mistral': 2056, 'n_tokens_neox': 2037, 'n_words': 374}