<commit_before>import React from 'react'
import { PropTypes } from 'react'
// import Text from './Text'

// NOTE: importing the non-wrapped provide() version
import FormCategory from './FormCategory'
import { getIndexOfElementById, removeItem, moveItemDown, moveItemUp } from './FormInteractions'
import ProviderHelpers from 'common/ProviderHelpers'
import provide from 'react-redux-provide'
import selectn from 'selectn'
import BrowseComponent from 'views/components/Editor/BrowseComponent'
const { string, array, object, func, number } = PropTypes

export class FormCategories extends React.Component {
  static propTypes = {
    name: string.isRequired,
    className: string,
    textInfo: string,
    items: array,
    idDescribedbyItemBrowse: string,
    idDescribedByItemMove: string,
    textDescribedbyItemBrowse: string,
    textDescribedByItemMove: string,
    textLegendItems: string,
    textBtnAddItem: string,
    textLegendItem: string,
    textBtnRemoveItem: string,
    textBtnMoveItemUp: string,
    textBtnMoveItemDown: string,
    textBtnCreateItem: string,
    textBtnSelectExistingItems: string,
    textLabelItemSearch: string,
    DEFAULT_PAGE: number,
    DEFAULT_PAGE_SIZE: number,
    DEFAULT_LANGUAGE: string,
    DEFAULT_SORT_COL: string,
    DEFAULT_SORT_TYPE: string,
    // REDUX/PROVIDE
    computeCategories: object.isRequired,
    computeDialect: object.isRequired,
    fetchCategories: func.isRequired,
    fetchDialect: func.isRequired,
    fetchResources: func.isRequired,
    splitWindowPath: array.isRequired,
  }
  static defaultProps = {
    className: 'FormCategories',
    idDescribedbyItemBrowse: 'describedbyCategoryBrowse',
    idDescribedByItemMove: 'describedByCategoryMove',
    name: 'FormCategories',
    textDescribedbyItemBrowse: 'Select a category from previously created categories',
    textDescribedByItemMove: `If you are adding multiple Categories, you can change the position of the category with
    the 'Move Category left' and 'Move Category right' buttons`,
    textLegendItems: 'Categories',
    textBtnAddItem: 'Add Category',
    textLegendItem: 'Category',
    textBtnRemoveItem: 'Remove Category',
    textBtnMoveItemUp: 'Move Category left',
    textBtnMoveItemDown: 'Move Category right',
    textBtnCreateItem: 'Create new category',
    textBtnSelectExistingItems: 'Select from existing categories',
    textLabelItemSearch: 'Search existing categories',
    DEFAULT_PAGE: 1,
    DEFAULT_PAGE_SIZE: 100,
    DEFAULT_LANGUAGE: 'english',
    DEFAULT_SORT_COL: 'dc:title',
    DEFAULT_SORT_TYPE: 'asc',
  }

  state = {
    items: [],
    loading: true,
    categories: [],
  }

  // Fetch data on initial render
  async componentDidMount() {
    const { fetchCategories, splitWindowPath } = this.props
    const categoriesPath = '/api/v1/path/FV/Workspaces/SharedData/Shared Categories/@children'
    await fetchCategories(categoriesPath)

    const dialect = await selectn('response', this.props.computeDialect)
    if (dialect) {
      this.setState({
        loading: false,
        dialect,
        dialectPath: ProviderHelpers.getDialectPathFromURLArray(splitWindowPath),
      })
    }
  }

