2015-06-05 11:06:36 +02:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-26 20:20:17 +02:00
|
|
|
import React from 'react';
|
2015-06-04 11:41:56 +02:00
|
|
|
import Router from 'react-router';
|
2015-05-26 20:20:17 +02:00
|
|
|
|
2015-06-04 13:48:07 +02:00
|
|
|
import { ColumnModel } from './models/table_models';
|
2015-05-26 20:20:17 +02:00
|
|
|
import TableColumnMixin from '../../mixins/table_column_mixin';
|
|
|
|
|
2015-06-04 16:07:37 +02:00
|
|
|
let Link = Router.Link;
|
|
|
|
|
2015-05-26 20:20:17 +02:00
|
|
|
let TableItemWrapper = React.createClass({
|
|
|
|
propTypes: {
|
2015-06-04 13:48:07 +02:00
|
|
|
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(ColumnModel)),
|
2015-05-26 20:20:17 +02:00
|
|
|
columnContent: React.PropTypes.object,
|
|
|
|
columnWidth: React.PropTypes.number.isRequired
|
|
|
|
},
|
|
|
|
|
2015-06-05 11:06:36 +02:00
|
|
|
mixins: [TableColumnMixin, Router.Navigation],
|
|
|
|
|
2015-05-26 20:20:17 +02:00
|
|
|
render() {
|
|
|
|
return (
|
2015-06-04 17:21:38 +02:00
|
|
|
<tr>
|
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-05-26 20:20:17 +02:00
|
|
|
let columnClass = this.calcColumnClasses(this.props.columnList, i, this.props.columnWidth);
|
|
|
|
|
2015-06-04 16:07:37 +02:00
|
|
|
if(!column.transition) {
|
|
|
|
return (
|
2015-06-04 17:21:38 +02:00
|
|
|
<td
|
2015-06-05 11:06:36 +02:00
|
|
|
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 linkProps = column.transition.toReactRouterLinkProps(this.props.columnContent[column.transition.valueKey]);
|
|
|
|
/**
|
|
|
|
* If a transition is defined in columnContent, then we can use
|
|
|
|
* Router.Navigation.transitionTo to redirect the user
|
|
|
|
* programmatically
|
|
|
|
*/
|
|
|
|
return (
|
2015-06-04 17:21:38 +02:00
|
|
|
<td key={i}>
|
2015-06-05 11:06:36 +02:00
|
|
|
<Link
|
|
|
|
className={'ascribe-table-item-column'}
|
2015-06-04 17:21:38 +02:00
|
|
|
onClick={column.transition.callback}
|
|
|
|
{...linkProps}>
|
|
|
|
<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;
|