<commit_before>import React, { Component, PropTypes } from "react";
import _ from "underscore";

import MetabaseAnalytics from "metabase/lib/analytics";

import MetadataHeader from './MetadataHeader.jsx';
import MetadataTablePicker from './MetadataTablePicker.jsx';
import MetadataTable from './MetadataTable.jsx';
import MetadataSchema from './MetadataSchema.jsx';

export default class MetadataEditor extends Component {
    constructor(props, context) {
        super(props, context);
        this.toggleShowSchema = this.toggleShowSchema.bind(this);
        this.updateField = this.updateField.bind(this);
        this.updateFieldSpecialType = this.updateFieldSpecialType.bind(this);
        this.updateFieldTarget = this.updateFieldTarget.bind(this);
        this.updateTable = this.updateTable.bind(this);

        this.state = {
            isShowingSchema: false
        };
    }

    static propTypes = {
        databaseId: PropTypes.number,
        databases: PropTypes.array.isRequired,
        selectDatabase: PropTypes.func.isRequired,
        databaseMetadata: PropTypes.object,
        tableId: PropTypes.number,
        tables: PropTypes.object.isRequired,
        selectTable: PropTypes.func.isRequired,
        idfields: PropTypes.array.isRequired,
        updateTable: PropTypes.func.isRequired,
        updateField: PropTypes.func.isRequired,
        updateFieldSpecialType: PropTypes.func.isRequired,
        updateFieldTarget: PropTypes.func.isRequired
    };

    toggleShowSchema() {
        this.setState({ isShowingSchema: !this.state.isShowingSchema });
        MetabaseAnalytics.trackEvent("Data Model", "Show OG Schema", !this.state.isShowingSchema);
    }

    handleSaveResult(promise) {
        this.refs.header.setSaving();
        promise.then(() => {
            this.refs.header.setSaved();
        }, (error) => {
            this.refs.header.setSaveError(error.data);
        });
    }

    updateTable(table) {
        this.handleSaveResult(this.props.updateTable(table));
        MetabaseAnalytics.trackEvent("Data Model", "Update Table");
    }

    updateField(field) {
        this.handleSaveResult(this.props.updateField(field));
        MetabaseAnalytics.trackEvent("Data Model", "Update Field");
    }

    updateFieldSpecialType(field) {
        this.handleSaveResult(this.props.updateFieldSpecialType(field));
        MetabaseAnalytics.trackEvent("Data Model", "Update Field Special-Type", field.special_type);
    }

    updateFieldTarget(field) {
        this.handleSaveResult(this.props.updateFieldTarget(field));
        MetabaseAnalytics.trackEvent("Data Model", "Update Field Target");
    }

    render() {
        var tableMetadata = (this.props.databaseMetadata) ? _.findWhere(this.props.databaseMetadata.tables, {id: this.props.tableId}) : null;
        var content;
        if (tableMetadata) {
            if (this.state.isShowingSchema) {
                content = (<MetadataSchema tableMetadata={tableMetadata} />);
            } else {
                content = (
                    <MetadataTable
                        tableMetadata={tableMetadata}
                        idfields={this.props.idfields}
                        updateTable={this.updateTable}
                        updateField={this.updateField}
                        updateFieldSpecialType={this.updateFieldSpecialType}
                        updateFieldTarget={this.updateFieldTarget}
                        onRetireSegment={this.props.onRetireSegment}
                        onRetireMetric={this.props.onRetireMetric}
                    />
                );
            }
        } else {
            content = (
                <div className="flex flex-full layout-centered">
                    <h2 className="text-grey-3">Select any table to see its schema and add or edit metadata.</h2>
                </div>
            );
        }
        return (
            <div className="MetadataEditor full-height p3">
                <MetadataHeader
                    ref="header"
                    databaseId={this.props.databaseId}
                    databases={this.props.databases}
                    selectDatabase={this.props.selectDatabase}
                    isShowingSchema={this.state.isShowingSchema}
                    toggleShowSchema={this.toggleShowSchema}
                />
              <div className="MetadataEditor-main flex flex-row flex-full mt2 full-height">
                    <MetadataTablePicker
                        tableId={this.props.tableId}
                        tables={(this.props.databaseMetadata) ? this.props.databaseMetadata.tables : []}
                        selectTable={this.props.selectTable}
                    />
                    {content}
                </div>
            </div>
        );
    }
}<commit_msg>fixes #2553 by removing some of the flex and full-height css settings.  this creates a complementary UX issue where as the length of the content changes the sidebar background gets longer/shorter.  we'll address that separately.<commit_after>import React, { Component, PropTypes } from "react";
import _ from "underscore";

