1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-16 01:55:07 +01:00
onion/js/components/ascribe_table/table_item_wrapper.js

63 lines
2.2 KiB
JavaScript
Raw Normal View History

'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
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: {
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
},
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
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}>
<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;