@@ -12,7 +12,7 @@ import DateTime from '@nateradebaugh/react-datetime'
1212import Pagination from 'react-js-pagination'
1313import cn from 'classnames'
1414
15- import { PrimaryButton } from '../../Buttons'
15+ import { OutlineButton , PrimaryButton } from '../../Buttons'
1616import Modal from '../../Modal'
1717import 'react-tabs/style/react-tabs.css'
1818import styles from './ChallengeList.module.scss'
@@ -22,7 +22,7 @@ import Message from '../Message'
2222import SortIcon from '../../../assets/images/sort-icon.svg'
2323import Select from '../../Select'
2424
25- import { CHALLENGE_STATUS } from '../../../config/constants'
25+ import { CHALLENGE_STATUS , PAGE_SIZE , PAGINATION_PER_PAGE_OPTIONS } from '../../../config/constants'
2626import { checkAdmin } from '../../../util/tc'
2727
2828require ( 'bootstrap/scss/bootstrap.scss' )
@@ -46,12 +46,14 @@ class ChallengeList extends Component {
4646 }
4747 this . directUpdateSearchParam = this . updateSearchParam . bind ( this ) // update search param without debounce
4848 this . handlePageChange = this . handlePageChange . bind ( this ) // update search param without debounce
49+ this . handlePerPageChange = this . handlePerPageChange . bind ( this )
4950 this . showError = this . showError . bind ( this )
5051 this . hideError = this . hideError . bind ( this )
5152 this . reloadChallengeList = this . reloadChallengeList . bind ( this )
5253 this . updateSearchParam = debounce ( this . updateSearchParam . bind ( this ) , 1000 )
5354 this . updateSort = this . updateSort . bind ( this )
5455 this . update = debounce ( this . updateSearchParam . bind ( this ) , 1000 )
56+ this . resetFilter = this . resetFilter . bind ( this )
5557 }
5658
5759 /**
@@ -111,7 +113,7 @@ class ChallengeList extends Component {
111113
112114 /**
113115 * Update filter for getting project by pagination
114- * @param {Number } pageNumber page numer
116+ * @param {Number } pageNumber page number
115117 */
116118 handlePageChange ( pageNumber ) {
117119 const { searchText } = this . state
@@ -142,6 +144,44 @@ class ChallengeList extends Component {
142144 }
143145 }
144146
147+ /**
148+ * Update filter for getting project by pagination
149+ * @param {Number } perPageNumber per page number
150+ */
151+ handlePerPageChange ( option ) {
152+ const perPageNumber = option . value
153+ const { searchText, sortBy, sortOrder } = this . state
154+ const {
155+ perPage,
156+ page,
157+ loadChallengesByPage,
158+ activeProjectId,
159+ dashboard,
160+ filterProjectOption,
161+ status,
162+ selfService,
163+ filterChallengeType,
164+ filterDate
165+ } = this . props
166+
167+ let projectId = dashboard ? filterProjectOption : activeProjectId
168+ if ( perPage !== perPageNumber ) {
169+ loadChallengesByPage (
170+ page ,
171+ projectId ,
172+ status ,
173+ searchText ,
174+ selfService ,
175+ this . getHandle ( ) ,
176+ filterChallengeType ,
177+ filterDate ,
178+ sortBy ,
179+ sortOrder ,
180+ perPageNumber
181+ )
182+ }
183+ }
184+
145185 /**
146186 * Reload challenge list
147187 */
@@ -259,6 +299,40 @@ class ChallengeList extends Component {
259299 ) : null
260300 }
261301
302+ resetFilter ( ) {
303+ const {
304+ activeProjectId,
305+ dashboard,
306+ filterProjectOption,
307+ selfService,
308+ loadChallengesByPage
309+ } = this . props
310+
311+ this . setState ( {
312+ searchText : '' ,
313+ challengeType : null ,
314+ sortBy : '' ,
315+ sortOrder : 'asc' ,
316+ challengeDate : { }
317+ } )
318+
319+ let projectId = dashboard ? filterProjectOption : activeProjectId
320+
321+ loadChallengesByPage (
322+ 1 ,
323+ projectId ,
324+ null ,
325+ '' ,
326+ selfService ,
327+ this . getHandle ( ) ,
328+ null ,
329+ { } ,
330+ null ,
331+ null ,
332+ PAGE_SIZE
333+ )
334+ }
335+
262336 render ( ) {
263337 const {
264338 searchText,
@@ -423,22 +497,30 @@ class ChallengeList extends Component {
423497 </ div >
424498 ) }
425499 < div className = { styles [ 'col-6' ] } >
426- < DebounceInput
427- className = { styles . challengeInput }
428- minLength = { 2 }
429- debounceTimeout = { 300 }
430- placeholder = 'Search Challenges'
431- onChange = { e =>
432- this . updateSearchParam (
433- e . target . value ,
434- status ,
435- challengeType ,
436- challengeDate ,
437- projectOption
438- )
439- }
440- value = { searchText }
441- />
500+ < div className = { cn ( styles . field , styles . input1 ) } >
501+ < label htmlFor = 'startDate' > Search :</ label >
502+ </ div >
503+ < div className = { styles [ 'searchInputWrapper' ] } >
504+ < DebounceInput
505+ className = { styles . challengeInput }
506+ minLength = { 2 }
507+ debounceTimeout = { 300 }
508+ placeholder = 'Search Challenges'
509+ onChange = { e =>
510+ this . updateSearchParam (
511+ e . target . value ,
512+ status ,
513+ challengeType ,
514+ challengeDate ,
515+ projectOption
516+ )
517+ }
518+ value = { searchText }
519+ />
520+ < div className = { styles [ 'resetFilter' ] } >
521+ < OutlineButton text = 'Reset Filters' type = { 'info' } onClick = { this . resetFilter } />
522+ </ div >
523+ </ div >
442524 </ div >
443525 </ div >
444526 < div className = { styles . row } >
@@ -699,16 +781,28 @@ class ChallengeList extends Component {
699781 } ) }
700782 </ ul >
701783 ) }
702- < div className = { styles . paginationContainer } >
703- < Pagination
704- activePage = { page }
705- itemsCountPerPage = { perPage }
706- totalItemsCount = { totalChallenges }
707- pageRangeDisplayed = { 5 }
708- onChange = { this . handlePageChange }
709- itemClass = 'page-item'
710- linkClass = 'page-link'
711- />
784+ < div className = { styles . footer } >
785+ < div className = { styles . perPageContainer } >
786+ < Select
787+ styles = { styles }
788+ name = 'perPage'
789+ value = { { label : perPage , value : perPage } }
790+ placeholder = 'Per page'
791+ options = { PAGINATION_PER_PAGE_OPTIONS }
792+ onChange = { this . handlePerPageChange }
793+ />
794+ </ div >
795+ < div className = { styles . paginationContainer } >
796+ < Pagination
797+ activePage = { page }
798+ itemsCountPerPage = { perPage }
799+ totalItemsCount = { totalChallenges }
800+ pageRangeDisplayed = { 5 }
801+ onChange = { this . handlePageChange }
802+ itemClass = 'page-item'
803+ linkClass = 'page-link'
804+ />
805+ </ div >
712806 </ div >
713807 { warningModal }
714808 </ div >
0 commit comments