import MetabaseAnalytics from "metabase/lib/analytics";

import MetadataHeader from './MetadataHeader.jsx';
import MetadataTablePicker from './MetadataTablePicker.jsx';
import MetadataTable from './MetadataTable.jsx';
import MetadataSchema from './MetadataSchema.jsx';

export default class MetadataEditor extends Component {
    constructor(props, context) {
        super(props, context);
        this.toggleShowSchema = this.toggleShowSchema.bind(this);
        this.updateField = this.updateField.bind(this);
        this.updateFieldSpecialType = this.updateFieldSpecialType.bind(this);
        this.updateFieldTarget = this.updateFieldTarget.bind(this);
        this.updateTable = this.updateTable.bind(this);

        this.state = {
            isShowingSchema: false
        };
    }

    static propTypes = {
        databaseId: PropTypes.number,
        databases: PropTypes.array.isRequired,
        selectDatabase: PropTypes.func.isRequired,
        databaseMetadata: PropTypes.object,
        tableId: PropTypes.number,
        tables: PropTypes.object.isRequired,
        selectTable: PropTypes.func.isRequired,
        idfields: PropTypes.array.isRequired,
        updateTable: PropTypes.func.isRequired,
        updateField: PropTypes.func.isRequired,
        updateFieldSpecialType: PropTypes.func.isRequired,
        updateFieldTarget: PropTypes.func.isRequired
    };

    toggleShowSchema() {
        this.setState({ isShowingSchema: !this.state.isShowingSchema });
        MetabaseAnalytics.trackEvent("Data Model", "Show OG Schema", !this.state.isShowingSchema);
    }

    handleSaveResult(promise) {
        this.refs.header.setSaving();
        promise.then(() => {
            this.refs.header.setSaved();
        }, (error) => {
            this.refs.header.setSaveError(error.data);
        });
    }

    updateTable(table) {
        this.handleSaveResult(this.props.updateTable(table));
        MetabaseAnalytics.trackEvent("Data Model", "Update Table");
    }

    updateField(field) {
        this.handleSaveResult(this.props.updateField(field));
        MetabaseAnalytics.trackEvent("Data Model", "Update Field");
    }

    updateFieldSpecialType(field) {
        this.handleSaveResult(this.props.updateFieldSpecialType(field));
        MetabaseAnalytics.trackEvent("Data Model", "Update Field Special-Type", field.special_type);
    }

    updateFieldTarget(field) {
        this.handleSaveResult(this.props.updateFieldTarget(field));
        MetabaseAnalytics.trackEvent("Data Model", "Update Field Target");
    }

    render() {
        var tableMetadata = (this.props.databaseMetadata) ? _.findWhere(this.props.databaseMetadata.tables, {id: this.props.tableId}) : null;
        var content;
        if (tableMetadata) {
            if (this.state.isShowingSchema) {
                content = (<MetadataSchema tableMetadata={tableMetadata} />);
            } else {
                content = (
                    <MetadataTable
                        tableMetadata={tableMetadata}
                        idfields={this.props.idfields}
                        updateTable={this.updateTable}
                        updateField={this.updateField}
                        updateFieldSpecialType={this.updateFieldSpecialType}
                        updateFieldTarget={this.updateFieldTarget}
                        onRetireSegment={this.props.onRetireSegment}
                        onRetireMetric={this.props.onRetireMetric}
                    />
                );
            }
        } else {
            content = (
                <div style={{paddingTop: "10rem"}} className="full text-centered">
                    <h2 className="text-grey-3">Select any table to see its schema and add or edit metadata.</h2>
                </div>
            );
        }
        return (
            <div className="p3">
                <MetadataHeader
                    ref="header"
                    databaseId={this.props.databaseId}
                    databases={this.props.databases}
                    selectDatabase={this.props.selectDatabase}
                    isShowingSchema={this.state.isShowingSchema}
                    toggleShowSchema={this.toggleShowSchema}
                />
              <div style={{minHeight: "60vh"}} className="flex flex-row flex-full mt2 full-height">
                    <MetadataTablePicker
                        tableId={this.props.tableId}
                        tables={(this.props.databaseMetadata) ? this.props.databaseMetadata.tables : []}
                        selectTable={this.props.selectTable}
                    />
                    {content}
                </div>
            </div>
        );
    }
}
{'fraction_non_alphanumeric': 0.10227272727272728, 'fraction_numerical': 0.0018262987012987013, 'mean_word_length': 2.0793502030615434, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 31, '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': '2892866', 'n_tokens_mistral': 2527, 'n_tokens_neox': 2455, 'n_words': 426}