<commit_before>import React from "react";
import {render} from "react-dom";
import {SubmissionFileManager} from "./submission_file_manager";

class RepoBrowser extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      revision_identifier: undefined,
      revisions: [],
    };
  }

  componentDidMount() {
    this.fetchRevisions();
  }

  // Update the list of revisions and set the currently-viewed revision to the most recent one.
  fetchRevisions = () => {
    fetch(
      Routes.revisions_course_assignment_submissions_path({
        course_id: this.props.course_id,
        assignment_id: this.props.assignment_id,
        grouping_id: this.props.grouping_id,
      }),
      {
        credentials: "same-origin",
        headers: {
          "content-type": "application/json",
        },
      }
    )
      .then(data => data.json())
      .then(data => this.setState({revisions: data, revision_identifier: data[0].id}));
  };

  selectRevision = event => {
    this.setState({revision_identifier: event.target.value});
  };

  revisionToOption = rev => {
    let text = `${rev.id_ui} `;
    if (rev.timestamp !== rev.server_timestamp) {
      text +=
        `(${I18n.t("submissions.repo_browser.client_time")} ${rev.timestamp}, ` +
        `${I18n.t("submissions.repo_browser.server_time")} ${rev.server_timestamp})`;
    } else {
      text += `(${rev.timestamp})`;
    }

    // Highlight the collected revision
    let className = "";
    if (rev.id === this.props.collected_revision_id) {
      className = "collected";
      text += ` — ${I18n.t("submissions.repo_browser.collected")}`;
    } else {
      className = "uncollected";
    }

    return (
      <option className={className} key={rev.id} value={rev.id}>
        {text}
      </option>
    );
  };

  isReadOnly = () => {
    if (!!this.state.revisions.length) {
      return this.state.revision_identifier !== this.state.revisions[0].id;
    } else {
      return false;
    }
  };

  render() {
    let className = "";
    if (this.state.revision_identifier === this.props.collected_revision_id) {
      className = "collected-checked";
    }
    return (
      <div>
        <h3>
          <label>{I18n.t("submissions.repo_browser.viewing_revision")}</label>
          <select
            value={this.state.revision_identifier}
            onChange={this.selectRevision}
            className={className}
          >
            {this.state.revisions.map(this.revisionToOption)}
          </select>
        </h3>
        {this.props.is_timed && (
          <p>
            <strong>{I18n.t("activerecord.attributes.assignment.start_time")}: </strong>
            {this.props.start_time || I18n.t("not_applicable")}
          </p>
        )}
        <p>
          <strong>{I18n.t("activerecord.attributes.assignment.due_date")}: </strong>
          {this.props.due_date}
        </p>
        <p>
          <strong>{I18n.t("activerecord.attributes.assignment.collection_date")}: </strong>
          {this.props.collection_date}
        </p>
        <SubmissionFileManager
          course_id={this.props.assignment_id}
          assignment_id={this.props.assignment_id}
          grouping_id={this.props.grouping_id}
          revision_identifier={this.state.revision_identifier}
          onChange={this.fetchRevisions}
          fetchOnMount={false}
          enableSubdirs={this.props.enableSubdirs}
          readOnly={this.isReadOnly()}
        />
        <ManualCollectionForm
          course_id={this.props.assignment_id}
          assignment_id={this.props.assignment_id}
          late_penalty={this.props.late_penalty}
          grouping_id={this.props.grouping_id}
          revision_identifier={this.state.revision_identifier}
        />
      </div>
    );
  }
}

class ManualCollectionForm extends React.Component {
  static defaultProps = {
    revision_identifier: "", //set initial value so that the input (in render) remains controlled
  };

  render() {
    const action = Routes.manually_collect_and_begin_grading_course_assignment_submissions_path(
      this.props.course_id,
      this.props.assignment_id
    );

    return (
      <fieldset>
        <legend>
          <span>{I18n.t("submissions.collect.manual_collection")}</span>
        </legend>
        <form method="POST" action={action}>
          <input
            type="hidden"<commit_msg>repo browser course id should use the correct id<commit_after>import React from "react";
import {render} from "react-dom";
import {SubmissionFileManager} from "./submission_file_manager";

class RepoBrowser extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      revision_identifier: undefined,
      revisions: [],
    };
  }

