<commit_before>import _ from 'underscore';
import React from 'react';
import Router from 'react-router';
import Input from 'react-bootstrap/lib/Input'
import TextBox from '../../components/editors/TextBox';
import MetaForm from '../../components/MetaForm';
import metadataProvider from '../../lib/metadataProvider.js';
import Alert from 'react-bootstrap/lib/Alert'

import clientActions from '../../flux/actions/clientActions.js';
import clientStores from '../../flux/stores/clientStores.js';


var Home = React.createClass({

    componentDidMount: function() {
        // logged user
        clientStores.applicationDomain.addChangeListener(this.applicationDomainChanged);
        clientActions.applicationDomain.loadApplicationDomain();
    },

    applicationDomainChanged: function() {
        this.setState({
            applicationDomain: clientStores.applicationDomain.getApplicationDomain()
        });
    },

    render: function() {

        // if the application domain hasn't been loaded already
        if(!this.state || !this.state.applicationDomain) {
            return (
                <div className="document">
                    <div className="document-header">Editing {this.props.params.entity}</div>
                    <div className="document-body">
                        <div> Editing: {this.props.params.entity}. Id: {this.props.params.id} </div>
                    </div>
                </div>
            );
        }

        let entityName = this.props.params.entity;
        let applicationDomain = this.state.applicationDomain;

        // try to find the appropriate entity
        let entity = _.find(applicationDomain.entities, e => e.name == entityName);
        if(!entity) {
            return (
                <div className="document">
                    <div className="document-header">Editing... Oh wait. Editing what?</div>
                    <div className="document-body">
                        <Alert bsStyle='danger'>
                            <h4>Oh snap! Cound not find entity: <b>{entityName}</b> </h4>
                        </Alert>
                    </div>
                </div>
            );
        }

        // if the application domain has loaded successfully
        return (
            <div className="document">
                <div className="document-header">Editing {this.props.params.entity}</div>
                <div className="document-body">
                    <MetaForm
                        schema={schema}
                        entityName='contact'
                        layoutName='contact-edit'
                        model={model}
                        title='Editing contact'/>
                </div>
            </div>
        );
    }
});

export default Home;<commit_msg>Edit view is starting to understand layouts<commit_after>import _ from 'underscore';
import React from 'react';
import Router from 'react-router';
import Input from 'react-bootstrap/lib/Input'
import TextBox from '../../components/editors/TextBox';
import MetaForm from '../../components/MetaForm';
import metadataProvider from '../../lib/metadataProvider.js';
import Alert from 'react-bootstrap/lib/Alert'

import clientActions from '../../flux/actions/clientActions.js';
import clientStores from '../../flux/stores/clientStores.js';


var Home = React.createClass({

    componentDidMount: function() {
        // logged user
        clientStores.applicationDomain.addChangeListener(this.applicationDomainChanged);
        clientActions.applicationDomain.loadApplicationDomain();
    },

    applicationDomainChanged: function() {
        this.setState({
            applicationDomain: clientStores.applicationDomain.getApplicationDomain()
        });
    },

    render: function() {

        // if the application domain hasn't been loaded already
        if(!this.state || !this.state.applicationDomain) {
            return (
                <div className="document">
                    <div className="document-header">Editing {this.props.params.entity}</div>
                    <div className="document-body">
                        <div> Editing: {this.props.params.entity}. Id: {this.props.params.id} </div>
                    </div>
                </div>
            );
        }

        let entityName = this.props.params.entity;
        let layoutName = this.props.params.layout;
        let applicationDomain = this.state.applicationDomain;

        // try to find the appropriate entity
        let entity = _.find(applicationDomain.entities, e => e.name == entityName);
        if(!entity) {
            return (
                <div className="document">
                    <div className="document-header">Editing... Oh wait. Editing what?</div>
                    <div className="document-body">
                        <Alert bsStyle='danger'>
                            <h4>Oh snap! Cound not find entity: <b>{entityName}</b> </h4>
                        </Alert>
                    </div>
                </div>
            );
        }

        if(!layoutName) {
            if (entity.defaultLayouts && entity.defaultLayouts.edit) {
                layoutName = entity.defaultLayouts.edit;
            }
            else {
                layoutName = `${entityName}-edit`;
            }
        }
        let layout = _.find(applicationDomain.layouts, e => e.name == layoutName);
        if(!layout) {
            return (
                <div className="document">
                    <div className="document-header">Editing {this.props.params.entity}</div>
                    <div className="document-body">
                        <Alert bsStyle='danger'>
                            <h4>Oh snap! The entity is fine, but couldn't find the layout: <b>{layoutName}</b> </h4>
                        </Alert>
                    </div>
                </div>
            );
        }

        // if the application domain has loaded successfully
        return (
            <div className="document">
                <div className="document-header">Editing {this.props.params.entity}</div>
                <div className="document-body">
                    <MetaForm
                        schema={applicationDomain}
                        entityName={entityName}
                        layoutName={layoutName}
                        model={{}}
                        title={`Editing ${entityName}`}/>
                </div>
            </div>
        );
    }
});

export default Home;
{'fraction_non_alphanumeric': 0.11970534069981584, 'fraction_numerical': 0.0009208103130755065, 'mean_word_length': 1.6556642216788917, 'pattern_counts': {'":': 0, '<': 69, '<?xml version=': 0, '>': 72, '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': '5080875', 'n_tokens_mistral': 1607, 'n_tokens_neox': 1526, 'n_words': 352}