<commit_before>import React from 'react';
import moment from 'moment';
import DatePicker from 'react-datepicker';
import Pluralize from 'pluralize';

import ApplyToAll from './apply_to_all'
import activityFromClassificationId from '../../modules/activity_from_classification_id.js';

import PreviewOrLaunchModal from '../../shared/preview_or_launch_modal';

const styles = {
  row: {
    display: 'flex',
    justifyContent: 'space-between',
    alignItems: 'center',
  },
  endRow:{
    display: 'flex',
    justifyContent: 'space-between',
    alignItems: 'center',
    maxWidth: '240px',
  },
  lessonEndRow:{
    display: 'flex',
    width: '100%',
    maxWidth: '390px',
    justifyContent: 'flex-end',
    alignItems: 'center',
  },
  reportEndRow:{
    display: 'flex',
    justifyContent: 'space-between',
    alignItems: 'center',
    marginRight: '15px',
  }
}

export default class ClassroomActivity extends React.Component {
  constructor(props) {
    super(props)

    this.state = {
      startDate: this.dueDate() ? new Date(this.dueDate()) : null,
      showModal: false,
      showCustomizeTooltip: false,
      showLessonPlanTooltip: false,
    }
  }

  UNSAFE_componentWillReceiveProps = (nextProps) => {
    const { startDate, } = this.state
    const newDueDate = nextProps.data ? nextProps.data.dueDate : null
    const formattedNewDueDate = newDueDate ? new Date(newDueDate) : undefined;
    if (formattedNewDueDate !== startDate) {
      this.setState({ startDate: formattedNewDueDate, });
    }
  }

  activityId = () => {
    const { data, } = this.props
    return data.activityId || data.activityUid || data.activity.uid;
  }

  activityName = () => {
    const { data, } = this.props
    return data.name || data.activity.name;
  }

  anonymousPath = () => {
    return `${process.env.DEFAULT_URL}/activity_sessions/anonymous?activity_id=${this.activityId()}`;
  }

  buttonForRecommendations = () => {
    const { activityWithRecommendationIds } = this.props
    if (activityWithRecommendationIds && activityWithRecommendationIds.includes(this.activityId()) && window.location.pathname.includes('diagnostic_reports')) {
      return (
        <div className="recommendations-button" onClick={this.handleRecommendationsLinkClick}>
          Recommendations
        </div>
      );
    }
  }

  calculateAverageScore = () => {
    const { data, } = this.props
    const averageScore = data.cumulativeScore / data.completedCount;
    if (isNaN(averageScore)) {
      return '—';
    } else if (Math.round(averageScore).toString().length === 2) {
      return `${averageScore.toPrecision(2)}%`;
    }
    return `${averageScore}%`;
  }

  classification = () => {
    const { data, } = this.props
    return data.activityClassificationId;
  }

  classroomId = () => {
    const { data, } = this.props
    return data.classroomId || data.classroom_id;
  }

  classroomUnitId = () => {
    const { data, } = this.props
    return data.cuId || data.classroom_unit_id;
  }

  closeModal = () => {
    this.setState({ showModal: false, });
  }

  deleteRow = () => {
    const { report, data, } = this.props
    if (!report && !(this.isLesson())) {
      const style = !data.ownedByCurrentUser ? { visibility: 'hidden', } : null;
      return <div className="pull-right" style={style}><img className="delete-classroom-activity h-pointer" onClick={this.handleHideUnitActivityClick} src="/images/x.svg" /></div>;
    }
  }

  dueDate = () => {
    const { data, } = this.props
    return data.due_date || data.dueDate;
  }

