<commit_before>import React from 'react';
import ReactTable from 'react-table';
import TextareaAutosize from 'react-autosize-textarea';
import LanguageForm from 'js/components/modalForms/languageForm';
import alertify from 'alertifyjs';
import {bem} from 'js/bem';
import {LoadingSpinner} from 'js/ui';
import {actions} from 'js/actions';
import {stores} from 'js/stores';
import {getLangString} from 'utils';
import {LOCKING_RESTRICTIONS} from 'js/components/locking/lockingConstants';
import {
  MODAL_TYPES,
  QUESTION_TYPES,
  GROUP_TYPES_BEGIN,
} from 'js/constants';
import {
  hasRowRestriction,
  hasAssetRestriction,
} from 'js/components/locking/lockingUtils.es6';

const SAVE_BUTTON_TEXT = {
  DEFAULT: t('Save Changes'),
  UNSAVED: t('* Save Changes'),
  PENDING: t('Saving…'),
};

export class TranslationTable extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      saveChangesButtonText: SAVE_BUTTON_TEXT.DEFAULT,
      isSaveChangesButtonPending: false,
      tableData: [],
      showLanguageForm: false,
      langString: props.langString,
    };
    stores.translations.setTranslationTableUnsaved(false);
    const {translated, survey, choices, translations} = props.asset.content;
    const langIndex = props.langIndex;
    const editableColTitle =
      langIndex == 0 ? t('updated text') : t('translation');

    // add each translatable property for survey items to translation table
    survey.forEach((row) => {
      let isLabelLocked = false;
      if (row?.label) {
        isLabelLocked = this.isRowLabelLocked(row.type, row.name);
      }
      translated.forEach((property) => {
        if (row[property] && row[property][0]) {
          this.state.tableData.push({
            original: row[property][0],
            value: row[property][langIndex],
            name: row.name || row.$autoname,
            itemProp: property,
            contentProp: 'survey',
            isLabelLocked: isLabelLocked,
          });
        }
      });
    });

    // add choice options to translation table
    if (choices && choices.length) {
      choices.forEach((choice) => {
        let isLabelLocked = this.isChoiceLabelLocked(choice.name);
        console.dir(choice);
        if (choice.label && choice.label[0]) {
          this.state.tableData.push({
            original: choice.label[0],
            value: choice.label[langIndex],
            name: choice.name || choice.$autovalue,
            listName: choice.list_name,
            itemProp: 'label',
            contentProp: 'choices',
            isLabelLocked: isLabelLocked,
          });
        }
      });
    }

    this.columns = [
      {
        Header: t('Original string'),
        accessor: 'original',
        minWidth: 130,
        Cell: (cellInfo) => {
          // Disabling has no effect on this cell, but we do it to gray out the<commit_msg>lock choices if a parent question has restriction<commit_after>import React from 'react';
import ReactTable from 'react-table';
import TextareaAutosize from 'react-autosize-textarea';
import LanguageForm from 'js/components/modalForms/languageForm';
import alertify from 'alertifyjs';
import {bem} from 'js/bem';
import {LoadingSpinner} from 'js/ui';
import {actions} from 'js/actions';
import {stores} from 'js/stores';
import {getLangString} from 'utils';
import {LOCKING_RESTRICTIONS} from 'js/components/locking/lockingConstants';
import {
  MODAL_TYPES,
  QUESTION_TYPES,
  GROUP_TYPES_BEGIN,
} from 'js/constants';
import {
  hasRowRestriction,
  hasAssetRestriction,
} from 'js/components/locking/lockingUtils.es6';

const SAVE_BUTTON_TEXT = {
  DEFAULT: t('Save Changes'),
  UNSAVED: t('* Save Changes'),
  PENDING: t('Saving…'),
};

export class TranslationTable extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      saveChangesButtonText: SAVE_BUTTON_TEXT.DEFAULT,
      isSaveChangesButtonPending: false,
      tableData: [],
      showLanguageForm: false,
      langString: props.langString,
    };
    stores.translations.setTranslationTableUnsaved(false);
    const {translated, survey, choices, translations} = props.asset.content;
    const langIndex = props.langIndex;
    const editableColTitle =
      langIndex == 0 ? t('updated text') : t('translation');
    const lockedChoiceLists = [];

    // add each translatable property for survey items to translation table
    survey.forEach((row) => {
      let isLabelLocked = false;
      if (row?.label) {
        isLabelLocked = this.isRowLabelLocked(row.type, row.name);
      }

      // choices don't know what questions use them so we keep track of the
      // choice lists here to know if a question that uses them has
      // `choice_label_edit` enabled
      if (this.isChoiceLabelLocked(row.name) && row.select_from_list_name) {
        lockedChoiceLists.push(row.select_from_list_name);
      }

      translated.forEach((property) => {
        if (row[property] && row[property][0]) {
          this.state.tableData.push({
            original: row[property][0],
            value: row[property][langIndex],
            name: row.name || row.$autoname,
            itemProp: property,
            contentProp: 'survey',
            isLabelLocked: isLabelLocked,
          });
        }
      });
    });

    // add choice options to translation table
    if (choices && choices.length) {
      choices.forEach((choice) => {
        let isLabelLocked = lockedChoiceLists.includes(choice.list_name);
        if (choice.label && choice.label[0]) {
          this.state.tableData.push({
            original: choice.label[0],
            value: choice.label[langIndex],
            name: choice.name || choice.$autovalue,
            listName: choice.list_name,
            itemProp: 'label',
            contentProp: 'choices',
            isLabelLocked: isLabelLocked,
          });
        }
      });
    }

    this.columns = [
      {
        Header: t('Original string'),
        accessor: 'original',
        minWidth: 130,
        Cell: (cellInfo) => {
          // Disabling has no effect on this cell, but we do it to gray out the
{'fraction_non_alphanumeric': 0.11809741000162893, 'fraction_numerical': 0.0029320736276266493, 'mean_word_length': 2.7807881773399017, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '1557260', 'n_tokens_mistral': 1804, 'n_tokens_neox': 1791, 'n_words': 428}