import React from "react"; import { Link, withRouter } from 'react-router-dom' import Modal from './modal' import * as api from '../../api' import numberFormatter from '../../number-formatter' import Bar from '../bar' import {parseQuery, toHuman} from '../../query' class ReferrerDrilldownModal extends React.Component { constructor(props) { super(props) this.state = { loading: true, query: parseQuery(props.location.search, props.site) } } componentDidMount() { api.get(`/api/stats/${this.props.site.domain}/referrers/${this.props.match.params.referrer}`, this.state.query, {limit: 100}) .then((res) => this.setState({loading: false, referrers: res.referrers, totalVisitors: res.total_visitors})) } renderReferrer(referrer) { return (
{ referrer.name } {numberFormatter(referrer.count)}
) } renderGoalText() { if (this.state.query.filters.goal) { return (

completed {this.state.query.filters.goal}

) } } renderBody() { if (this.state.loading) { return (
) } else if (this.state.referrers) { return (
← All referrers

{this.state.totalVisitors} visitors from {this.props.match.params.referrer}
{toHuman(this.state.query)}

{this.renderGoalText()}
{ this.state.referrers.map(this.renderReferrer.bind(this)) }
) } } render() { return ( { this.renderBody() } ) } } export default withRouter(ReferrerDrilldownModal)