1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-23 09:50:31 +01:00
onion/js/components/ascribe_table/table_item_wrapper.js

53 lines
1.8 KiB
JavaScript
Raw Normal View History

'use strict';
2015-05-26 20:20:17 +02:00
import React from 'react';
import { Link } from 'react-router';
2015-05-26 20:20:17 +02:00
import { ColumnModel } from './models/table_models';
2015-05-26 20:20:17 +02:00
2015-06-04 16:07:37 +02:00
2015-05-26 20:20:17 +02:00
let TableItemWrapper = React.createClass({
propTypes: {
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(ColumnModel)),
2015-05-26 20:20:17 +02:00
columnContent: React.PropTypes.object,
2015-07-08 17:35:30 +02:00
columnWidth: React.PropTypes.number.isRequired,
onClick: React.PropTypes.func
2015-05-26 20:20:17 +02:00
},
render() {
return (
2015-07-08 17:35:30 +02:00
<tr onClick={this.props.onClick}>
2015-05-26 20:20:17 +02:00
{this.props.columnList.map((column, i) => {
let TypeElement = column.displayType;
2015-06-01 14:10:11 +02:00
let typeElementProps = column.transformFn(this.props.columnContent);
2015-06-04 16:07:37 +02:00
if(!column.transition) {
return (
2015-06-04 17:21:38 +02:00
<td
className={'ascribe-table-item-column'}
2015-06-04 16:07:37 +02:00
key={i}>
<TypeElement {...typeElementProps} />
2015-06-04 17:21:38 +02:00
</td>
2015-06-04 16:07:37 +02:00
);
} else {
let linkString = column.transition.toReactRouterLink(this.props.columnContent[column.transition.valueKey]);
2015-06-04 16:07:37 +02:00
return (
2015-07-01 10:53:40 +02:00
<td key={i} className={column.className}>
<Link
to={linkString}
className={'ascribe-table-item-column'}
onClick={column.transition.callback}>
2015-06-04 17:21:38 +02:00
<TypeElement {...typeElementProps} />
</Link>
</td>
2015-06-04 16:07:37 +02:00
);
}
2015-05-26 20:20:17 +02:00
})}
2015-06-04 17:21:38 +02:00
</tr>
2015-05-26 20:20:17 +02:00
);
}
});
export default TableItemWrapper;