<commit_before>import React from 'react'
import RichTextEditor from 'react-rte'

const toolbarConfig = {
  // Optionally specify the groups to display (displayed in the order listed).
  display: ['INLINE_STYLE_BUTTONS', 'BLOCK_TYPE_BUTTONS', 'LINK_BUTTONS', 'BLOCK_TYPE_DROPDOWN'],
  INLINE_STYLE_BUTTONS: [
    {label: 'Bold', style: 'BOLD'},
    {label: 'Italic', style: 'ITALIC'},
    {label: 'Underline', style: 'UNDERLINE'}
  ],
  BLOCK_TYPE_DROPDOWN: [
    {label: 'Normal', style: 'unstyled'},
    {label: 'Heading Large', style: 'header-one'},
    {label: 'Heading Medium', style: 'header-two'},
    {label: 'Heading Small', style: 'header-three'}
  ],
  BLOCK_TYPE_BUTTONS: [
    {label: 'UL', style: 'unordered-list-item'},
    {label: 'OL', style: 'ordered-list-item'}
  ]
}
class RTE extends React.Component {
  constructor(props){
    super(props)
    const state = {}
    if(props.value !== '' && props.value !== undefined){
      state.value = RichTextEditor.createValueFromString(props.value, 'markdown')
    } else {
      state.value = RichTextEditor.createEmptyValue()
    }
    this.state = state
  }
  componentDidUpdate(prevProps){
    if (prevProps.value !== this.props.value && this.props.value === '') {
      setTimeout(() => {
        this.setState({ value: RichTextEditor.createEmptyValue() })
      })
    }
  }
  handleChange = (value) => {
    this.setState({ value })
    if(this.props.onChange){
      this.props.onChange(value.toString('markdown'))
    }
  }
  render(){
    const { disabled, placeholder } = this.props
    const { value } = this.state
    return (
      <RichTextEditor className="rte" onChange={this.handleChange} {...{ value, toolbarConfig, disabled, placeholder }} />
    )
  }
}
<commit_msg>[#4441] RTE to handle prop value updates<commit_after>import React from 'react'
import RichTextEditor from 'react-rte'

const toolbarConfig = {
  // Optionally specify the groups to display (displayed in the order listed).
  display: ['INLINE_STYLE_BUTTONS', 'BLOCK_TYPE_BUTTONS', 'LINK_BUTTONS', 'BLOCK_TYPE_DROPDOWN'],
  INLINE_STYLE_BUTTONS: [
    {label: 'Bold', style: 'BOLD'},
    {label: 'Italic', style: 'ITALIC'},
    {label: 'Underline', style: 'UNDERLINE'}
  ],
  BLOCK_TYPE_DROPDOWN: [
    {label: 'Normal', style: 'unstyled'},
    {label: 'Heading Large', style: 'header-one'},
    {label: 'Heading Medium', style: 'header-two'},
    {label: 'Heading Small', style: 'header-three'}
  ],
  BLOCK_TYPE_BUTTONS: [
    {label: 'UL', style: 'unordered-list-item'},
    {label: 'OL', style: 'ordered-list-item'}
  ]
}
class RTE extends React.Component {
  constructor(props){
    super(props)
    const state = {}
    if(props.value !== '' && props.value !== undefined){
      state.value = RichTextEditor.createValueFromString(props.value, 'markdown')
    } else {
      state.value = RichTextEditor.createEmptyValue()
    }
    this.state = state
  }
  componentDidUpdate(prevProps){
    if (prevProps.value !== this.props.value && this.props.value === '') {
      setTimeout(() => {
        this.setState({ value: RichTextEditor.createEmptyValue() })
      })
    }
    else if(this.props.value !== ''){
      setTimeout(() => {
        this.setState({ value: RichTextEditor.createValueFromString(this.props.value, 'markdown') })
      })
    }
  }
  handleChange = (value) => {
    this.setState({ value })
    if(this.props.onChange){
      this.props.onChange(value.toString('markdown'))
    }
  }
  render(){
    const { disabled, placeholder } = this.props
    const { value } = this.state
    return (
      <RichTextEditor className="rte" onChange={this.handleChange} {...{ value, toolbarConfig, disabled, placeholder }} />
    )
  }
}

{'fraction_non_alphanumeric': 0.16324324324324324, 'fraction_numerical': 0.001081081081081081, 'mean_word_length': 3.486060606060606, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '1529948', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1197, 'n_words': 249}