@@ -71,41 +71,50 @@ ShareURL.propTypes = {
71
71
value : PropTypes . string . isRequired ,
72
72
} ;
73
73
74
- class CollectionItemRowBase extends React . Component {
75
- handleSketchRemove = ( ) => {
76
- if ( window . confirm ( `Are you sure you want to remove "${ this . props . item . project . name } " from this collection?` ) ) {
77
- this . props . removeFromCollection ( this . props . collection . id , this . props . item . project . id ) ;
74
+ const CollectionItemRowBase = ( {
75
+ collection, item, isOwner, removeFromCollection
76
+ } ) => {
77
+ const projectIsDeleted = item . isDeleted ;
78
+
79
+ const handleSketchRemove = ( ) => {
80
+ const name = projectIsDeleted ? 'deleted sketch' : item . project . name ;
81
+
82
+ if ( window . confirm ( `Are you sure you want to remove "${ name } " from this collection?` ) ) {
83
+ removeFromCollection ( collection . id , item . projectId ) ;
78
84
}
79
- }
85
+ } ;
80
86
81
- render ( ) {
82
- const { item } = this . props ;
83
- const sketchOwnerUsername = item . project . user . username ;
84
- const sketchUrl = `/${ item . project . user . username } /sketches/${ item . project . id } ` ;
87
+ const name = projectIsDeleted ? < span > Sketch was deleted</ span > : (
88
+ < Link to = { `/${ item . project . user . username } /sketches/${ item . projectId } ` } >
89
+ { item . project . name }
90
+ </ Link >
91
+ ) ;
85
92
86
- return (
87
- < tr
88
- className = "sketches-table__row"
89
- >
90
- < th scope = "row" >
91
- < Link to = { sketchUrl } >
92
- { item . project . name }
93
- </ Link >
94
- </ th >
95
- < td > { format ( new Date ( item . createdAt ) , 'MMM D, YYYY h:mm A' ) } </ td >
96
- < td > { sketchOwnerUsername } </ td >
97
- < td className = "collection-row__action-column " >
93
+ const sketchOwnerUsername = projectIsDeleted ? null : item . project . user . username ;
94
+
95
+ return (
96
+ < tr
97
+ className = { `sketches-table__row ${ projectIsDeleted ? 'is-deleted' : '' } ` }
98
+ >
99
+ < th scope = "row" >
100
+ { name }
101
+ </ th >
102
+ < td > { format ( new Date ( item . createdAt ) , 'MMM D, YYYY h:mm A' ) } </ td >
103
+ < td > { sketchOwnerUsername } </ td >
104
+ < td className = "collection-row__action-column " >
105
+ { isOwner &&
98
106
< button
99
107
className = "collection-row__remove-button"
100
- onClick = { this . handleSketchRemove }
108
+ onClick = { handleSketchRemove }
101
109
aria-label = "Remove sketch from collection"
102
110
>
103
111
< RemoveIcon focusable = "false" aria-hidden = "true" />
104
112
</ button >
105
- </ td >
106
- </ tr > ) ;
107
- }
108
- }
113
+ }
114
+ </ td >
115
+ </ tr > ) ;
116
+ } ;
117
+
109
118
110
119
CollectionItemRowBase . propTypes = {
111
120
collection : PropTypes . shape ( {
@@ -114,14 +123,17 @@ CollectionItemRowBase.propTypes = {
114
123
} ) . isRequired ,
115
124
item : PropTypes . shape ( {
116
125
createdAt : PropTypes . string . isRequired ,
126
+ projectId : PropTypes . string . isRequired ,
127
+ isDeleted : PropTypes . bool . isRequired ,
117
128
project : PropTypes . shape ( {
118
129
id : PropTypes . string . isRequired ,
119
130
name : PropTypes . string . isRequired ,
120
131
user : PropTypes . shape ( {
121
132
username : PropTypes . string . isRequired
122
- } )
133
+ } ) ,
123
134
} ) . isRequired ,
124
135
} ) . isRequired ,
136
+ isOwner : PropTypes . bool . isRequired ,
125
137
user : PropTypes . shape ( {
126
138
username : PropTypes . string ,
127
139
authenticated : PropTypes . bool . isRequired
@@ -342,6 +354,7 @@ class Collection extends React.Component {
342
354
343
355
render ( ) {
344
356
const title = this . hasCollection ( ) ? this . getCollectionName ( ) : null ;
357
+ const isOwner = this . isOwner ( ) ;
345
358
346
359
return (
347
360
< main className = "collection-container" data-has-items = { this . hasCollectionItems ( ) ? 'true' : 'false' } >
@@ -372,6 +385,7 @@ class Collection extends React.Component {
372
385
user = { this . props . user }
373
386
username = { this . getUsername ( ) }
374
387
collection = { this . props . collection }
388
+ isOwner = { isOwner }
375
389
/> ) ) }
376
390
</ tbody >
377
391
</ table >
0 commit comments