<commit_before>import React, { Component } from 'react';
import Dialog from 'material-ui/Dialog';
import PropTypes from 'prop-types';

import QuetionsList from './QuetionsList';
import QuestionForm from './QuestionForm';
import AddQuestionBtn from './AddQuestionBtn';

/**
 * @description propTypes for QuestionsDialogBox
 * @type {Object}
 */
const propTypes = {
  handleCloseDialog: PropTypes.func.isRequired,
  submitQuestionForm: PropTypes.func.isRequired,
  onDeleteQuestion: PropTypes.func.isRequired,
  openDialog: PropTypes.bool.isRequired,
  questions: PropTypes.arrayOf(PropTypes.shape({
    id: PropTypes.string.isRequired,
    question: PropTypes.string.isRequired,
  })).isRequired,
};

/**
 * @class QuestionsDialogBox
 * @extends React.Component
 * @description Render component
 */
class QuestionsDialogBox extends Component {
  state = {
    showForm: false,
    clickedQuestion: null,
  };

  /**
   * @description Handle click on Add Question btn
   */
  handleAddQuestion = () => {
    this.setState({ showForm: true });
  };

  /**
   * @description handle on close dialog box
   */
  handleClose = () => {
    this.hideForm();
    this.props.handleCloseDialog();
  };

  /**
   * @description set state on close form
   */
  hideForm = () => {
    this.setState({ showForm: false, clickedQuestion: null });
  };

  /**
   * @description handle on submit question form
   * @param data
   */
  handleFormSubmit = (data) => {
    this.props.submitQuestionForm(data);
    this.hideForm();
  };

  /**
   * @description handle form cancel
   */
  handleFormCancel = () => {
    this.hideForm();
  };

  /**
   * @description handle Question Item on click
   * @param {Object} data question data
   */
  handleClickOnItem = (data) => {
    this.setState({
      showForm: true,
      clickedQuestion: data,
    });
  };

  /**
   * @description handle click on delete icon
   * @param {String} id
   */
  handleOnDeleteItem = (id) => {
    if (window.confirm('Delete Question?')) {
      this.props.onDeleteQuestion(id);
    }
  };


  /**
   * @description render
   * @return {Object} JSX HTML Content
   */
  render() {
    const { showForm, clickedQuestion } = this.state;
    const { openDialog, questions } = this.props;

    let content = (
      <QuetionsList
        clickOnItem={this.handleClickOnItem}
        onDelete={this.handleOnDeleteItem}
        questions={questions}
      />
    );
    let dialogProps = {
      title: 'Suggested Questions',
      actions: <AddQuestionBtn handleAddQuestion={this.handleAddQuestion} />,
      actionsContainerStyle: { padding: 20, textAlign: 'center' },
    };

    if (showForm) {
      content = (
        <QuestionForm
          handleFormSubmit={this.handleFormSubmit}
          handleFormCancel={this.handleFormCancel}
          initialValues={clickedQuestion}
        />
      );
      dialogProps = {
        title: `${clickedQuestion ? 'Update' : 'Add'} Questions`,
        actions: null,
        actionsContainerStyle: {},
      };
    }
    return (<commit_msg>refactoring dialog box<commit_after>import React, { Component } from 'react';
import Dialog from 'material-ui/Dialog';
import PropTypes from 'prop-types';

import QuetionsList from './QuetionsList';
import QuestionForm from './QuestionForm';
import AddQuestionBtn from './AddQuestionBtn';

/**
 * @description propTypes for QuestionsDialogBox
 * @type {Object}
 */
const propTypes = {
  handleCloseDialog: PropTypes.func.isRequired,
  submitQuestionForm: PropTypes.func.isRequired,
  onDeleteQuestion: PropTypes.func.isRequired,
  openDialog: PropTypes.bool.isRequired,
  questions: PropTypes.arrayOf(PropTypes.shape({
    id: PropTypes.string.isRequired,
    question: PropTypes.string.isRequired,
  })).isRequired,
};

/**
 * @class QuestionsDialogBox
 * @extends React.Component
 * @description Render component
 */
class QuestionsDialogBox extends Component {
  state = {
    showForm: false,
    clickedQuestion: null,
  };

  /**
   * @description Handle click on Add Question btn
   */
  handleAddQuestion = () => {
    this.setState({ showForm: true });
  };

  /**
   * @description handle on close dialog box
   */
  handleClose = () => {
    this.hideForm();
    this.props.handleCloseDialog();
  };

  /**
   * @description set state on close form
   */
  hideForm = () => {
    this.setState({ showForm: false, clickedQuestion: null });
  };

  /**
   * @description handle on submit question form
   * @param data
   */
  handleFormSubmit = (data) => {
    this.props.submitQuestionForm(data);
    this.hideForm();
  };

  /**
   * @description handle form cancel
   */
  handleFormCancel = () => {
    this.hideForm();
  };

  /**
   * @description handle Question Item on click
   * @param {Object} data question data
   */
  handleClickOnItem = (data) => {
    this.setState({
      showForm: true,
      clickedQuestion: data,
    });
  };

  /**
   * @description handle click on delete icon
   * @param {String} id
   */
  handleOnDeleteItem = (id) => {
    if (window.confirm('Delete Question?')) {
      this.props.onDeleteQuestion(id);
    }
  };

  setDialogPropsForQestionList = () => ({
    title: 'Suggested Questions',
    actions: <AddQuestionBtn handleAddQuestion={this.handleAddQuestion} />,
    actionsContainerStyle: { padding: 20, textAlign: 'center' },
  });

  setDialogPropsForQuestionForm = () => ({
    title: `${this.state.clickedQuestion ? 'Update' : 'Add'} Questions`,
    actions: null,
    actionsContainerStyle: {},
  });

  renderQuestionList = () => {
    const { questions } = this.props;
    return (
      <QuetionsList
        clickOnItem={this.handleClickOnItem}
        onDelete={this.handleOnDeleteItem}
        questions={questions}
      />
    );
  };

  renderQuestionForm = () => {
    const { clickedQuestion } = this.state;
    return (
      <QuestionForm
        handleFormSubmit={this.handleFormSubmit}
        handleFormCancel={this.handleFormCancel}
        initialValues={clickedQuestion}
      />
    );
  };

  /**
   * @description render
   * @return {Object} JSX HTML Content
   */
  render() {
    const { showForm } = this.state;
    const { openDialog } = this.props;

    let content = this.renderQuestionList();
    let dialogProps = this.setDialogPropsForQestionList();

    if (showForm) {
      content = this.renderQuestionForm();
      dialogProps = this.setDialogPropsForQuestionForm();
    }

    return (
{'fraction_non_alphanumeric': 0.13250388802488336, 'fraction_numerical': 0.0006220839813374805, 'mean_word_length': 2.9919304779639977, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, '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': '3868103', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1877, 'n_words': 414}