<commit_before>import * as React from 'react';
import TextareaAutosize from 'react-textarea-autosize';
import { classes } from 'typestyle';
import { showErrorMessage } from '@jupyterlab/apputils';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import ClearIcon from '@material-ui/icons/Clear';
import { Git, IGitExtension } from '../tokens';
import {
  actionsWrapperClass,
  commitFormClass,
  commitSummaryClass,
  commitDescriptionClass,
  buttonClass,
  cancelButtonClass,
  closeButtonClass,
  contentWrapperClass,
  resetRevertDialogClass,
  submitButtonClass,
  titleClass,
  titleWrapperClass
} from '../style/ResetRevertDialog';

/**
 * Interface describing component properties.
 */
export interface IResetRevertDialogProps {
  /**
   * Type of action to perform.
   */
  action: 'reset' | 'revert';

  /**
   * Commit data for a single commit.
   */
  commit: Git.ISingleCommitInfo;

  /**
   * Extension data model.
   */
  model: IGitExtension;

  /**
   * Boolean indicating whether to show the dialog.
   */
  open: boolean;

  /**
   * Callback invoked upon closing the dialog.
   */
  onClose: () => void;
}

/**
 * Interface describing component state.
 */
export interface IResetRevertDialogState {
  /**
   * Commit message summary.
   */
  summary: string;

  /**
   * Commit message description.
   */
  description: string;

  /**
   * Boolean indicating whether component buttons should be disabled.
   */
  disabled: boolean;
}

/**
 * React component for rendering a dialog for reseting or reverting a single commit.
 */
export class ResetRevertDialog extends React.Component<
  IResetRevertDialogProps,
  IResetRevertDialogState
