1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/packages/unleash-frontend/public/js/components/log/LogEntry.jsx

88 lines
2.4 KiB
React
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
const React = require('react');
const moment = require('moment');
2014-11-13 15:14:41 +01:00
2016-06-18 21:53:18 +02:00
const DIFF_PREFIXES = {
A: ' ',
E: ' ',
D: '-',
2016-06-18 21:55:46 +02:00
N: '+',
2015-03-23 18:47:23 +01:00
};
2016-06-18 21:53:18 +02:00
const SPADEN_CLASS = {
A: 'blue', // array edited
E: 'blue', // edited
D: 'negative', // deleted
N: 'positive', // added
2015-03-23 18:47:23 +01:00
};
2016-06-18 21:53:18 +02:00
const LogEntry = React.createClass({
2014-11-13 15:14:41 +01:00
propTypes: {
2016-06-18 21:55:46 +02:00
event: React.PropTypes.object.isRequired,
2014-11-13 15:14:41 +01:00
},
2016-07-02 11:54:50 +02:00
render () {
2016-06-18 21:53:18 +02:00
const date = moment(this.props.event.createdAt);
2014-11-13 15:14:41 +01:00
return (
<tr>
<td>
2015-02-04 18:47:37 +01:00
{date.format('ll')}<br />
{date.format('HH:mm')}
</td>
<td>
<strong>{this.props.event.data.name}</strong><em>[{this.props.event.type}]</em>
</td>
2016-06-18 21:55:46 +02:00
<td style={{ maxWidth: 300 }}>
{this.renderEventDiff()}
</td>
<td>{this.props.event.createdBy}</td>
2014-11-13 15:14:41 +01:00
</tr>
);
},
2016-07-02 11:54:50 +02:00
renderFullEventData () {
2016-06-18 21:53:18 +02:00
const localEventData = JSON.parse(JSON.stringify(this.props.event.data));
delete localEventData.description;
delete localEventData.name;
2016-06-18 21:53:18 +02:00
const prettyPrinted = JSON.stringify(localEventData, null, 2);
2016-06-18 21:55:46 +02:00
return (<code className="JSON smalltext man">{prettyPrinted}</code>);
},
2016-07-02 11:54:50 +02:00
renderEventDiff () {
if (!this.props.showFullEvents && this.props.event.diffs) {
2016-06-18 21:53:18 +02:00
const changes = this.props.event.diffs.map(this.buildDiff);
2015-03-23 18:47:23 +01:00
return (
2016-06-18 21:55:46 +02:00
<code className="smalltext man">{changes.length === 0 ? '(no changes)' : changes}</code>
2015-03-23 18:47:23 +01:00
);
}
2016-06-18 22:23:19 +02:00
return this.renderFullEventData();
},
2016-07-02 11:54:50 +02:00
buildDiff (diff, idx) {
2016-06-18 21:53:18 +02:00
let change;
const key = diff.path.join('.');
if (diff.lhs !== undefined && diff.rhs !== undefined) {
change = (
<div>
<div className={SPADEN_CLASS.D}>- {key}: {JSON.stringify(diff.lhs)}</div>
<div className={SPADEN_CLASS.N}>+ {key}: {JSON.stringify(diff.rhs)}</div>
</div>
);
} else {
2016-06-18 21:53:18 +02:00
const spadenClass = SPADEN_CLASS[diff.kind];
const prefix = DIFF_PREFIXES[diff.kind];
2015-03-23 18:47:23 +01:00
change = (<div className={spadenClass}>{prefix} {key}: {JSON.stringify(diff.rhs)}</div>);
}
2015-03-23 18:47:23 +01:00
return (<div key={idx}>{change}</div>);
2016-06-18 21:55:46 +02:00
},
2014-11-13 15:14:41 +01:00
});
2015-03-23 18:47:23 +01:00
module.exports = LogEntry;