import React from 'react'; import { DetailedMeasure } from './detailed-measure'; import { DonutChart } from '../../../components/charts/donut-chart'; import { DrilldownLink } from '../../../components/shared/drilldown-link'; import { formatMeasure, formatMeasureVariation } from '../../../helpers/measures'; export const CoverageMeasures = React.createClass({ propTypes: { measures: React.PropTypes.object.isRequired, leak: React.PropTypes.object.isRequired, prefix: React.PropTypes.string.isRequired }, getMetricName(metric) { const { prefix } = this.props; return prefix + metric; }, getNewCoverageMetricName () { const { prefix } = this.props; return 'new_' + prefix + 'coverage'; }, getCoverageMeasure() { const coverageMetricName = this.getMetricName('coverage'); return this.props.measures[coverageMetricName]; }, getCoverageLeak() { const coverageMetricName = this.getMetricName('coverage'); return this.props.leak[coverageMetricName]; }, getNewCoverageMeasure() { const newCoverageMetricName = this.getNewCoverageMetricName(); return this.props.leak[newCoverageMetricName]; }, renderCoverageLeak () { if (!this.props.leakPeriodDate) { return null; } const coverageLeak = this.getCoverageLeak(); return
{formatMeasureVariation(coverageLeak, 'PERCENT')}
; }, renderCoverageOnNewCode() { const newCoverageMetricName = this.getNewCoverageMetricName(); const newCoverage = this.getNewCoverageMeasure(); if (!this.props.leakPeriodDate || newCoverage == null) { return null; } const donutData = [ { value: newCoverage, fill: '#85bb43' }, { value: 100 - newCoverage, fill: '#d4333f' } ]; return
{window.t('metric', newCoverageMetricName, 'name')}
{formatMeasure(newCoverage, 'PERCENT')}
; }, renderDonut() { const coverage = this.getCoverageMeasure(); const donutData = [ { value: coverage, fill: '#85bb43' }, { value: 100 - coverage, fill: '#d4333f' } ]; return ; }, render() { const coverageMetricName = this.getMetricName('coverage'); const coverage = this.getCoverageMeasure(); return (
{window.t('metric', coverageMetricName, 'name')} {this.renderDonut()} {formatMeasure(coverage, 'PERCENT')}
{this.renderCoverageLeak()}
{this.renderCoverageOnNewCode()}
); } });