> {
  /**
   * Returns a React component for reseting or reverting a single commit.
   *
   * @param props - component properties
   * @returns React component
   */
  constructor(props: IResetRevertDialogProps) {
    super(props);
    this.state = {
      summary: '',
      description: '',
      disabled: false
    };
  }

  /**
   * Renders the component.
   *
   * @returns React element
   */
  render(): React.ReactElement {
    const shortCommit = this.props.commit.commit.slice(0, 7);
    return (
      <Dialog
        classes={{
          paper: resetRevertDialogClass
        }}
        open={this.props.open}
        onClose={this._onClose}
      >
        <div className={titleWrapperClass}>
          <p className={titleClass}>
            {this.props.action === 'revert'
              ? 'Revert Changes'
              : 'Reset Changes'}
          </p>
          <button className={closeButtonClass}>
            <ClearIcon
              titleAccess="Close this dialog"
              fontSize="small"
              onClick={this._onClose}
            />
          </button>
        </div>
        <div className={contentWrapperClass}>
          <p>
            {this.props.action === 'revert'
              ? "These changes will be reverted. Only commit if you're sure you're okay losing these changes."
              : `All changes after commit ${shortCommit} will be gone forever (hard reset). Are you sure?`}
          </p>
          {this.props.action === 'revert' ? (
            <div className={commitFormClass}>
              <input
                className={commitSummaryClass}
                type="text"
                placeholder={this._defaultSummary()}
                title="Enter a commit message summary (a single line, preferably less than 50 characters)"
                value={this.state.summary}
                onChange={this._onSummaryChange}
              />
              <TextareaAutosize
                className={commitDescriptionClass}
                minRows={5}
                placeholder={this._defaultDescription()}
                title="Enter a commit message description"
                value={this.state.description}
                onChange={this._onDescriptionChange}
              />
            </div>
          ) : null}
        </div>
        <DialogActions className={actionsWrapperClass}>
          <input
            className={classes(buttonClass, cancelButtonClass)}
            type="button"
            title="Cancel changes"
            value="Cancel"
            onClick={this._onClose}
          />
          <input
            disabled={this.state.disabled}<commit_msg>Ensure cancel button is also disabled while awaiting execution<commit_after>import * as React from 'react';
import TextareaAutosize from 'react-textarea-autosize';
import { classes } from 'typestyle';
import { showErrorMessage } from '@jupyterlab/apputils';
import Dialog from '@material-ui/core/Dialog';
import DialogActions from '@material-ui/core/DialogActions';
import ClearIcon from '@material-ui/icons/Clear';
import { Git, IGitExtension } from '../tokens';
import {
  actionsWrapperClass,
  commitFormClass,
  commitSummaryClass,
  commitDescriptionClass,
  buttonClass,
  cancelButtonClass,
  closeButtonClass,
  contentWrapperClass,
  resetRevertDialogClass,
  submitButtonClass,
  titleClass,
  titleWrapperClass
} from '../style/ResetRevertDialog';

/**
 * Interface describing component properties.
 */
export interface IResetRevertDialogProps {
  /**
   * Type of action to perform.
   */
  action: 'reset' | 'revert';

  /**
   * Commit data for a single commit.
   */
  commit: Git.ISingleCommitInfo;

  /**
   * Extension data model.
   */
  model: IGitExtension;

  /**
   * Boolean indicating whether to show the dialog.
   */
  open: boolean;

  /**
   * Callback invoked upon closing the dialog.
   */
  onClose: () => void;
}

/**
 * Interface describing component state.
 */
export interface IResetRevertDialogState {
  /**
   * Commit message summary.
   */
  summary: string;

  /**
   * Commit message description.
   */
  description: string;

  /**
   * Boolean indicating whether component buttons should be disabled.
   */
  disabled: boolean;
}

/**
 * React component for rendering a dialog for reseting or reverting a single commit.
 */
export class ResetRevertDialog extends React.Component<
  IResetRevertDialogProps,
  IResetRevertDialogState
> {
  /**
   * Returns a React component for reseting or reverting a single commit.
   *
   * @param props - component properties
   * @returns React component
   */
  constructor(props: IResetRevertDialogProps) {
    super(props);
    this.state = {
      summary: '',
      description: '',
      disabled: false
    };
  }

  /**
   * Renders the component.
   *
   * @returns React element
   */
  render(): React.ReactElement {
    const shortCommit = this.props.commit.commit.slice(0, 7);
    return (
      <Dialog
        classes={{
          paper: resetRevertDialogClass
        }}
        open={this.props.open}
        onClose={this._onClose}
      >
        <div className={titleWrapperClass}>
          <p className={titleClass}>
            {this.props.action === 'revert'
              ? 'Revert Changes'
              : 'Reset Changes'}
          </p>
          <button className={closeButtonClass}>
            <ClearIcon
              titleAccess="Close this dialog"
              fontSize="small"
              onClick={this._onClose}
            />
          </button>
        </div>
        <div className={contentWrapperClass}>
          <p>
            {this.props.action === 'revert'
              ? "These changes will be reverted. Only commit if you're sure you're okay losing these changes."
              : `All changes after commit ${shortCommit} will be gone forever (hard reset). Are you sure?`}
          </p>
          {this.props.action === 'revert' ? (
            <div className={commitFormClass}>
              <input
                className={commitSummaryClass}
                type="text"
                placeholder={this._defaultSummary()}
                title="Enter a commit message summary (a single line, preferably less than 50 characters)"
                value={this.state.summary}
                onChange={this._onSummaryChange}
              />
              <TextareaAutosize
                className={commitDescriptionClass}
                minRows={5}
                placeholder={this._defaultDescription()}
                title="Enter a commit message description"
                value={this.state.description}
                onChange={this._onDescriptionChange}
              />
            </div>
          ) : null}
        </div>
        <DialogActions className={actionsWrapperClass}>
          <input
            disabled={this.state.disabled}
            className={classes(buttonClass, cancelButtonClass)}
            type="button"
            title="Cancel changes"
            value="Cancel"
            onClick={this._onClose}
          />
          <input
            disabled={this.state.disabled}
{'fraction_non_alphanumeric': 0.10610531093962779, 'fraction_numerical': 0.0011348161597821154, 'mean_word_length': 2.1792929292929295, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '349712', 'n_tokens_mistral': 2337, 'n_tokens_neox': 2295, 'n_words': 590}