<commit_before>var React = require('react');
var classnames = require('classnames');

var styles = require('./StructuredElement.less');

var StructuredElement;

StructuredElement = React.createClass({
    propTypes: {
        element: React.PropTypes.any.isRequired,
        subComponent: React.PropTypes.func,
        arraysInitiallyCollapsed: React.PropTypes.bool,
        initiallyCollapsedItems: React.PropTypes.array
    },

    getDefaultProps() {
        return {
            subComponent: null,
            arraysInitiallyCollapsed: false,
            initiallyCollapsedItems: []
        };
    },

    getInitialState() {
        var collapsed = {};
        this.props.initiallyCollapsedItems.forEach(item => collapsed[item] = true);
        return {
            collapsedItems: collapsed,
            arrayCollapsed: this.props.arraysInitiallyCollapsed
        };
    },

    toggleObjectCollapse(item) {
        var collapsedItems = _.clone(this.state.collapsedItems);
        collapsedItems[item] = !collapsedItems[item];
        this.setState({ collapsedItems });
    },

    toggleArrayCollapse() {
        this.setState({ arrayCollapsed: !this.state.arrayCollapsed });
    },

    renderItem(item) {
        if (Array.isArray(item)) {
            return this.renderArray(item);
        }
        if (typeof item === 'object' && item !== null) {
            return this.renderObject(item);
        }
        return this.renderPrimitive(item);
    },

    renderArray(array) {
        var items = array.map(function (item, ndx) {
            return (
                <div className='array-item' key={ndx}>
                    <div className='array-item-marker'
                         onClick={this.toggleArrayCollapse}>
                    </div>
                    <div className='array-item-content'>
                        {this.renderSubItem(item)}
                    </div>
                </div>
            );
        }.bind(this));

        var collapsed = (
            <div className='array-item collapsed'
                 onClick={this.toggleArrayCollapse}>
            </div>
        );

        return (
            <div
                className={classnames('array', { empty: !items.length })}>
                {(this.state.arrayCollapsed && items.length) ? collapsed : items}
            </div>
        );
    },

    renderSubItem(item) {
        var component = this.props.subComponent || StructuredElement;
        return (<component element={item}/>);
    },

    renderExpandableValue(key, value) {
        if (!this.state.collapsedItems[key]) {
            return this.renderSubItem(value);
        }
        return (
            <div className='object-collapsed'
                 onClick={this.toggleObjectCollapse.bind(this, key)}>
            </div>
        );
    },

    renderObject(object) {
        var objectProps = Object.keys(object).sort().map(function (key) {<commit_msg>Fix StructuredElement default subComponent rendering<commit_after>var React = require('react');
var classnames = require('classnames');

var styles = require('./StructuredElement.less');

var StructuredElement;
StructuredElement = React.createClass({
    propTypes: {
        element: React.PropTypes.any.isRequired,
        subComponent: React.PropTypes.func,
        arraysInitiallyCollapsed: React.PropTypes.bool,
        initiallyCollapsedItems: React.PropTypes.array
    },

    getDefaultProps() {
        return {
            subComponent: null,
            arraysInitiallyCollapsed: false,
            initiallyCollapsedItems: []
        };
    },

    getInitialState() {
        var collapsed = {};
        this.props.initiallyCollapsedItems.forEach(item => collapsed[item] = true);
        return {
            collapsedItems: collapsed,
            arrayCollapsed: this.props.arraysInitiallyCollapsed
        };
    },

    toggleObjectCollapse(item) {
        var collapsedItems = _.clone(this.state.collapsedItems);
        collapsedItems[item] = !collapsedItems[item];
        this.setState({ collapsedItems });
    },

    toggleArrayCollapse() {
        this.setState({ arrayCollapsed: !this.state.arrayCollapsed });
    },

    renderItem(item) {
        if (Array.isArray(item)) {
            return this.renderArray(item);
        }
        if (typeof item === 'object' && item !== null) {
            return this.renderObject(item);
        }
        return this.renderPrimitive(item);
    },

    renderArray(array) {
        var items = array.map(function (item, ndx) {
            return (
                <div className='array-item' key={ndx}>
                    <div className='array-item-marker'
                         onClick={this.toggleArrayCollapse}>
                    </div>
                    <div className='array-item-content'>
                        {this.renderSubItem(item)}
                    </div>
                </div>
            );
        }.bind(this));

        var collapsed = (
            <div className='array-item collapsed'
                 onClick={this.toggleArrayCollapse}>
            </div>
        );

        return (
            <div
                className={classnames('array', { empty: !items.length })}>
                {(this.state.arrayCollapsed && items.length) ? collapsed : items}
            </div>
        );
    },

    renderSubItem(item) {
        if (this.props.subComponent) {
            return <this.props.subComponent element={item}/>;
        }
        return <StructuredElement element={item}/>;
    },

    renderExpandableValue(key, value) {
        if (!this.state.collapsedItems[key]) {
            return this.renderSubItem(value);
        }
        return (
            <div className='object-collapsed'
                 onClick={this.toggleObjectCollapse.bind(this, key)}>
            </div>
        );
    },

    renderObject(object) {
        var objectProps = Object.keys(object).sort().map(function (key) {
{'fraction_non_alphanumeric': 0.12084948592617563, 'fraction_numerical': 0.0, 'mean_word_length': 1.869439071566731, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 32, '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': '1345437', 'n_tokens_mistral': 1573, 'n_tokens_neox': 1541, 'n_words': 263}