@@ -23,27 +23,39 @@ import SortIcon from '../../../assets/images/sort-icon.svg'
23
23
import Select from '../../Select'
24
24
import Loader from '../../Loader'
25
25
26
- import { CHALLENGE_STATUS , PAGE_SIZE , PAGINATION_PER_PAGE_OPTIONS } from '../../../config/constants'
27
- import { checkAdmin } from '../../../util/tc'
26
+ import { CHALLENGE_STATUS , PAGE_SIZE , PAGINATION_PER_PAGE_OPTIONS , PROJECT_ROLES } from '../../../config/constants'
27
+ import { checkAdmin , checkReadOnlyRoles } from '../../../util/tc'
28
28
29
29
require ( 'bootstrap/scss/bootstrap.scss' )
30
30
31
+ const defaultSearchParam = {
32
+ searchText : '' ,
33
+ challengeProjectOption : null ,
34
+ challengeStatus : '' ,
35
+ challengeType : null ,
36
+ sortBy : 'startDate' ,
37
+ sortOrder : 'desc' ,
38
+ challengeDate : { }
39
+ }
40
+
31
41
const theme = {
32
42
container : styles . modalContainer
33
43
}
34
44
35
45
class ChallengeList extends Component {
36
46
constructor ( props ) {
37
47
super ( props )
48
+
49
+ const defaultSearchParamClone = _ . cloneDeep ( defaultSearchParam )
38
50
this . state = {
39
- searchText : this . props . filterChallengeName ,
51
+ searchText : this . props . filterChallengeName || defaultSearchParamClone . searchText ,
40
52
errorMessage : null ,
41
- sortBy : this . props . filterSortBy || 'startDate' ,
42
- sortOrder : this . props . filterSortOrder || 'desc' ,
43
- challengeProjectOption : this . props . filterProjectOption ,
44
- challengeStatus : this . props . status ,
45
- challengeType : this . props . filterChallengeType ,
46
- challengeDate : this . props . filterDate
53
+ sortBy : this . props . filterSortBy || defaultSearchParamClone . sortBy ,
54
+ sortOrder : this . props . filterSortOrder || defaultSearchParamClone . sortOrder ,
55
+ challengeProjectOption : this . props . filterProjectOption || defaultSearchParamClone . challengeProjectOption ,
56
+ challengeStatus : this . props . status || defaultSearchParamClone . challengeStatus ,
57
+ challengeType : this . props . filterChallengeType || defaultSearchParamClone . challengeType ,
58
+ challengeDate : this . props . filterDate || defaultSearchParamClone . challengeDate
47
59
}
48
60
this . directUpdateSearchParam = this . updateSearchParam . bind ( this ) // update search param without debounce
49
61
this . handlePageChange = this . handlePageChange . bind ( this ) // update search param without debounce
@@ -312,22 +324,14 @@ class ChallengeList extends Component {
312
324
loadChallengesByPage
313
325
} = this . props
314
326
315
- this . setState ( {
316
- searchText : '' ,
317
- challengeProjectOption : null ,
318
- challengeStatus : '' ,
319
- challengeType : null ,
320
- sortBy : '' ,
321
- sortOrder : 'asc' ,
322
- challengeDate : { }
323
- } )
327
+ this . setState ( _ . cloneDeep ( defaultSearchParam ) )
324
328
325
329
let projectId = dashboard ? filterProjectOption : activeProjectId
326
330
327
331
loadChallengesByPage (
328
332
1 ,
329
333
projectId ,
330
- null ,
334
+ 'all' ,
331
335
'' ,
332
336
selfService ,
333
337
this . getHandle ( ) ,
@@ -372,6 +376,8 @@ class ChallengeList extends Component {
372
376
challengeTypes,
373
377
loginUserRoleInProject
374
378
} = this . props
379
+ const isReadOnly = checkReadOnlyRoles ( this . props . auth . token ) || loginUserRoleInProject === PROJECT_ROLES . READ
380
+
375
381
if ( warnMessage ) {
376
382
return < Message warnMessage = { warnMessage } />
377
383
}
@@ -688,7 +694,8 @@ class ChallengeList extends Component {
688
694
</ div >
689
695
< div className = { styles . header } >
690
696
< div
691
- className = { cn ( styles . col5 ) }
697
+ className = { cn ( styles . col5 , styles . sortable ) }
698
+ onClick = { ( ) => this . updateSort ( 'type' ) }
692
699
>
693
700
< span className = { styles . filterItem } >
694
701
Type
@@ -741,14 +748,15 @@ class ChallengeList extends Component {
741
748
</ span >
742
749
</ div >
743
750
< div
744
- className = { cn ( styles . col3 ) }
751
+ className = { cn ( styles . col3 , styles . sortable ) }
752
+ onClick = { ( ) => this . updateSort ( 'status' ) }
745
753
>
746
754
< span className = { styles . filterItem } >
747
755
Status
748
756
{ this . renderSortIcon ( 'status' ) }
749
757
</ span >
750
758
</ div >
751
- < div className = { styles . col6 } > </ div >
759
+ { ! isReadOnly ? ( < div className = { styles . col6 } > </ div > ) : null }
752
760
< div className = { styles . col6 } > </ div >
753
761
< div className = { styles . col6 } > </ div >
754
762
</ div >
0 commit comments