application/components/author/author-table.js
import React from 'react';
import {Table, TableBody, TableHeader, TableHeaderColumn, TableRow, TableRowColumn} from 'material-ui/Table';
import {Link} from 'react-router';
import {timeToFormat, parameterize} from './../../util/strings';
class AuthorTable extends React.Component {
constructor(props) {
super(props);
this.state = {
selected: []
};
}
handleRowSelection(selection) {
this.setState({'selected': selection});
this.props.onRowSelection(selection);
}
renderLinkTo(author, label) {
return (
<Link to={'/ceo/settings/author/' + author.get('uuid')} className="truncate">
{label}
</Link>
);
}
render() {
if (!this.props.authors.items.size) {
return <div>No authors!</div>;
}
return (
<Table
fixedHeader={true}
selectable={true}
multiSelectable={true}
onRowSelection={this.handleRowSelection.bind(this)}
>
<TableHeader>
<TableRow>
<TableHeaderColumn>Name</TableHeaderColumn>
<TableHeaderColumn>Slug</TableHeaderColumn>
</TableRow>
</TableHeader>
<TableBody
deselectOnClickaway={false}
>
{this.props.authors.items.map((author, i) => {
return (
<TableRow key={i} selected={this.state.selected == 'all' || this.state.selected.indexOf(i) != -1 ? true : false}>
<TableRowColumn>{this.renderLinkTo(author, author.get('name'))}</TableRowColumn>
<TableRowColumn>{this.renderLinkTo(author, author.get('slug') ? author.get('slug') : (<span className="invalid">No slug</span>))}</TableRowColumn>
</TableRow>
);
})}
</TableBody>
</Table>
);
}
}
export default AuthorTable;