'use strict'; const React = require('react'); const moment = require('moment'); const DIFF_PREFIXES = { A: ' ', E: ' ', D: '-', N: '+', }; const SPADEN_CLASS = { A: 'blue', // array edited E: 'blue', // edited D: 'negative', // deleted N: 'positive', // added }; const LogEntry = React.createClass({ propTypes: { event: React.PropTypes.object.isRequired, }, render () { const date = moment(this.props.event.createdAt); return ( {date.format('ll')}
{date.format('HH:mm')} {this.props.event.data.name}[{this.props.event.type}] {this.renderEventDiff()} {this.props.event.createdBy} ); }, renderFullEventData () { const localEventData = JSON.parse(JSON.stringify(this.props.event.data)); delete localEventData.description; delete localEventData.name; const prettyPrinted = JSON.stringify(localEventData, null, 2); return ({prettyPrinted}); }, renderEventDiff () { if (!this.props.showFullEvents && this.props.event.diffs) { const changes = this.props.event.diffs.map(this.buildDiff); return ( {changes.length === 0 ? '(no changes)' : changes} ); } return this.renderFullEventData(); }, buildDiff (diff, idx) { let change; const key = diff.path.join('.'); if (diff.lhs !== undefined && diff.rhs !== undefined) { change = (
- {key}: {JSON.stringify(diff.lhs)}
+ {key}: {JSON.stringify(diff.rhs)}
); } else { const spadenClass = SPADEN_CLASS[diff.kind]; const prefix = DIFF_PREFIXES[diff.kind]; change = (
{prefix} {key}: {JSON.stringify(diff.rhs)}
); } return (
{change}
); }, }); module.exports = LogEntry;