1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-12 13:48:35 +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
};
class HistoryItem extends Component {
static propTypes () {
return {
entry: PropTypes.object,
};
}
getIcon (type) {
function getIcon (type) {
if (type.indexOf('created') > -1 ) {
return 'add';
}
@ -43,13 +35,34 @@ class HistoryItem extends Component {
return 'archived';
}
return 'bookmark';
}
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>
);
}
buildDiff (diff, idx) {
return change;
}
function buildDiff (diff, idx) {
let change;
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 = (
<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 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>);
}
class HistoryItem extends Component {
static propTypes () {
return {
entry: PropTypes.object,
};
}
renderEventDiff (logEntry) {
if (!logEntry.diffs) {
return;
}
const changes = logEntry.diffs.map(this.buildDiff);
const changes = logEntry.diffs.map(buildDiff);
return (
<code className="smalltext man">{changes.length === 0 ? '(no changes)' : changes}</code>
);
@ -95,7 +116,7 @@ class HistoryItem extends Component {
} = this.props.entry;
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 ?
this.renderFullEventData(this.props.entry) : this.renderEventDiff(this.props.entry);