@@ -5,9 +5,12 @@ import Section from '../../components/section'
55import Table from '../../components/tables/table'
66import theme from '../../styles/theme'
77import join from 'url-join'
8- import { pick , map } from 'ramda'
8+ import { pick , map , sort , descend , ascend , prop } from 'ramda'
99import { getTeams } from '../../lib/teams-api'
1010import logger from '../../lib/logger'
11+ import { serverRuntimeConfig } from '../../../next.config.js'
12+ import Pagination from '../../components/pagination'
13+ const { DEFAULT_PAGE_SIZE } = serverRuntimeConfig
1114
1215const Map = dynamic ( import ( '../../components/list-map' ) , {
1316 ssr : false ,
@@ -24,6 +27,11 @@ export default class TeamList extends Component {
2427 teams : [ ] ,
2528 searchOnMapMove : false ,
2629 mapBounds : undefined ,
30+ page : 1 ,
31+ sortOptions : {
32+ key : 'name' ,
33+ direction : 'asc' ,
34+ } ,
2735 }
2836 }
2937
@@ -51,24 +59,50 @@ export default class TeamList extends Component {
5159 }
5260
5361 renderTeams ( ) {
54- const { teams } = this . state
62+ const { teams, sortOptions , page } = this . state
5563 if ( ! teams ) return null
5664
57- if ( teams . length === 0 ) {
58- return < p > No teams created</ p >
59- }
65+ const columns = [
66+ { key : 'name' , sortable : true } ,
67+ { key : 'id' , sortable : true } ,
68+ { key : 'hashtag' , sortable : true } ,
69+ ]
70+
71+ let rows = sort (
72+ sortOptions . direction === 'asc'
73+ ? ascend ( prop ( sortOptions . key ) )
74+ : descend ( prop ( sortOptions . key ) ) ,
75+ teams
76+ )
77+
78+ // Calculate start and end index
79+ const pageStartIndex = ( page - 1 ) * DEFAULT_PAGE_SIZE
80+ const pageEndIndex = pageStartIndex + DEFAULT_PAGE_SIZE
6081
6182 return (
62- < Table
63- rows = { teams }
64- columns = { [ { key : 'name' } , { key : 'id' } , { key : 'hashtag' } ] }
65- onRowClick = { ( row ) => {
66- Router . push (
67- join ( URL , `/team?id=${ row . id } ` ) ,
68- join ( URL , `/teams/${ row . id } ` )
69- )
70- } }
71- />
83+ < >
84+ < Table
85+ data-cy = { `teams-table` }
86+ columns = { columns }
87+ rows = { rows . slice ( pageStartIndex , pageEndIndex ) }
88+ onRowClick = { ( row ) => {
89+ Router . push ( join ( URL , `/teams/${ row . id } ` ) )
90+ } }
91+ emptyPlaceHolder = { 'No teams created yet.' }
92+ showRowNumbers
93+ sort = { sortOptions }
94+ setSort = { ( s ) => this . setState ( { sortOptions : s } ) }
95+ />
96+ < Pagination
97+ data-cy = { `teams-table-pagination` }
98+ pagination = { {
99+ perPage : DEFAULT_PAGE_SIZE ,
100+ total : rows . length ,
101+ currentPage : page ,
102+ } }
103+ setPage = { ( p ) => this . setState ( { page : p } ) }
104+ />
105+ </ >
72106 )
73107 }
74108
0 commit comments