<commit_before>/**
  * SubmissionsTableContent.jsx
  * Created by <NAME> 10/27/16
  */

import React from 'react';
import PropTypes from 'prop-types';
import FilterBarContainer from 'containers/submissionsTable/FilterBarContainer';
import SubmissionsTable from './SubmissionsTable';
import SubmissionsTableFilters from './SubmissionsTableFilters';
import FiltersMessage from './filters/FiltersMessage';

const propTypes = {
    loadTableData: PropTypes.func,
    session: PropTypes.object,
    activeSubmissions: PropTypes.array,
    publishedSubmissions: PropTypes.array,
    type: PropTypes.oneOf(['dabs', 'fabs']),
    activeTotal: PropTypes.number,
    publishedTotal: PropTypes.number,
    activeLoading: PropTypes.bool,
    publishedLoading: PropTypes.bool,
    activeError: PropTypes.string,
    publishedError: PropTypes.string,
    toggleDashboardFilter: PropTypes.func,
    updateDashboardFilter: PropTypes.func,
    activeMinDateLastModified: PropTypes.string,
    publishedMinDateLastModified: PropTypes.string,
    stagedFilters: PropTypes.object,
    appliedFilters: PropTypes.object
};

const defaultProps = {
    loadTableData: null,
    session: null,
    activeSubmissions: [],
    publishedSubmissions: [],
    type: '',
    activeTotal: 0,
    publishedTotal: 0,
    activeLoading: false,
    publishedLoading: false,
    activeError: '',
    publishedError: '',
    toggleDashboardFilter: null,
    updateDashboardFilter: null,
    activeMinDateLastModified: '',
    publishedMinDateLastModified: '',
    stagedFilters: {},
    appliedFilters: {}
};

