<commit_before>import React from 'react';
import { FormattedMessage, injectIntl } from 'react-intl';
import { connect } from 'react-redux';
import { push } from 'react-router-redux';
import { Row, Col } from 'react-flexbox-grid/lib';
import composeAsyncContainer from '../../common/AsyncContainer';
import DataCard from '../../common/DataCard';
import messages from '../../../resources/messages';
import composeHelpfulContainer from '../../common/HelpfulContainer';
import { DownloadButton } from '../../common/IconButton';
import MetadataCoverageItem from './MetadataCoverageItem';
import { TAG_SET_PUBLICATION_COUNTRY, TAG_SET_PUBLICATION_STATE } from '../../../lib/tagUtil';

const localMessages = {
  chartTitle: { id: 'collection.summary.metadatacoverage.chart.title', defaultMessage: 'Metadata' },
  title: { id: 'collection.summary.metadatacoverage.title', defaultMessage: 'Metadata Coverage' },
  helpTitle: { id: 'collection.summary.metadatacoverage.help.title', defaultMessage: 'About Metadata Coverage' },
  helpText: { id: 'collection.summary.metadatacoverage.help.text',
    defaultMessage: '<p>These visualizations show you the percentage of sources in this collection that we have tagged with each type of metadata information.</p>',
  },
  cantShow: { id: 'collection.summary.metadatacoverage.cantShow', defaultMessage: 'This collection is empty.' },
  pubCountryTitle: { id: 'collection.summary.metadatacoverage.pubCountry.title', defaultMessage: 'Country of Publication' },
  pubCountryTagged: { id: 'collection.summary.metadatacoverage.pubCountry.tagged', defaultMessage: 'with a country' },
  pubCountryNotTagged: { id: 'collection.summary.metadatacoverage.pubCountry.notTagged', defaultMessage: 'unknown country' },
  pubStateTitle: { id: 'collection.summary.metadatacoverage.pubState.title', defaultMessage: 'State of Publication' },
  pubStateTagged: { id: 'collection.summary.metadatacoverage.pubState.tagged', defaultMessage: 'with a state' },
  pubStateNotTagged: { id: 'collection.summary.metadatacoverage.pubState.notTagged', defaultMessage: 'unknown state' },
};

class CollectionMetadataCoverageSummaryContainer extends React.Component {

  downloadCsv = () => {
    const { collectionId } = this.props;
    const url = `/api/collections/${collectionId}/metadatacoverage.csv`;
    window.location = url;
  }

  handlePieSliceClick = () => {
  }

  render() {
    const { helpButton, sources } = this.props;
    const { formatMessage } = this.props.intl;
    let content = null;
    if (sources.length === 0) {
      content = <p><FormattedMessage {...localMessages.cantShow} /></p>;
    } else {
      content = (
        <Row>
          <Col lg={6}>
            <MetadataCoverageItem
              title={formatMessage(localMessages.pubCountryTitle)}
              sources={sources}
              metadataId={TAG_SET_PUBLICATION_COUNTRY}
              taggedText={formatMessage(localMessages.pubCountryTagged)}
              notTaggedText={formatMessage(localMessages.pubCountryNotTagged)}
            />
          </Col>
          <Col lg={6}>
            <MetadataCoverageItem
              title={formatMessage(localMessages.pubStateTitle)}
              sources={sources}
              metadataId={TAG_SET_PUBLICATION_STATE}
              taggedText={formatMessage(localMessages.pubStateTagged)}
              notTaggedText={formatMessage(localMessages.pubStateNotTagged)}
            />
          </Col>
        </Row>
      );
    }
    return (
      <DataCard>
        <Row>
          <Col lg={12}>
            <div className="actions">
              <DownloadButton tooltip={formatMessage(messages.download)} onClick={this.downloadCsv} />
            </div>
            <h2>
              <FormattedMessage {...localMessages.title} />
              {helpButton}
            </h2>
          </Col>
        </Row>
        {content}
      </DataCard>
    );
  }

}

CollectionMetadataCoverageSummaryContainer.propTypes = {
  // from state
  fetchStatus: React.PropTypes.string.isRequired,
  // from parent
  collectionId: React.PropTypes.number.isRequired,
  collection: React.PropTypes.object.isRequired,
  sources: React.PropTypes.array.isRequired,
  // from dispatch
  asyncFetch: React.PropTypes.func.isRequired,
  // from composition
  intl: React.PropTypes.object.isRequired,
  helpButton: React.PropTypes.node.isRequired,
};

