1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-17 13:46:47 +02:00

more event-differ

This commit is contained in:
ivaosthu 2016-11-22 22:58:09 +01:00
parent cc8ccfd403
commit be35162a94
3 changed files with 72 additions and 51 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -18,15 +18,7 @@ const SPADEN_CLASS = {
N: style.positive, // added N: style.positive, // added
}; };
class HistoryItem extends Component { function getIcon (type) {
static propTypes () {
return {
entry: PropTypes.object,
};
}
getIcon (type) {
if (type.indexOf('created') > -1 ) { if (type.indexOf('created') > -1 ) {
return 'add'; return 'add';
} }
@ -45,11 +37,32 @@ class HistoryItem extends Component {
return 'bookmark'; return 'bookmark';
} }
buildDiff (diff, idx) { function buildItemDiff (diff, key) {
let change;
if (diff.lhs !== undefined) {
change = (
<div>
<div className={SPADEN_CLASS.D}>- {key}: {JSON.stringify(diff.lhs)}</div>
</div>
);
} else if (diff.rhs !== undefined) {
change = (
<div>
<div className={SPADEN_CLASS.N}>+ {key}: {JSON.stringify(diff.rhs)}</div>
</div>
);
}
return change;
}
function buildDiff (diff, idx) {
let change; let change;
const key = diff.path.join('.'); const key = diff.path.join('.');
if (diff.lhs !== undefined && diff.rhs !== undefined) { if (diff.item) {
change = buildItemDiff(diff.item, key);
} else if (diff.lhs !== undefined && diff.rhs !== undefined) {
change = ( change = (
<div> <div>
<div className={SPADEN_CLASS.D}>- {key}: {JSON.stringify(diff.lhs)}</div> <div className={SPADEN_CLASS.D}>- {key}: {JSON.stringify(diff.lhs)}</div>
@ -60,17 +73,25 @@ class HistoryItem extends Component {
const spadenClass = SPADEN_CLASS[diff.kind]; const spadenClass = SPADEN_CLASS[diff.kind];
const prefix = DIFF_PREFIXES[diff.kind]; const prefix = DIFF_PREFIXES[diff.kind];
change = (<div className={spadenClass}>{prefix} {key}: {JSON.stringify(diff.rhs)}</div>); change = (<div className={spadenClass}>{prefix} {key}: {JSON.stringify(diff.rhs || diff.item)}</div>);
} }
return (<div key={idx}>{change}</div>); return (<div key={idx}>{change}</div>);
} }
class HistoryItem extends Component {
static propTypes () {
return {
entry: PropTypes.object,
};
}
renderEventDiff (logEntry) { renderEventDiff (logEntry) {
if (!logEntry.diffs) { if (!logEntry.diffs) {
return; return;
} }
const changes = logEntry.diffs.map(this.buildDiff); const changes = logEntry.diffs.map(buildDiff);
return ( return (
<code className="smalltext man">{changes.length === 0 ? '(no changes)' : changes}</code> <code className="smalltext man">{changes.length === 0 ? '(no changes)' : changes}</code>
); );
@ -95,7 +116,7 @@ class HistoryItem extends Component {
} = this.props.entry; } = this.props.entry;
const createdAt = (new Date(this.props.entry.createdAt)).toLocaleString('nb-NO'); const createdAt = (new Date(this.props.entry.createdAt)).toLocaleString('nb-NO');
const icon = this.getIcon(type); const icon = getIcon(type);
const data = this.props.showData ? const data = this.props.showData ?
this.renderFullEventData(this.props.entry) : this.renderEventDiff(this.props.entry); this.renderFullEventData(this.props.entry) : this.renderEventDiff(this.props.entry);