export default class SubmissionsTableContent extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            activePage: 1,
            publishedPage: 1,
            filterCounts: {
                dabs: {
                    active: 0,
                    published: 0
                },
                fabs: {
                    active: 0,
                    published: 0
                }
            }
        };

        this.toggleFilter = this.toggleFilter.bind(this);
        this.updateFilterCount = this.updateFilterCount.bind(this);
        this.generateMessage = this.generateMessage.bind(this);
    }

    toggleFilter(table, filter, value) {
        if (filter === 'lastDateModified') {
            this.props.updateDashboardFilter({
                dashboard: this.props.type,
                table,
                filter,
                value
            });
        }
        else {
            this.props.toggleDashboardFilter({
                dashboard: this.props.type,
                table,
                filter,
                value
            });
        }
    }

    /**
     * Use the top filter bar container's internal filter parsing to track the current number of
     * filters applied
     */

    updateFilterCount(count, type, tableType) {
        const dashboard = Object.assign({}, this.state.filterCounts[type], {
            [tableType]: count
        });

        const filterCounts = Object.assign({}, this.state.filterCounts, {
            [type]: dashboard
        });

        this.setState({
            filterCounts
        });
    }

    generateMessage(count) {
        if (count > 0) {
            return (
                <FiltersMessage
                    filterCount={count} />
            );
        }
        return null;
    }

    render() {
        const stagedFilters = this.props.stagedFilters[this.props.type];
        const appliedFilters = this.props.appliedFilters[this.props.type];
        const secondTable = 'published';

        const activeMessage = this.generateMessage(this.state.filterCounts[this.props.type].active);
        const secondMessage = this.generateMessage(this.state.filterCounts[this.props.type][secondTable]);

        return (
            <div className="container">
                <div className="row">
                    <div className="col-md-12">
                        <div className="table-heading">
                            <h2 className="table-heading__title">Active Submissions</h2>
                            {activeMessage}
                        </div>
                        <SubmissionsTableFilters
                            toggleFilter={this.toggleFilter}
                            stagedFilters={stagedFilters.active}
                            appliedFilters={appliedFilters.active}
                            minDateLastModified={this.props.activeMinDateLastModified}
                            type={this.props.type}
                            table="active" />
                        <FilterBarContainer
                            type={this.props.type}
                            table="active"
                            stagedFilters={stagedFilters.active}
                            appliedFilters={appliedFilters.active}
                            updateFilterCount={this.updateFilterCount} />
                        <SubmissionsTable
                            isLoading={this.props.activeLoading}
                            errorMessage={this.props.activeError}
                            isPublished={false}
                            loadTableData={this.props.loadTableData}
                            appliedFilters={appliedFilters.active}
                            total={this.props.activeTotal}
                            data={this.props.activeSubmissions}
                            page={this.state.activePage}
                            session={this.props.session}
                            type={this.props.type} />
                    </div>
                </div>
                <div className="row">
                    <div className="col-md-12">
                        <div className="table-heading">
                            <h2 className="table-heading__title">
                                {this.props.type === 'fabs' ? 'Published Submissions' : 'Certified Submissions'}
                            </h2>
                            {secondMessage}
                        </div>
                        <SubmissionsTableFilters
                            toggleFilter={this.toggleFilter}
                            stagedFilters={stagedFilters[secondTable]}
                            appliedFilters={appliedFilters[secondTable]}
                            minDateLastModified={this.props.publishedMinDateLastModified}
                            table={secondTable}
                            type={this.props.type} />
                        <FilterBarContainer
                            type={this.props.type}
                            table={secondTable}
                            stagedFilters={stagedFilters[secondTable]}
                            appliedFilters={appliedFilters[secondTable]}
                            updateFilterCount={this.updateFilterCount} />
                        <SubmissionsTable
                            isLoading={this.props.publishedLoading}
                            errorMessage={this.props.publishedError}
                            loadTableData={this.props.loadTableData}
                            appliedFilters={appliedFilters[secondTable]}<commit_msg>Updating Certified Submissions header<commit_after>/**
  * SubmissionsTableContent.jsx
  * Created by <NAME> 10/27/16
  */

import React from 'react';
import PropTypes from 'prop-types';
import FilterBarContainer from 'containers/submissionsTable/FilterBarContainer';
import SubmissionsTable from './SubmissionsTable';
import SubmissionsTableFilters from './SubmissionsTableFilters';
import FiltersMessage from './filters/FiltersMessage';

const propTypes = {
    loadTableData: PropTypes.func,
    session: PropTypes.object,
    activeSubmissions: PropTypes.array,
    publishedSubmissions: PropTypes.array,
    type: PropTypes.oneOf(['dabs', 'fabs']),
    activeTotal: PropTypes.number,
    publishedTotal: PropTypes.number,
    activeLoading: PropTypes.bool,
    publishedLoading: PropTypes.bool,
    activeError: PropTypes.string,
    publishedError: PropTypes.string,
    toggleDashboardFilter: PropTypes.func,
    updateDashboardFilter: PropTypes.func,
    activeMinDateLastModified: PropTypes.string,
    publishedMinDateLastModified: PropTypes.string,
    stagedFilters: PropTypes.object,
    appliedFilters: PropTypes.object
};

const defaultProps = {
    loadTableData: null,
    session: null,
    activeSubmissions: [],
    publishedSubmissions: [],
    type: '',
    activeTotal: 0,
    publishedTotal: 0,
    activeLoading: false,
    publishedLoading: false,
    activeError: '',
    publishedError: '',
    toggleDashboardFilter: null,
    updateDashboardFilter: null,
    activeMinDateLastModified: '',
    publishedMinDateLastModified: '',
    stagedFilters: {},
    appliedFilters: {}
};

export default class SubmissionsTableContent extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
            activePage: 1,
            publishedPage: 1,
            filterCounts: {
                dabs: {
                    active: 0,
                    published: 0
                },
                fabs: {
                    active: 0,
                    published: 0
                }
            }
        };

        this.toggleFilter = this.toggleFilter.bind(this);
        this.updateFilterCount = this.updateFilterCount.bind(this);
        this.generateMessage = this.generateMessage.bind(this);
    }

    toggleFilter(table, filter, value) {
        if (filter === 'lastDateModified') {
            this.props.updateDashboardFilter({
                dashboard: this.props.type,
                table,
                filter,
                value
            });
        }
        else {
            this.props.toggleDashboardFilter({
                dashboard: this.props.type,
                table,
                filter,
                value
            });
        }
    }

    /**
     * Use the top filter bar container's internal filter parsing to track the current number of
     * filters applied
     */

    updateFilterCount(count, type, tableType) {
        const dashboard = Object.assign({}, this.state.filterCounts[type], {
            [tableType]: count
        });

        const filterCounts = Object.assign({}, this.state.filterCounts, {
            [type]: dashboard
        });

        this.setState({
            filterCounts
        });
    }

    generateMessage(count) {
        if (count > 0) {
            return (
                <FiltersMessage
                    filterCount={count} />
            );
        }
        return null;
    }

    render() {
        const stagedFilters = this.props.stagedFilters[this.props.type];
        const appliedFilters = this.props.appliedFilters[this.props.type];
        const secondTable = 'published';

        const activeMessage = this.generateMessage(this.state.filterCounts[this.props.type].active);
        const secondMessage = this.generateMessage(this.state.filterCounts[this.props.type][secondTable]);

        return (
            <div className="container">
                <div className="row">
                    <div className="col-md-12">
                        <div className="table-heading">
                            <h2 className="table-heading__title">Active Submissions</h2>
                            {activeMessage}
                        </div>
                        <SubmissionsTableFilters
                            toggleFilter={this.toggleFilter}
                            stagedFilters={stagedFilters.active}
                            appliedFilters={appliedFilters.active}
                            minDateLastModified={this.props.activeMinDateLastModified}
                            type={this.props.type}
                            table="active" />
                        <FilterBarContainer
                            type={this.props.type}
                            table="active"
                            stagedFilters={stagedFilters.active}
                            appliedFilters={appliedFilters.active}
                            updateFilterCount={this.updateFilterCount} />
                        <SubmissionsTable
                            isLoading={this.props.activeLoading}
                            errorMessage={this.props.activeError}
                            isPublished={false}
                            loadTableData={this.props.loadTableData}
                            appliedFilters={appliedFilters.active}
                            total={this.props.activeTotal}
                            data={this.props.activeSubmissions}
                            page={this.state.activePage}
                            session={this.props.session}
                            type={this.props.type} />
                    </div>
                </div>
                <div className="row">
                    <div className="col-md-12">
                        <div className="table-heading">
                            <h2 className="table-heading__title">
                                {this.props.type === 'fabs' ? 'Published Submissions' : 'Published and Certified Submissions'}
                            </h2>
                            {secondMessage}
                        </div>
                        <SubmissionsTableFilters
                            toggleFilter={this.toggleFilter}
                            stagedFilters={stagedFilters[secondTable]}
                            appliedFilters={appliedFilters[secondTable]}
                            minDateLastModified={this.props.publishedMinDateLastModified}
                            table={secondTable}
                            type={this.props.type} />
                        <FilterBarContainer
                            type={this.props.type}
                            table={secondTable}
                            stagedFilters={stagedFilters[secondTable]}
                            appliedFilters={appliedFilters[secondTable]}
                            updateFilterCount={this.updateFilterCount} />
                        <SubmissionsTable
                            isLoading={this.props.publishedLoading}
                            errorMessage={this.props.publishedError}
                            loadTableData={this.props.loadTableData}
                            appliedFilters={appliedFilters[secondTable]}
{'fraction_non_alphanumeric': 0.08947804473902236, 'fraction_numerical': 0.0031759182546257938, 'mean_word_length': 1.4828591018169353, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, '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': '3314497', 'n_tokens_mistral': 3415, 'n_tokens_neox': 3342, 'n_words': 558}