import React from 'react'; import { RetinaImg } from 'mailspring-component-kit'; export class MetricContainer extends React.Component { render() { return (
{this.props.children}
{this.props.name}
); } } export class MetricStat extends React.Component { render() { const { value, units, name } = this.props; return (
(this._el = el)}>
{`${(value / 1).toLocaleString()}${units}`}
); } } export class MetricHistogram extends React.Component { componentDidMount() { if (!this.props.loading) { window.requestAnimationFrame(() => this._el && this._el.classList.add('visible')); } } render() { const { values, left, right } = this.props; let max = 0; for (const v of values) { max = Math.max(v, max); } return (
(this._el = el)}>
{left}
{right}
{values.map((value, idx) => (
))}
); } } export class MetricGraph extends React.Component { componentDidMount() { if (!this.props.loading) { window.requestAnimationFrame(() => this._el && this._el.classList.add('visible')); } } render() { const { values } = this.props; const total = values.reduce((a, sum) => (sum += a), 0); const maxValue = Math.max(...values) || 1; const step = 100.0 / values.length; const pointsForSvg = values .reverse() .map((v, idx) => [(values.length - idx) * step, (maxValue - v) / maxValue * 10]); // make a little diamond at the end if (pointsForSvg[0]) { const [fx, fy] = pointsForSvg[0]; const diamondRadius = 0.45; pointsForSvg.unshift([fx - diamondRadius, fy]); pointsForSvg.unshift([fx, fy - diamondRadius]); pointsForSvg.unshift([fx + diamondRadius, fy]); pointsForSvg.unshift([fx, fy + diamondRadius]); pointsForSvg.unshift([fx - diamondRadius, fy]); } else { // avoid rendering an invalid SVG by making a single point pointsForSvg[0] = [0, 0]; } return (
(this._el = el)}>
{values.map((_, idx) => (
))}
`${x},${y}`).join(' L')}`} />
{(total / 1).toLocaleString()}
); } } export class MetricsBySubjectTable extends React.Component { render() { const { data } = this.props; return (
{data.map(({ subject, count, opens, clicks, replies }) => ( ))}
Subject Line Messages Sent Open Rate Link Click Rate Reply Rate
{subject} {count} {opens ? ( `${Math.ceil(opens / count * 100)}% (${opens})` ) : ( )} {clicks ? ( `${Math.ceil(clicks / count * 100)}% (${clicks})` ) : ( )} {replies ? ( `${Math.ceil(replies / count * 100)}% (${replies})` ) : ( )}
); } }