<commit_before>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { injectIntl, intlShape } from 'react-intl';

import Toggle from 'material-ui/Toggle';
import NarrowEditor from './NarrowEditor';
import WideEditor from './WideEditor';
import { annotationShape } from '../../propTypes';
import translations from '../../translations';

const EDITOR_MODE_NARROW = 'narrow';
const EDITOR_MODE_WIDE = 'wide';

class ReadOnlyEditor extends Component {
  constructor(props) {
    super(props);

    const expanded = [];
    for (let i = 0; i < props.content.length; i += 1) {
      expanded.push(false);
    }

    const initialEditorMode =
      props.annotations.length > 0 ? EDITOR_MODE_WIDE : EDITOR_MODE_NARROW;
    this.state = { expanded, editorMode: initialEditorMode };

    this.showCommentsPanel = this.showCommentsPanel.bind(this);
  }

  componentDidUpdate(prevProps) {
    const { expanded } = this.state;

    // We only want to minimize the annotation/comment popup line that is added/deleted which can be
    // computed by getting the differences of lines before and after the operation.
    const annotationLinesPrev = prevProps.annotations.map(
      (annotation) => annotation.line,
    );
    const annotationLinesNext = this.props.annotations.map(
      (annotation) => annotation.line,
    );
    // If an annotation is deleted
    const updatedLineLeft = annotationLinesPrev.filter(
      (x) => !annotationLinesNext.includes(x),
    );
    // If an annotation is added
    const updatedLineRight = annotationLinesNext.filter(
      (x) => !annotationLinesPrev.includes(x),
    );
    const updatedLine = [...updatedLineLeft, ...updatedLineRight];

    const newExpanded = expanded.slice(0);
    newExpanded[updatedLine[0] - 1] = false;

    if (updatedLine.length > 0) {
      // eslint-disable-next-line react/no-did-update-set-state<commit_msg>refactor(annotation box): update variable naming<commit_after>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { injectIntl, intlShape } from 'react-intl';

import Toggle from 'material-ui/Toggle';
import NarrowEditor from './NarrowEditor';
import WideEditor from './WideEditor';
import { annotationShape } from '../../propTypes';
import translations from '../../translations';

const EDITOR_MODE_NARROW = 'narrow';
const EDITOR_MODE_WIDE = 'wide';

class ReadOnlyEditor extends Component {
  constructor(props) {
    super(props);

    const expanded = [];
    for (let i = 0; i < props.content.length; i += 1) {
      expanded.push(false);
    }

    const initialEditorMode =
      props.annotations.length > 0 ? EDITOR_MODE_WIDE : EDITOR_MODE_NARROW;
    this.state = { expanded, editorMode: initialEditorMode };

    this.showCommentsPanel = this.showCommentsPanel.bind(this);
  }

  componentDidUpdate(prevProps) {
    const { expanded } = this.state;

    // We only want to minimize the annotation/comment popup line that is added/deleted which can be
    // computed by getting the differences of lines before and after the operation.
    const annotationLinesPrev = prevProps.annotations.map(
      (annotation) => annotation.line,
    );
    const annotationLinesNext = this.props.annotations.map(
      (annotation) => annotation.line,
    );
    // If an annotation is deleted
    const deletedAnnotationLine = annotationLinesPrev.filter(
      (x) => !annotationLinesNext.includes(x),
    );
    // If an annotation is added
    const addedAnnotationLine = annotationLinesNext.filter(
      (x) => !annotationLinesPrev.includes(x),
    );
    const updatedLine = [...deletedAnnotationLine, ...addedAnnotationLine];

    if (updatedLine.length > 0) {
      const newExpanded = expanded.slice(0);
      newExpanded[updatedLine[0] - 1] = false;
      // eslint-disable-next-line react/no-did-update-set-state
{'fraction_non_alphanumeric': 0.11598339387649195, 'fraction_numerical': 0.0036325895173845357, 'mean_word_length': 3.5246478873239435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '5278124', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1083, 'n_words': 293}