  componentDidMount() {
    this.fetchRevisions();
  }

  // Update the list of revisions and set the currently-viewed revision to the most recent one.
  fetchRevisions = () => {
    fetch(
      Routes.revisions_course_assignment_submissions_path({
        course_id: this.props.course_id,
        assignment_id: this.props.assignment_id,
        grouping_id: this.props.grouping_id,
      }),
      {
        credentials: "same-origin",
        headers: {
          "content-type": "application/json",
        },
      }
    )
      .then(data => data.json())
      .then(data => this.setState({revisions: data, revision_identifier: data[0].id}));
  };

  selectRevision = event => {
    this.setState({revision_identifier: event.target.value});
  };

  revisionToOption = rev => {
    let text = `${rev.id_ui} `;
    if (rev.timestamp !== rev.server_timestamp) {
      text +=
        `(${I18n.t("submissions.repo_browser.client_time")} ${rev.timestamp}, ` +
        `${I18n.t("submissions.repo_browser.server_time")} ${rev.server_timestamp})`;
    } else {
      text += `(${rev.timestamp})`;
    }

    // Highlight the collected revision
    let className = "";
    if (rev.id === this.props.collected_revision_id) {
      className = "collected";
      text += ` — ${I18n.t("submissions.repo_browser.collected")}`;
    } else {
      className = "uncollected";
    }

    return (
      <option className={className} key={rev.id} value={rev.id}>
        {text}
      </option>
    );
  };

  isReadOnly = () => {
    if (!!this.state.revisions.length) {
      return this.state.revision_identifier !== this.state.revisions[0].id;
    } else {
      return false;
    }
  };

  render() {
    let className = "";
    if (this.state.revision_identifier === this.props.collected_revision_id) {
      className = "collected-checked";
    }
    return (
      <div>
        <h3>
          <label>{I18n.t("submissions.repo_browser.viewing_revision")}</label>
          <select
            value={this.state.revision_identifier}
            onChange={this.selectRevision}
            className={className}
          >
            {this.state.revisions.map(this.revisionToOption)}
          </select>
        </h3>
        {this.props.is_timed && (
          <p>
            <strong>{I18n.t("activerecord.attributes.assignment.start_time")}: </strong>
            {this.props.start_time || I18n.t("not_applicable")}
          </p>
        )}
        <p>
          <strong>{I18n.t("activerecord.attributes.assignment.due_date")}: </strong>
          {this.props.due_date}
        </p>
        <p>
          <strong>{I18n.t("activerecord.attributes.assignment.collection_date")}: </strong>
          {this.props.collection_date}
        </p>
        <SubmissionFileManager
          course_id={this.props.course_id}
          assignment_id={this.props.assignment_id}
          grouping_id={this.props.grouping_id}
          revision_identifier={this.state.revision_identifier}
          onChange={this.fetchRevisions}
          fetchOnMount={false}
          enableSubdirs={this.props.enableSubdirs}
          readOnly={this.isReadOnly()}
        />
        <ManualCollectionForm
          course_id={this.props.course_id}
          assignment_id={this.props.assignment_id}
          late_penalty={this.props.late_penalty}
          grouping_id={this.props.grouping_id}
          revision_identifier={this.state.revision_identifier}
        />
      </div>
    );
  }
}

class ManualCollectionForm extends React.Component {
  static defaultProps = {
    revision_identifier: "", //set initial value so that the input (in render) remains controlled
  };

  render() {
    const action = Routes.manually_collect_and_begin_grading_course_assignment_submissions_path(
      this.props.course_id,
      this.props.assignment_id
    );

    return (
      <fieldset>
        <legend>
          <span>{I18n.t("submissions.collect.manual_collection")}</span>
        </legend>
        <form method="POST" action={action}>
          <input
            type="hidden"
{'fraction_non_alphanumeric': 0.1371636198478483, 'fraction_numerical': 0.004996025888497786, 'mean_word_length': 2.4419695193434934, 'pattern_counts': {'":': 2, '<': 65, '<?xml version=': 0, '>': 75, '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': '1210186', 'n_tokens_mistral': 2783, 'n_tokens_neox': 2718, 'n_words': 405}