Files
Iris/src/js/components/List.js

84 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-11-01 19:27:59 +13:00
import React, { PropTypes } from 'react'
2016-11-21 16:54:17 +13:00
import { Link, browserHistory } from 'react-router'
2016-11-11 23:21:51 +13:00
import FontAwesome from 'react-fontawesome'
2016-11-21 16:26:47 +13:00
import ArtistSentence from './ArtistSentence'
import * as helpers from '../helpers'
2016-11-01 19:27:59 +13:00
export default class List extends React.Component{
constructor(props) {
super(props);
}
2016-11-21 16:54:17 +13:00
handleClick(e, uri){
// make sure we haven't clicked a nested link (ie Artist name)
if( e.target.tagName.toLowerCase() !== 'a' ){
browserHistory.push( this.props.link_prefix + encodeURIComponent(uri) );
}
}
2016-11-01 19:27:59 +13:00
renderHeader(){
if( !this.props.columns ) return null
return (
<div className="list-item header cf">
{
this.props.columns.map( (col, col_index) => {
2016-11-21 16:26:47 +13:00
return <div className={'col w'+col.width} key={col_index}>{ col.label ? col.label : col.name }</div>
2016-11-01 19:27:59 +13:00
})
}
</div>
)
}
renderValue( row, key_string ){
var key = key_string.split('.')
2016-11-21 16:26:47 +13:00
var value = row
for( var i = 0; i < key.length; i++ ){
if( typeof(value[key[i]]) !== 'undefined' ){
value = value[key[i]]
}else{
return <span>-</span>
}
}
if( key_string === 'owner' ) return <Link to={ '/user/'+ value.uri }>{value.id}</Link>
2016-11-21 16:26:47 +13:00
if( key[0] === 'artists' ) return <ArtistSentence artists={value} />
2016-11-11 23:21:51 +13:00
if( value === true ) return <FontAwesome name="check" />
2016-11-21 16:26:47 +13:00
if( typeof(value) === 'number' ) return <span>{value.toLocaleString()}</span>
2016-11-11 23:21:51 +13:00
return <span>{value}</span>
}
2016-11-01 19:27:59 +13:00
render(){
if( !this.props.rows ) return null
2016-11-01 19:27:59 +13:00
return (
<div className="list">
{ this.renderHeader() }
{
this.props.rows.map( (row, row_index) => {
return (
2016-11-21 16:54:17 +13:00
<div onClick={ e => this.handleClick(e, row.uri)} className="list-item cf" key={row_index}>
2016-11-01 19:27:59 +13:00
{
this.props.columns.map( (col, col_index) => {
2016-11-02 21:23:35 +13:00
return (
<div className={'col w'+col.width} key={col_index}>
2016-11-21 16:26:47 +13:00
{ this.renderValue(row, col.name) }
2016-11-02 21:23:35 +13:00
</div>
)
2016-11-01 19:27:59 +13:00
})
}
2016-11-21 16:26:47 +13:00
{ this.props.show_source_icon ? <FontAwesome className="source" name={helpers.sourceIcon(row.uri)} /> : null }
2016-11-21 16:54:17 +13:00
</div>
2016-11-01 19:27:59 +13:00
)
})
}
</div>
);
}
}