1
0
mirror of https://github.com/ascribe/onion.git synced 2025-01-03 10:25:08 +01:00

Merge pull request #29 from ascribe/AD-1281-if-contract-was-appended-to-loan

Add contract link to loan history
This commit is contained in:
Tim Daubenschütz 2015-11-17 14:58:09 +01:00
commit 60bf4b12f5

View File

@ -5,11 +5,33 @@ import React from 'react';
import Form from '../ascribe_forms/form'; import Form from '../ascribe_forms/form';
import Property from '../ascribe_forms/property'; import Property from '../ascribe_forms/property';
import { replaceSubstringAtIndex } from '../../utils/general_utils';
let HistoryIterator = React.createClass({ let HistoryIterator = React.createClass({
propTypes: { propTypes: {
history: React.PropTypes.array history: React.PropTypes.array
}, },
composeHistoryDescription(historicalEvent) {
if(historicalEvent.length === 3) {
// We want to get the capturing group without the quotes,
// which is why we access the match list at index 1 and not 0
const contractName = historicalEvent[1].match(/\"(.*)\"/)[1];
const historicalEventDescription = replaceSubstringAtIndex(historicalEvent[1], `"${contractName}"`, '');
return (
<span>
{historicalEventDescription}
<a href={historicalEvent[2]} target="_blank">{contractName}</a>
</span>
);
} else if(historicalEvent.length === 2) {
return historicalEvent[1];
} else {
throw new Error('Expected an historical event list with either 3 or 2 items. Got less or more.');
}
},
render() { render() {
return ( return (
<Form> <Form>
@ -20,7 +42,7 @@ let HistoryIterator = React.createClass({
key={i} key={i}
label={ historicalEvent[0] } label={ historicalEvent[0] }
editable={false}> editable={false}>
<pre className="ascribe-pre">{ historicalEvent[1] }</pre> <pre className="ascribe-pre">{this.composeHistoryDescription(historicalEvent)}</pre>
</Property> </Property>
); );
})} })}