<commit_before>"use strict";
/*global _*/

import ColumnarSelector from "./columnar_selector.react";

export default React.createClass({
    displayName: "FieldSelector",
    propTypes: {
        field: React.PropTypes.oneOfType([React.PropTypes.number, React.PropTypes.array]),
        fieldOptions: React.PropTypes.object.isRequired,
        tableName: React.PropTypes.string,
        setField: React.PropTypes.func.isRequired
    },

    render: function() {
        var sourceTable = {
            title: this.props.tableName || null,
            field: null
        };

        if (!this.props.fieldOptions) {
            return <div>blah</div>;
        }

        var connectionTables = this.props.fieldOptions.fks
            .map((fk) => {
                return {
                    title: fk.field.display_name,
                    subtitle: this.props.tableName || null,
                    field: ["fk->", fk.field.id, null],
                    fieldId: fk.field.id
                };
            });

        var tableSections = [
            {
                title: "Source",
                items: [sourceTable]
            }
        ];
        if (connectionTables.length > 0) {
            tableSections.push({
                title: "Connections",
                items: connectionTables
            });
        }

        var tableColumn = {
            sections: tableSections,
            selectedItem: null,
            itemTitleFn: (table) => {
                var subtitleElement = table.subtitle ? <div className="text-grey-3 mb1">{table.subtitle}</div> : null;
                return (
                    <div>
                        {subtitleElement}
                        <div>{table.title}</div>
                    </div>
                );
            },
            itemSelectFn: (table) => {
                this.props.setField(table.field);
            }
        }

        var fieldColumn = {
            items: null,
            selectedItem: null,
            itemTitleFn: (field) => field.display_name,
            itemSelectFn: null
        };

        if (this.props.field == undefined || typeof this.props.field === "number") {
            tableColumn.selectedItem = sourceTable;
            fieldColumn.items = this.props.fieldOptions.fields;
            fieldColumn.selectedItem = _.find(this.props.fieldOptions.fields, (f) => f.id === this.props.field);
            fieldColumn.itemSelectFn = (f) => {
                this.props.setField(f.id);
            }
        } else {
            tableColumn.selectedItem = _.find(connectionTables, (t) => t.fieldId === this.props.field[1]);
            fieldColumn.items = _.find(this.props.fieldOptions.fks, (fk) => fk.field.id === tableColumn.selectedItem.fieldId).fields;
            fieldColumn.selectedItem = _.find(fieldColumn.items, (f) => f.id === this.props.field[2]);
            fieldColumn.itemSelectFn = (f) => {
                this.props.setField(["fk->", this.props.field[1], f.id]);
            }
        }

        var columns = [
            tableColumn,
            fieldColumn
        ];

        return (
            <ColumnarSelector columns={columns}/>
        );
    }
});
<commit_msg>Don't set partial fields in qb<commit_after>"use strict";
/*global _*/

import ColumnarSelector from "./columnar_selector.react";

import Query from "./query";

export default React.createClass({
    displayName: "FieldSelector",
    propTypes: {
        field: React.PropTypes.oneOfType([React.PropTypes.number, React.PropTypes.array]),
        fieldOptions: React.PropTypes.object.isRequired,
        tableName: React.PropTypes.string,
        setField: React.PropTypes.func.isRequired
    },

    getInitialState: function() {
        return {
            partialField: null
        };
    },

    setField: function(field) {
        if (Query.isValidField(field)) {
            this.setState({ partialField: null });
            this.props.setField(field);
        } else {
            this.setState({ partialField: field });
        }
    },

    render: function() {
        var field = this.state.partialField != null ? this.state.partialField : this.props.field;

        var sourceTable = {
            title: this.props.tableName || null,
            field: null
        };

        if (!this.props.fieldOptions) {
            return <div>blah</div>;
        }

        var connectionTables = this.props.fieldOptions.fks
            .map((fk) => {
                return {
                    title: fk.field.display_name,
                    subtitle: this.props.tableName || null,
                    field: ["fk->", fk.field.id, null],
                    fieldId: fk.field.id
                };
            });

        var tableSections = [
            {
                title: "Source",
                items: [sourceTable]
            }
        ];
        if (connectionTables.length > 0) {
            tableSections.push({
                title: "Connections",
                items: connectionTables
            });
        }

        var tableColumn = {
            sections: tableSections,
            selectedItem: null,
            itemTitleFn: (table) => {
                var subtitleElement = table.subtitle ? <div className="text-grey-3 mb1">{table.subtitle}</div> : null;
                return (
                    <div>
                        {subtitleElement}
                        <div>{table.title}</div>
                    </div>
                );
            },
            itemSelectFn: (table) => {
                this.setField(table.field);
            }
        }

        var fieldColumn = {
            items: null,
            selectedItem: null,
            itemTitleFn: (field) => field.display_name,
            itemSelectFn: null
        };

        if (field == undefined || typeof field === "number") {
            tableColumn.selectedItem = sourceTable;
            fieldColumn.items = this.props.fieldOptions.fields;
            fieldColumn.selectedItem = _.find(this.props.fieldOptions.fields, (f) => f.id === field);
            fieldColumn.itemSelectFn = (f) => {
                this.setField(f.id);
            }
        } else {
            tableColumn.selectedItem = _.find(connectionTables, (t) => t.fieldId === field[1]);
            fieldColumn.items = _.find(this.props.fieldOptions.fks, (fk) => fk.field.id === tableColumn.selectedItem.fieldId).fields;
            fieldColumn.selectedItem = _.find(fieldColumn.items, (f) => f.id === field[2]);
            fieldColumn.itemSelectFn = (f) => {
                this.setField(["fk->", field[1], f.id]);
            }
        }

        var columns = [
            tableColumn,
            fieldColumn
        ];

        return (
            <ColumnarSelector columns={columns}/>
        );
    }
});

{'fraction_non_alphanumeric': 0.12419354838709677, 'fraction_numerical': 0.0017595307917888563, 'mean_word_length': 1.479462013813159, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 47, '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': '829451', 'n_tokens_mistral': 1860, 'n_tokens_neox': 1798, 'n_words': 322}