<commit_before>import React from 'react';
import classnames from 'classnames';
import update from 'immutability-helper';
import { StickyContainer, Sticky } from 'react-sticky';
import './Action.scss';

import Record from '../Record/Record';
import Attributes from '../Attribute/Attributes';
import EditorForm from '../EditorForm/EditorForm';
import Popup from 'components/Popup';
import Dropdown from 'components/Dropdown';
import TypeDropdown from '../TypeDropdown/TypeDropdown';
import DeleteView from '../DeleteView/DeleteView';
import ReorderView from '../Reorder/ReorderView';
import ImportView from '../ImportView/ImportView';

export class Action extends React.Component {
  constructor (props) {
    super(props);
    this.onTypeChange = this.onTypeChange.bind(this);
    this.onTypeInputChange = this.onTypeInputChange.bind(this);
    this.onTypeSpecifierChange = this.onTypeSpecifierChange.bind(this);
    this.createRecord = this.createRecord.bind(this);
    this.cancelRecordCreation = this.cancelRecordCreation.bind(this);
    this.editActionForm = this.editActionForm.bind(this);
    this.editActionWithForm = this.editActionWithForm.bind(this);
    this.editRecordForm = this.editRecordForm.bind(this);
    this.complementRecordForm = this.complementRecordForm.bind(this);
    this.editRecordWithForm = this.editRecordWithForm.bind(this);
    this.cancelRecordEdit = this.cancelRecordEdit.bind(this);
    this.cancelRecordComplement = this.cancelRecordComplement.bind(this);
    this.updateTypeSpecifier = this.updateTypeSpecifier.bind(this);
    this.updateActionType = this.updateActionType.bind(this);
    // this.updateActionAttribute = this.updateActionAttribute.bind(this);
    this.renderActionButtons = this.renderActionButtons.bind(this);
    this.renderBasicAttributes = this.renderBasicAttributes.bind(this);
    this.toggleAttributeVisibility = this.toggleAttributeVisibility.bind(this);
    this.disableEditMode = this.disableEditMode.bind(this);
    this.state = {
      typeSpecifier: this.props.action.attributes.TypeSpecifier || '(ei tarkennetta)',
      type: this.props.action.attributes.ActionType || '---',
      attributes: this.props.action.attributes,
      mode: 'view',
      editingTypeSpecifier: false,
      editingType: false,
      creatingRecord: false,
      editingRecord: false,
      complementingRecord: false,
      editingAction: false,
      complementingAction: false,
      deleting: false,
      showReorderView: false,
      showImportView: false,
      showAttributes: false
    };
  }

  componentWillReceiveProps (nextProps) {
    if (nextProps.action && nextProps.action.attributes.TypeSpecifier) {
      this.setState({ typeSpecifier: nextProps.action.attributes.TypeSpecifier });
    }
    if (nextProps.action && nextProps.action.attributes.ActionType) {
      this.setState({ type: nextProps.action.attributes.ActionType });
    }
    if (nextProps.documentState === 'view') {
      this.disableEditMode();
    }
  }

  toggleReorderView () {
    const current = this.state.showReorderView;
    this.setState({ showReorderView: !current });
  }

  toggleImportView () {
    const current = this.state.showImportView;
    this.setState({ showImportView: !current });
  }

  toggleAttributeVisibility () {
    const currentVisibility = this.state.showAttributes;
    const newVisibility = !currentVisibility;
    this.setState({ showAttributes: newVisibility });
  }

  editTypeSpecifier () {
    if (this.props.documentState === 'edit') {
      this.setState({ editingTypeSpecifier: true, mode: 'edit' });
    }
  }

  editType () {
    if (this.props.documentState === 'edit') {
      this.setState({ editingType: true, mode: 'edit' });
    }
  }

  editActionForm () {
    if (this.props.documentState === 'edit') {
      this.setState({ editingAction: true, mode: 'edit' });
    }
  }

  complementActionForm () {
    if (this.props.documentState === 'edit') {
      this.setState({ complementingAction: true, mode: 'edit' });
    }
  }

  disableEditMode () {
    this.setState({
      editingTypeSpecifier: false,
      editingType: false,
      editingAction: false,
      complementingAction: false,
      editingRecord: false,
      complementingRecord: false,
      mode: 'view'
    });
  }

  onChange (e) {
    this.setState({ name: e.target.value });
  }

  onTypeSpecifierChange (event) {
    this.setState({ typeSpecifier: event.target.value });
  }

  onTypeChange (value) {
    this.setState(update(this.state, {
      type: {
        $set: value
      }
    }));
  }

  onTypeInputChange (event) {
    this.setState({ type: event.target.value });
  }

  updateTypeSpecifier (event) {
    event.preventDefault();
    const updatedTypeSpecifier = {
      typeSpecifier: this.state.typeSpecifier,
      actionId: this.props.action.id
    };
    this.props.editActionAttribute(updatedTypeSpecifier);
    if (this.state.typeSpecifier.length > 0) {
      this.disableEditMode();
    }
  }

  updateActionType (event) {
    event.preventDefault();
    const updatedActionType = {
      type: this.state.type,
      actionId: this.props.action.id
    };
    this.props.editActionAttribute(updatedActionType);
    this.disableEditMode();
  }

  // updateActionAttribute (attribute, attributeIndex, actionId) {
  //   this.setState({
  //     attributes: {
  //       [attributeIndex]: attribute
  //     }
  //   });
  //   const updatedActionAttribute = { attribute, attributeIndex, actionId };
  //   this.props.editActionAttribute(updatedActionAttribute);
  // }

