2015-08-20 15:50:30 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
|
|
|
|
import Form from '../ascribe_forms/form';
|
|
|
|
import Property from '../ascribe_forms/property';
|
|
|
|
|
2015-11-16 11:45:56 +01:00
|
|
|
|
2015-08-20 15:50:30 +02:00
|
|
|
let HistoryIterator = React.createClass({
|
|
|
|
propTypes: {
|
|
|
|
history: React.PropTypes.array
|
|
|
|
},
|
|
|
|
|
2015-11-16 11:45:56 +01:00
|
|
|
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];
|
2016-06-13 16:46:12 +02:00
|
|
|
const historicalEventDescription = historicalEvent[1].replace(`"${contractName}"`, '');
|
2015-11-16 11:45:56 +01:00
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{historicalEventDescription}
|
2015-12-23 09:48:45 +01:00
|
|
|
<a className="anchor-no-expand-print"
|
|
|
|
target="_blank"
|
|
|
|
href={historicalEvent[2]}>
|
|
|
|
{contractName}
|
|
|
|
</a>
|
2015-11-16 11:45:56 +01:00
|
|
|
</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.');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2015-08-20 15:50:30 +02:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Form>
|
|
|
|
{this.props.history.map((historicalEvent, i) => {
|
|
|
|
return (
|
|
|
|
<Property
|
|
|
|
name={i}
|
|
|
|
key={i}
|
|
|
|
label={ historicalEvent[0] }
|
|
|
|
editable={false}>
|
2015-11-16 11:45:56 +01:00
|
|
|
<pre className="ascribe-pre">{this.composeHistoryDescription(historicalEvent)}</pre>
|
2015-08-20 15:50:30 +02:00
|
|
|
</Property>
|
|
|
|
);
|
|
|
|
})}
|
|
|
|
<hr />
|
|
|
|
</Form>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
export default HistoryIterator;
|