1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 17:45:10 +01:00
onion/js/components/ascribe_table/table_item_wrapper.js

63 lines
2.2 KiB
JavaScript

'use strict';
import React from 'react';
import Router from 'react-router';
import { ColumnModel } from './models/table_models';
import TableColumnMixin from '../../mixins/table_column_mixin';
let Link = Router.Link;
let TableItemWrapper = React.createClass({
propTypes: {
columnList: React.PropTypes.arrayOf(React.PropTypes.instanceOf(ColumnModel)),
columnContent: React.PropTypes.object,
columnWidth: React.PropTypes.number.isRequired
},
mixins: [TableColumnMixin, Router.Navigation],
render() {
return (
<tr>
{this.props.columnList.map((column, i) => {
let TypeElement = column.displayType;
let typeElementProps = column.transformFn(this.props.columnContent);
let columnClass = this.calcColumnClasses(this.props.columnList, i, this.props.columnWidth);
if(!column.transition) {
return (
<td
className={'ascribe-table-item-column'}
key={i}>
<TypeElement {...typeElementProps} />
</td>
);
} 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 (
<td key={i}>
<Link
className={'ascribe-table-item-column'}
onClick={column.transition.callback}
{...linkProps}>
<TypeElement {...typeElementProps} />
</Link>
</td>
);
}
})}
</tr>
);
}
});
export default TableItemWrapper;