  editActionWithForm (attributes, actionId) {<commit_msg>Reveal function to edit Action attributes<commit_after>import React from 'react';
import classnames from 'classnames';
import update from 'immutability-helper';
import { StickyContainer, Sticky } from 'react-sticky';
import './Action.scss';

import Record from '../Record/Record';
import Attributes from '../Attribute/Attributes';
import EditorForm from '../EditorForm/EditorForm';
import Popup from 'components/Popup';
import Dropdown from 'components/Dropdown';
import TypeDropdown from '../TypeDropdown/TypeDropdown';
import DeleteView from '../DeleteView/DeleteView';
import ReorderView from '../Reorder/ReorderView';
import ImportView from '../ImportView/ImportView';

export class Action extends React.Component {
  constructor (props) {
    super(props);
    this.onTypeChange = this.onTypeChange.bind(this);
    this.onTypeInputChange = this.onTypeInputChange.bind(this);
    this.onTypeSpecifierChange = this.onTypeSpecifierChange.bind(this);
    this.createRecord = this.createRecord.bind(this);
    this.cancelRecordCreation = this.cancelRecordCreation.bind(this);
    this.editActionForm = this.editActionForm.bind(this);
    this.editActionWithForm = this.editActionWithForm.bind(this);
    this.editRecordForm = this.editRecordForm.bind(this);
    this.complementRecordForm = this.complementRecordForm.bind(this);
    this.editRecordWithForm = this.editRecordWithForm.bind(this);
    this.cancelRecordEdit = this.cancelRecordEdit.bind(this);
    this.cancelRecordComplement = this.cancelRecordComplement.bind(this);
    this.updateTypeSpecifier = this.updateTypeSpecifier.bind(this);
    this.updateActionType = this.updateActionType.bind(this);
    this.updateActionAttribute = this.updateActionAttribute.bind(this);
    this.renderActionButtons = this.renderActionButtons.bind(this);
    this.renderBasicAttributes = this.renderBasicAttributes.bind(this);
    this.toggleAttributeVisibility = this.toggleAttributeVisibility.bind(this);
    this.disableEditMode = this.disableEditMode.bind(this);
    this.state = {
      typeSpecifier: this.props.action.attributes.TypeSpecifier || '(ei tarkennetta)',
      type: this.props.action.attributes.ActionType || '---',
      attributes: this.props.action.attributes,
      mode: 'view',
      editingTypeSpecifier: false,
      editingType: false,
      creatingRecord: false,
      editingRecord: false,
      complementingRecord: false,
      editingAction: false,
      complementingAction: false,
      deleting: false,
      showReorderView: false,
      showImportView: false,
      showAttributes: false
    };
  }

  componentWillReceiveProps (nextProps) {
    if (nextProps.action && nextProps.action.attributes.TypeSpecifier) {
      this.setState({ typeSpecifier: nextProps.action.attributes.TypeSpecifier });
    }
    if (nextProps.action && nextProps.action.attributes.ActionType) {
      this.setState({ type: nextProps.action.attributes.ActionType });
    }
    if (nextProps.documentState === 'view') {
      this.disableEditMode();
    }
  }

  toggleReorderView () {
    const current = this.state.showReorderView;
    this.setState({ showReorderView: !current });
  }

  toggleImportView () {
    const current = this.state.showImportView;
    this.setState({ showImportView: !current });
  }

  toggleAttributeVisibility () {
    const currentVisibility = this.state.showAttributes;
    const newVisibility = !currentVisibility;
    this.setState({ showAttributes: newVisibility });
  }

  editTypeSpecifier () {
    if (this.props.documentState === 'edit') {
      this.setState({ editingTypeSpecifier: true, mode: 'edit' });
    }
  }

  editType () {
    if (this.props.documentState === 'edit') {
      this.setState({ editingType: true, mode: 'edit' });
    }
  }

  editActionForm () {
    if (this.props.documentState === 'edit') {
      this.setState({ editingAction: true, mode: 'edit' });
    }
  }

  complementActionForm () {
    if (this.props.documentState === 'edit') {
      this.setState({ complementingAction: true, mode: 'edit' });
    }
  }

  disableEditMode () {
    this.setState({
      editingTypeSpecifier: false,
      editingType: false,
      editingAction: false,
      complementingAction: false,
      editingRecord: false,
      complementingRecord: false,
      mode: 'view'
    });
  }

  onChange (e) {
    this.setState({ name: e.target.value });
  }

  onTypeSpecifierChange (event) {
    this.setState({ typeSpecifier: event.target.value });
  }

  onTypeChange (value) {
    this.setState(update(this.state, {
      type: {
        $set: value
      }
    }));
  }

  onTypeInputChange (event) {
    this.setState({ type: event.target.value });
  }

  updateTypeSpecifier (event) {
    event.preventDefault();
    const updatedTypeSpecifier = {
      typeSpecifier: this.state.typeSpecifier,
      actionId: this.props.action.id
    };
    this.props.editActionAttribute(updatedTypeSpecifier);
    if (this.state.typeSpecifier.length > 0) {
      this.disableEditMode();
    }
  }

  updateActionType (event) {
    event.preventDefault();
    const updatedActionType = {
      type: this.state.type,
      actionId: this.props.action.id
    };
    this.props.editActionAttribute(updatedActionType);
    this.disableEditMode();
  }

  updateActionAttribute (attribute, attributeIndex, actionId) {
    this.setState({
      attributes: {
        [attributeIndex]: attribute
      }
    });
    const updatedActionAttribute = { attribute, attributeIndex, actionId };
    this.props.editActionAttribute(updatedActionAttribute);
  }

  editActionWithForm (attributes, actionId) {
{'fraction_non_alphanumeric': 0.12310166160443095, 'fraction_numerical': 0.00017866714311238162, 'mean_word_length': 3.6183993399339935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '348005', 'n_tokens_mistral': 3233, 'n_tokens_neox': 3266, 'n_words': 587}