  finalCell = () => {
    const { activityReport, data, report, numberOfStudentsAssignedToUnit, isFirst, updateAllDueDates, } = this.props
    const { startDate, } = this.state
    if (activityReport) {
      return [
        <span className="number-of-students" key="number-of-students">{this.renderPieChart()} {data.completedCount} of {numberOfStudentsAssignedToUnit} {Pluralize('student', numberOfStudentsAssignedToUnit)}</span>,
        <span className="average-score" key="average-score">{this.calculateAverageScore()}</span>,
        <img className="chevron-right" key="chevron-right" src="https://assets.quill.org/images/icons/chevron-dark-green.svg" />
      ];
    } else if (report) {
      /* eslint-disable react/jsx-no-target-blank */
      return [<a href={this.anonymousPath()} key={this.anonymousPath()} target="_blank">Preview</a>, <a key={`report-url-${this.classroomUnitId()}`} onClick={this.handleReportLinkClick}>View Report</a>];
      /* eslint-enable react/jsx-no-target-blank */
    } else if (this.isLesson()) {
      return this.lessonFinalCell();
    }
    if (data.ownedByCurrentUser) {
      return (<span className="due-date-field">
        <DatePicker className="due-date-input" onChange={this.handleChange} placeholderText={startDate ? startDate : 'Due Date (Optional)'} selected={startDate} />
        {startDate && isFirst ? <ApplyToAll startDate={startDate} updateAllDueDates={updateAllDueDates} /> : null}
      </span>);
    }
    return startDate ? <div className="due-date-input">{startDate}</div> : null;
  }<commit_msg>fix issue with my activities page not loading (#6174)<commit_after>import React from 'react';
import moment from 'moment';
import DatePicker from 'react-datepicker';
import Pluralize from 'pluralize';

import ApplyToAll from './apply_to_all'
import activityFromClassificationId from '../../modules/activity_from_classification_id.js';

import PreviewOrLaunchModal from '../../shared/preview_or_launch_modal';

const styles = {
  row: {
    display: 'flex',
    justifyContent: 'space-between',
    alignItems: 'center',
  },
  endRow:{
    display: 'flex',
    justifyContent: 'space-between',
    alignItems: 'center',
    maxWidth: '240px',
  },
  lessonEndRow:{
    display: 'flex',
    width: '100%',
    maxWidth: '390px',
    justifyContent: 'flex-end',
    alignItems: 'center',
  },
  reportEndRow:{
    display: 'flex',
    justifyContent: 'space-between',
    alignItems: 'center',
    marginRight: '15px',
  }
}

export default class ClassroomActivity extends React.Component {
  constructor(props) {
    super(props)

    this.state = {
      startDate: this.dueDate() ? new Date(this.dueDate()) : null,
      showModal: false,
      showCustomizeTooltip: false,
      showLessonPlanTooltip: false,
    }
  }

  UNSAFE_componentWillReceiveProps = (nextProps) => {
    const { startDate, } = this.state
    const newDueDate = nextProps.data ? nextProps.data.dueDate : null
    const formattedNewDueDate = newDueDate ? new Date(newDueDate) : undefined;
    if (formattedNewDueDate !== startDate) {
      this.setState({ startDate: formattedNewDueDate, });
    }
  }

  activityId = () => {
    const { data, } = this.props
    return data.activityId || data.activityUid || data.activity.uid;
  }

  activityName = () => {
    const { data, } = this.props
    return data.name || data.activity.name;
  }

  anonymousPath = () => {
    return `${process.env.DEFAULT_URL}/activity_sessions/anonymous?activity_id=${this.activityId()}`;
  }

  buttonForRecommendations = () => {
    const { activityWithRecommendationIds } = this.props
    if (activityWithRecommendationIds && activityWithRecommendationIds.includes(this.activityId()) && window.location.pathname.includes('diagnostic_reports')) {
      return (
        <div className="recommendations-button" onClick={this.handleRecommendationsLinkClick}>
          Recommendations
        </div>
      );
    }
  }

  calculateAverageScore = () => {
    const { data, } = this.props
    const averageScore = data.cumulativeScore / data.completedCount;
    if (isNaN(averageScore)) {
      return '—';
    } else if (Math.round(averageScore).toString().length === 2) {
      return `${averageScore.toPrecision(2)}%`;
    }
    return `${averageScore}%`;
  }

  classification = () => {
    const { data, } = this.props
    return data.activityClassificationId;
  }

  classroomId = () => {
    const { data, } = this.props
    return data.classroomId || data.classroom_id;
  }

  classroomUnitId = () => {
    const { data, } = this.props
    return data.cuId || data.classroom_unit_id;
  }

  closeModal = () => {
    this.setState({ showModal: false, });
  }

  deleteRow = () => {
    const { report, data, } = this.props
    if (!report && !(this.isLesson())) {
      const style = !data.ownedByCurrentUser ? { visibility: 'hidden', } : null;
      return <div className="pull-right" style={style}><img className="delete-classroom-activity h-pointer" onClick={this.handleHideUnitActivityClick} src="/images/x.svg" /></div>;
    }
  }

  dueDate = () => {
    const { data, } = this.props
    return data.due_date || data.dueDate;
  }

  finalCell = () => {
    const { activityReport, data, report, numberOfStudentsAssignedToUnit, isFirst, updateAllDueDates, } = this.props
    const { startDate, } = this.state
    if (activityReport) {
      return [
        <span className="number-of-students" key="number-of-students">{this.renderPieChart()} {data.completedCount} of {numberOfStudentsAssignedToUnit} {Pluralize('student', numberOfStudentsAssignedToUnit)}</span>,
        <span className="average-score" key="average-score">{this.calculateAverageScore()}</span>,
        <img className="chevron-right" key="chevron-right" src="https://assets.quill.org/images/icons/chevron-dark-green.svg" />
      ];
    } else if (report) {
      /* eslint-disable react/jsx-no-target-blank */
      return [<a href={this.anonymousPath()} key={this.anonymousPath()} target="_blank">Preview</a>, <a key={`report-url-${this.classroomUnitId()}`} onClick={this.handleReportLinkClick}>View Report</a>];
      /* eslint-enable react/jsx-no-target-blank */
    } else if (this.isLesson()) {
      return this.lessonFinalCell();
    }
    if (data.ownedByCurrentUser) {
      return (<span className="due-date-field">
        <DatePicker className="due-date-input" onChange={this.handleChange} placeholderText={startDate ? startDate : 'Due Date (Optional)'} selected={startDate} />
        {startDate && isFirst ? <ApplyToAll startDate={startDate} updateAllDueDates={updateAllDueDates} /> : null}
      </span>);
    }
    return startDate ? <div className="due-date-input">{new Intl.DateTimeFormat('en-US').format(startDate)}</div> : null;
  }
{'fraction_non_alphanumeric': 0.15161823306443775, 'fraction_numerical': 0.0029157352512391875, 'mean_word_length': 3.555112881806109, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 69, 'https://': 2, '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': '1470190', 'n_tokens_mistral': 3289, 'n_tokens_neox': 3197, 'n_words': 591}