<commit_before>

import React, { PropTypes } from 'react';
import Helmet from 'react-helmet';
import _ from 'lodash';
//
import * as Basic from '../../components/basic';
import * as Advanced from '../../components/advanced';
import DecisionButtons from './DecisionButtons';

/**
 * Default component for render task detail.
 * Detail is compound from basic fields (name of task, name of applicant ...) and
 * dynamic compoentns. Dynamic components are generated by task definition.
 */
class DynamicTaskDetail extends Basic.AbstractContent {

  constructor(props) {
    super(props);
    this.state = {showLoading: props.showLoading, readOnly: true};
  }

  getContentKey() {
    return 'content.task.instance';
  }

  _toFormDataValues(formDatas) {
    const result = {};
    for (const formData of formDatas) {
      result[formData.id] = formData.value;
    }
    return result;
  }

  _toFormData(formDataValues, formDatas) {
    const result = _.merge({}, formDataValues);
    for (const formData of formDatas) {
      if (!formData.writable && !formData.required) {
        delete result[formData.id];
      }
    }
    return result;
  }

  _validateAndCompleteTask(decision) {
    if (!this.refs.form.isFormValid()) {
      return;
    }
    if (this.refs.formData && !this.refs.formData.isFormValid()) {
      return;
    }
    if (decision.showWarning) {
      this.refs.confirm.show(this.i18n(decision.warningMessage ? decision.warningMessage : 'completeTaskConfirmDetail'), this.i18n('completeTaskConfirmTitle'))
      .then(() => {
        this._completeTask(decision);
      }, () => {
        // Rejected
      });
    } else {
      this._completeTask(decision);
    }
  }

  _completeTask(decision) {
    const formDataValues = this.refs.formData ? this.refs.formData.getData() : {};
    const task = this.refs.form.getData();
    const formData = {'decision': decision.id, 'formData': this._toFormData(formDataValues, task.formData)};
    // this.setState({
    //   showLoading: true
    // });<commit_msg>#614 - Show loading for dynamic task - fixed<commit_after>

import React, { PropTypes } from 'react';
import Helmet from 'react-helmet';
import _ from 'lodash';
//
import * as Basic from '../../components/basic';
import * as Advanced from '../../components/advanced';
import DecisionButtons from './DecisionButtons';

/**
 * Default component for render task detail.
 * Detail is compound from basic fields (name of task, name of applicant ...) and
 * dynamic compoentns. Dynamic components are generated by task definition.
 */
class DynamicTaskDetail extends Basic.AbstractContent {

  constructor(props) {
    super(props);
    this.state = {showLoading: props.showLoading, readOnly: true};
  }

  getContentKey() {
    return 'content.task.instance';
  }

  _toFormDataValues(formDatas) {
    const result = {};
    for (const formData of formDatas) {
      result[formData.id] = formData.value;
    }
    return result;
  }

  _toFormData(formDataValues, formDatas) {
    const result = _.merge({}, formDataValues);
    for (const formData of formDatas) {
      if (!formData.writable && !formData.required) {
        delete result[formData.id];
      }
    }
    return result;
  }

  _validateAndCompleteTask(decision) {
    if (!this.refs.form.isFormValid()) {
      return;
    }
    if (this.refs.formData && !this.refs.formData.isFormValid()) {
      return;
    }
    if (decision.showWarning) {
      this.refs.confirm.show(this.i18n(decision.warningMessage ? decision.warningMessage : 'completeTaskConfirmDetail'), this.i18n('completeTaskConfirmTitle'))
      .then(() => {
        this._completeTask(decision);
      }, () => {
        // Rejected
      });
    } else {
      this._completeTask(decision);
    }
  }

  _completeTask(decision) {
    const formDataValues = this.refs.formData ? this.refs.formData.getData() : {};
    const task = this.refs.form.getData();
    const formData = {'decision': decision.id, 'formData': this._toFormData(formDataValues, task.formData)};
    this.setState({
      showLoading: true
    });
{'fraction_non_alphanumeric': 0.13531434184675836, 'fraction_numerical': 0.0027013752455795677, 'mean_word_length': 3.1224696356275303, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '7152217', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1213, 'n_words': 278}