<commit_before>import React           from 'react';
import TopListChart    from './TopListChart';
import Parties         from '../constants/Parties';
import ImageUtils      from '../utils/ImageUtils';

class ResultStats extends React.Component {
    constructor(props) {
        super(props);

        this.searchStore = this.props.flux.getStore('search');

        this.state = {
            parties: [],
            people: [],
            query: ''
        };
    }

    componentDidMount() {
        this.searchStore.addListener('change', this.handleChange.bind(this));
    }

    componentWillUnmount() {
        this.searchStore.removeListener('change', this.handleChange.bind(this));
    }

    handleChange() {
        let parties = [];
        let people  = [];
        let query   = '';

        let result = this.searchStore.getLastResult();

        if (result) {
            people = result.result.people;
            parties = result.result.parties;
            query = result.query;
        }

        this.setState({
            query: query,
            parties: parties,
            people: people,
            topParties: this.topParties(parties)
        });
    }

    render() {
        return (
            <div className="card">
                {this.renderPartyStats()}
                <div className="divider" />
                {this.renderPeopleStats()}
            </div>
        );
    }

    renderPartyStats() {
        if (this.state.parties.length) {
            return (
                <div className="row stats">
                    <div className="col-md-6">
                        <TopListChart
                            subtitle="Partier"
                            orientation={this.props.orientation}
                            unit={this.props.unit}
                            counts={this.state.parties.sort((a, b) => Parties.order(b.key) - Parties.order(a.key))}
                        />
                    </div>

                    <div className="col-md-6">
                        {this.renderPartyText()}
                    </div>
                </div>
            );
        } else {
            return <div />;
        }
    }

    renderPeopleStats() {
        let people = this.state.people[this.props.unit] || [];

        if (people.length) {
            let topPerson = people[0];
            let num = this.props.unit === 'pct' ? `${topPerson.pct.toFixed(2)} %` : topPerson.count;
            let unitText = this.props.unit === 'pct' ? 'av sine innlegg' : 'innlegg';

            return (
                <div className="row stats">
                    <div className="col-md-5 text-center">
                        <img
                            src={ImageUtils.personImageFor(topPerson.meta.external_id)}
                            alt={`Bilde av ${topPerson.key}`}
                            height="200"
                        />
<commit_msg>Hide stats when query is empty<commit_after>import React           from 'react';
import TopListChart    from './TopListChart';
import Parties         from '../constants/Parties';
import ImageUtils      from '../utils/ImageUtils';

class ResultStats extends React.Component {
    constructor(props) {
        super(props);

        this.searchStore = this.props.flux.getStore('search');

        this.state = {
            parties: [],
            people: [],
            query: ''
        };
    }

    componentDidMount() {
        this.searchStore.addListener('change', this.handleChange.bind(this));
    }

    componentWillUnmount() {
        this.searchStore.removeListener('change', this.handleChange.bind(this));
    }

    handleChange() {
        let parties = [];
        let people  = [];
        let query   = '';

        let result = this.searchStore.getLastResult();

        if (result) {
            people = result.result.people;
            parties = result.result.parties;
            query = result.query;
        }

        this.setState({
            query: query,
            parties: parties,
            people: people,
            topParties: this.topParties(parties)
        });
    }

    render() {
        if (this.state.query.length) {
            return (
                <div className="card">
                    {this.renderPartyStats()}
                    <div className="divider" />
                    {this.renderPeopleStats()}
                </div>
            );
        } else {
            return <div />;
        }
    }

    renderPartyStats() {
        return (
            <div className="row stats">
                <div className="col-md-6">
                    <TopListChart
                        subtitle="Partier"
                        orientation={this.props.orientation}
                        unit={this.props.unit}
                        counts={this.state.parties.sort((a, b) => Parties.order(b.key) - Parties.order(a.key))}
                    />
                </div>

                <div className="col-md-6">
                    {this.renderPartyText()}
                </div>
            </div>
        );
    }

    renderPeopleStats() {
        let people = this.state.people[this.props.unit] || [];

        if (people.length) {
            let topPerson = people[0];
            let num = this.props.unit === 'pct' ? `${topPerson.pct.toFixed(2)} %` : topPerson.count;
            let unitText = this.props.unit === 'pct' ? 'av sine innlegg' : 'innlegg';

            return (
                <div className="row stats">
                    <div className="col-md-5 text-center">
                        <img
                            src={ImageUtils.personImageFor(topPerson.meta.external_id)}
                            alt={`Bilde av ${topPerson.key}`}
                            height="200"
                        />

{'fraction_non_alphanumeric': 0.12502146659797356, 'fraction_numerical': 0.0027477245406148034, 'mean_word_length': 1.2965299684542586, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 33, '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': '519900', 'n_tokens_mistral': 1553, 'n_tokens_neox': 1488, 'n_words': 269}