  render() {
    const {
      className,
      idDescribedbyItemBrowse,
      idDescribedByItemMove,
      textDescribedbyItemBrowse,
      textDescribedByItemMove,
      textLegendItems,
    } = this.props

    const items = this.state.items

    return (
      <fieldset className={className}>
        <legend>{textLegendItems}</legend>

        <BrowseComponent
          type="FVCategory"
          label="Select from existing categories"
          onComplete={this.handleItemSelected}
          disabled={this.state.dialect === undefined}
          dialect={this.state.dialect}
          containerType="FVWord"
        />

        {items}

        {/* SCREEN READER DESCRIPTIONS --------------- */}
        <span id={idDescribedbyItemBrowse} className="visually-hidden"><commit_msg>Defensive loading of component (for undef)<commit_after>import React from 'react'
import { PropTypes } from 'react'
// import Text from './Text'

// NOTE: importing the non-wrapped provide() version
import FormCategory from './FormCategory'
import { getIndexOfElementById, removeItem, moveItemDown, moveItemUp } from './FormInteractions'
import ProviderHelpers from 'common/ProviderHelpers'
import provide from 'react-redux-provide'
import selectn from 'selectn'
import BrowseComponent from 'views/components/Editor/BrowseComponent'
const { string, array, object, func, number } = PropTypes

export class FormCategories extends React.Component {
  static propTypes = {
    name: string.isRequired,
    className: string,
    textInfo: string,
    items: array,
    idDescribedbyItemBrowse: string,
    idDescribedByItemMove: string,
    textDescribedbyItemBrowse: string,
    textDescribedByItemMove: string,
    textLegendItems: string,
    textBtnAddItem: string,
    textLegendItem: string,
    textBtnRemoveItem: string,
    textBtnMoveItemUp: string,
    textBtnMoveItemDown: string,
    textBtnCreateItem: string,
    textBtnSelectExistingItems: string,
    textLabelItemSearch: string,
    DEFAULT_PAGE: number,
    DEFAULT_PAGE_SIZE: number,
    DEFAULT_LANGUAGE: string,
    DEFAULT_SORT_COL: string,
    DEFAULT_SORT_TYPE: string,
    // REDUX/PROVIDE
    computeCategories: object.isRequired,
    computeDialect: object.isRequired,
    fetchCategories: func.isRequired,
    fetchDialect: func.isRequired,
    fetchResources: func.isRequired,
    splitWindowPath: array.isRequired,
  }
  static defaultProps = {
    className: 'FormCategories',
    idDescribedbyItemBrowse: 'describedbyCategoryBrowse',
    idDescribedByItemMove: 'describedByCategoryMove',
    name: 'FormCategories',
    textDescribedbyItemBrowse: 'Select a category from previously created categories',
    textDescribedByItemMove: `If you are adding multiple Categories, you can change the position of the category with
    the 'Move Category left' and 'Move Category right' buttons`,
    textLegendItems: 'Categories',
    textBtnAddItem: 'Add Category',
    textLegendItem: 'Category',
    textBtnRemoveItem: 'Remove Category',
    textBtnMoveItemUp: 'Move Category left',
    textBtnMoveItemDown: 'Move Category right',
    textBtnCreateItem: 'Create new category',
    textBtnSelectExistingItems: 'Select from existing categories',
    textLabelItemSearch: 'Search existing categories',
    DEFAULT_PAGE: 1,
    DEFAULT_PAGE_SIZE: 100,
    DEFAULT_LANGUAGE: 'english',
    DEFAULT_SORT_COL: 'dc:title',
    DEFAULT_SORT_TYPE: 'asc',
  }

  state = {
    items: [],
    loading: true,
    categories: [],
  }

  // Fetch data on initial render
  async componentDidMount() {
    const { fetchCategories, splitWindowPath } = this.props
    const categoriesPath = '/api/v1/path/FV/Workspaces/SharedData/Shared Categories/@children'
    await fetchCategories(categoriesPath)

    const dialect = await selectn('response', this.props.computeDialect)
    if (dialect) {
      this.setState({
        loading: false,
        dialect,
        dialectPath: ProviderHelpers.getDialectPathFromURLArray(splitWindowPath),
      })
    }
  }

  render() {
    const {
      className,
      idDescribedbyItemBrowse,
      idDescribedByItemMove,
      textDescribedbyItemBrowse,
      textDescribedByItemMove,
      textLegendItems,
    } = this.props

    const items = this.state.items

    return (
      <fieldset className={className}>
        <legend>{textLegendItems}</legend>

        {this.state.dialect && BrowseComponent && (
          <BrowseComponent
            type="FVCategory"
            label="Select from existing categories"
            onComplete={this.handleItemSelected}
            disabled={this.state.dialect === undefined}
            dialect={this.state.dialect}
            containerType="FVWord"
          />
        )}

        {items}

        {/* SCREEN READER DESCRIPTIONS --------------- */}
        <span id={idDescribedbyItemBrowse} className="visually-hidden">
{'fraction_non_alphanumeric': 0.0922003488661849, 'fraction_numerical': 0.00124595066035385, 'mean_word_length': 3.5868571428571427, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '4828944', 'n_tokens_mistral': 2343, 'n_tokens_neox': 2278, 'n_words': 544}