const mapStateToProps = (state, ownprops) => ({
  fetchStatus: state.sources.collections.selected.collectionDetails.fetchStatus,
  sources: ownprops.sources,
  collection: state.sources.collections.selected.collectionDetails.object,
});<commit_msg>Revert "#260 collections metadata pie for state"<commit_after>import React from 'react';
import { FormattedMessage, injectIntl } from 'react-intl';
import { connect } from 'react-redux';
import { push } from 'react-router-redux';
import { Row, Col } from 'react-flexbox-grid/lib';
import composeAsyncContainer from '../../common/AsyncContainer';
import DataCard from '../../common/DataCard';
import messages from '../../../resources/messages';
import composeHelpfulContainer from '../../common/HelpfulContainer';
import { DownloadButton } from '../../common/IconButton';
import MetadataCoverageItem from './MetadataCoverageItem';
import { TAG_SET_PUBLICATION_COUNTRY } from '../../../lib/tagUtil';

const localMessages = {
  chartTitle: { id: 'collection.summary.metadatacoverage.chart.title', defaultMessage: 'Metadata' },
  title: { id: 'collection.summary.metadatacoverage.title', defaultMessage: 'Metadata Coverage' },
  helpTitle: { id: 'collection.summary.metadatacoverage.help.title', defaultMessage: 'About Metadata Coverage' },
  helpText: { id: 'collection.summary.metadatacoverage.help.text',
    defaultMessage: '<p>These visualizations show you the percentage of sources in this collection that we have tagged with each type of metadata information.</p>',
  },
  cantShow: { id: 'collection.summary.metadatacoverage.cantShow', defaultMessage: 'This collection is empty.' },
  pubCountryTitle: { id: 'collection.summary.metadatacoverage.pubCountry.title', defaultMessage: 'Country of Publication' },
  pubCountryTagged: { id: 'collection.summary.metadatacoverage.pubCountry.tagged', defaultMessage: 'with a country' },
  pubCountryNotTagged: { id: 'collection.summary.metadatacoverage.pubCountry.notTagged', defaultMessage: 'unknown country' },
};

class CollectionMetadataCoverageSummaryContainer extends React.Component {

  downloadCsv = () => {
    const { collectionId } = this.props;
    const url = `/api/collections/${collectionId}/metadatacoverage.csv`;
    window.location = url;
  }

  handlePieSliceClick = () => {
  }

  render() {
    const { helpButton, sources } = this.props;
    const { formatMessage } = this.props.intl;
    let content = null;
    if (sources.length === 0) {
      content = <p><FormattedMessage {...localMessages.cantShow} /></p>;
    } else {
      content = (
        <Col lg={4}>
          <MetadataCoverageItem
            title={formatMessage(localMessages.pubCountryTitle)}
            sources={sources}
            metadataId={TAG_SET_PUBLICATION_COUNTRY}
            taggedText={formatMessage(localMessages.pubCountryTagged)}
            notTaggedText={formatMessage(localMessages.pubCountryNotTagged)}
          />
        </Col>
      );
    }
    return (
      <DataCard>
        <Row>
          <Col lg={12}>
            <div className="actions">
              <DownloadButton tooltip={formatMessage(messages.download)} onClick={this.downloadCsv} />
            </div>
            <h2>
              <FormattedMessage {...localMessages.title} />
              {helpButton}
            </h2>
          </Col>
        </Row>
        <Row>
          {content}
        </Row>
      </DataCard>
    );
  }

}

CollectionMetadataCoverageSummaryContainer.propTypes = {
  // from state
  fetchStatus: React.PropTypes.string.isRequired,
  // from parent
  collectionId: React.PropTypes.number.isRequired,
  collection: React.PropTypes.object.isRequired,
  sources: React.PropTypes.array.isRequired,
  // from dispatch
  asyncFetch: React.PropTypes.func.isRequired,
  // from composition
  intl: React.PropTypes.object.isRequired,
  helpButton: React.PropTypes.node.isRequired,
};

const mapStateToProps = (state, ownprops) => ({
  fetchStatus: state.sources.collections.selected.collectionDetails.fetchStatus,
  sources: ownprops.sources,
  collection: state.sources.collections.selected.collectionDetails.object,
});
{'fraction_non_alphanumeric': 0.1279302626928967, 'fraction_numerical': 0.0018847920838732477, 'mean_word_length': 3.4195731389901094, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 56, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4630188', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2411, 'n_words': 478}