@@ -62,28 +62,37 @@ export default class Resources extends React.Component {
62
62
sort : ''
63
63
} ,
64
64
selectedTab : 0 ,
65
- showDeleteResourceModal : null
65
+ showDeleteResourceModal : null ,
66
+ exceptionHandlesDeleteList : { }
66
67
}
67
68
68
69
this . sortResources = this . sortResources . bind ( this )
69
70
this . getResourcesSortParam = this . getResourcesSortParam . bind ( this )
70
71
this . updateSortedResources = this . updateSortedResources . bind ( this )
72
+ this . updateExceptionHandlesDelete = this . updateExceptionHandlesDelete . bind ( this )
71
73
this . onSortChange = this . onSortChange . bind ( this )
72
74
this . setSelectedTab = this . setSelectedTab . bind ( this )
73
75
}
74
76
75
77
componentDidMount ( ) {
76
78
this . updateSortedResources ( )
79
+ this . updateExceptionHandlesDelete ( )
77
80
}
78
81
79
82
componentDidUpdate ( prevProps ) {
80
- const { resources, resourcesSort } = this . props
83
+ const { resources, resourcesSort, submissions , challenge } = this . props
81
84
if (
82
85
! _ . isEqual ( prevProps . resources , resources ) ||
83
86
! _ . isEqual ( prevProps . resourcesSort , resourcesSort )
84
87
) {
85
88
this . updateSortedResources ( )
86
89
}
90
+ if (
91
+ ! _ . isEqual ( prevProps . submissions , submissions ) ||
92
+ ! _ . isEqual ( prevProps . challenge , challenge )
93
+ ) {
94
+ this . updateExceptionHandlesDelete ( )
95
+ }
87
96
}
88
97
onSortChange ( sort ) {
89
98
this . setState ( {
@@ -129,6 +138,20 @@ export default class Resources extends React.Component {
129
138
this . setState ( { sortedResources } )
130
139
}
131
140
141
+ /**
142
+ * Update exception handles delete
143
+ * Don't allow deletion of submitters who submitted, or creator of challenge
144
+ */
145
+ updateExceptionHandlesDelete ( ) {
146
+ const { submissions, challenge } = this . props
147
+ const exceptionHandlesDeleteList = { }
148
+ exceptionHandlesDeleteList [ challenge . createdBy ] = true
149
+ _ . forEach ( submissions , ( s ) => {
150
+ exceptionHandlesDeleteList [ s . createdBy ] = true
151
+ } )
152
+ this . setState ( { exceptionHandlesDeleteList } )
153
+ }
154
+
132
155
/**
133
156
* Sort array of registrant
134
157
* @param {Array } resources array of registrant
@@ -186,7 +209,7 @@ export default class Resources extends React.Component {
186
209
const { challenge, canEditResource, deleteResource } = this . props
187
210
const { track } = challenge
188
211
189
- const { sortedResources, selectedTab, showDeleteResourceModal } = this . state
212
+ const { sortedResources, selectedTab, showDeleteResourceModal, exceptionHandlesDeleteList } = this . state
190
213
191
214
const { field, sort } = this . getResourcesSortParam ( )
192
215
const revertSort = sort === 'desc' ? 'asc' : 'desc'
@@ -353,17 +376,18 @@ export default class Resources extends React.Component {
353
376
< span role = 'cell' > { formatDate ( r . created ) } </ span >
354
377
</ td >
355
378
356
- { canEditResource ? ( < td className = { cn ( styles [ 'col-8Table' ] , styles [ 'col-bodyTable' ] ) } >
357
- < button
358
- onClick = { ( ) => {
359
- this . setState ( {
360
- showDeleteResourceModal : r
361
- } )
362
- } }
363
- >
364
- < ReactSVG path = { assets ( `${ Trash } ` ) } />
365
- </ button >
366
- </ td > ) : null }
379
+ { ( canEditResource && ! exceptionHandlesDeleteList [ r . memberHandle ] ) ? (
380
+ < td className = { cn ( styles [ 'col-8Table' ] , styles [ 'col-bodyTable' ] ) } >
381
+ < button
382
+ onClick = { ( ) => {
383
+ this . setState ( {
384
+ showDeleteResourceModal : r
385
+ } )
386
+ } }
387
+ >
388
+ < ReactSVG path = { assets ( `${ Trash } ` ) } />
389
+ </ button >
390
+ </ td > ) : null }
367
391
</ tr >
368
392
)
369
393
} ) }
@@ -383,7 +407,8 @@ export default class Resources extends React.Component {
383
407
Resources . defaultProps = {
384
408
results : [ ] ,
385
409
checkpointResults : { } ,
386
- resourcesSort : { }
410
+ resourcesSort : { } ,
411
+ submissions : [ ]
387
412
}
388
413
389
414
Resources . propTypes = {
@@ -404,6 +429,7 @@ Resources.propTypes = {
404
429
type : PT . string ,
405
430
track : PT . string
406
431
} ) . isRequired ,
432
+ submissions : PT . arrayOf ( PT . shape ( ) ) ,
407
433
resources : PT . arrayOf ( PT . shape ( ) ) ,
408
434
resourcesSort : PT . shape ( {
409
435
field : PT . string ,
0 commit comments