@@ -2,11 +2,11 @@ import React, { Component, PropTypes } from 'react';
22import { Link } from 'react-router' ;
33import { connect } from 'react-redux' ;
44import { get , find , keyBy } from 'lodash' ;
5- import { Button , Table } from 'reactstrap' ;
5+ import { Button } from 'reactstrap' ;
66
77import { fetchList , getMap , getMany } from '../../store/api' ;
88import { withResourceList } from '../../hocs' ;
9- import { ListHeader , Pagination } from '../UI' ;
9+ import { ListHeader , ListTable } from '../UI' ;
1010import PostListFilter from './PostListFilter' ;
1111
1212const formatDate = date => ( new Date ( date ) ) . toLocaleString ( ) ;
@@ -24,7 +24,27 @@ export class PostList extends Component {
2424 }
2525
2626 render ( ) {
27- const { resourceList, onFilter, onSort, categories } = this . props ;
27+ const { resourceList, onFilter, categories } = this . props ;
28+
29+ const columns = [
30+ {
31+ header : 'Category' ,
32+ minWidth : '50px' ,
33+ rowRender : post => this . getCategoryForPost ( post ) . name ,
34+ } ,
35+ {
36+ attribute : 'title' ,
37+ header : 'Title' ,
38+ rowRender : post => < Link to = { `/posts/${ post . id } ` } > { post . title } </ Link > ,
39+ sortable : true ,
40+ } ,
41+ {
42+ attribute : 'createdAt' ,
43+ header : 'Created At' ,
44+ rowRender : post => formatDate ( post . createdAt ) ,
45+ sortable : true ,
46+ } ,
47+ ] ;
2848
2949 return (
3050 < div >
@@ -36,46 +56,7 @@ export class PostList extends Component {
3656 categories = { categories } >
3757 </ PostListFilter >
3858
39- < Table >
40- < thead >
41- < tr >
42- < th >
43- Category
44- </ th >
45- < th >
46- Title
47- < select name = "sort" value = { resourceList . params . sort } onChange = { onSort } >
48- < option value = "title" > Asc</ option >
49- < option value = "-title" > Desc</ option >
50- </ select >
51- </ th >
52- < th >
53- Created at
54- < select name = "sort" value = { resourceList . params . sort } onChange = { onSort } >
55- < option value = "createdAt" > Asc</ option >
56- < option value = "-createdAt" > Desc</ option >
57- </ select >
58- </ th >
59- </ tr >
60- </ thead >
61- < tbody >
62- { resourceList . data . map ( post =>
63- < tr key = { post . id } >
64- < td >
65- { this . getCategoryForPost ( post ) . name }
66- </ td >
67- < td >
68- < Link to = { `/posts/${ post . id } ` } > { post . title } </ Link >
69- </ td >
70- < td >
71- { formatDate ( post . createdAt ) }
72- </ td >
73- </ tr >
74- ) }
75- </ tbody >
76- </ Table >
77- < Pagination { ...this . props } > </ Pagination >
78- { resourceList . empty && resourceList . loading && < p > Loading...</ p > }
59+ < ListTable { ...this . props } columns = { columns } />
7960 </ div >
8061 ) ;
8162 }
0 commit comments