@@ -10,6 +10,7 @@ import TrashIcon from '../../assets/icons/icon-trash.svg'
1010import CloseIcon from '../../assets/icons/icon-close.svg'
1111import EditIcon from '../../assets/icons/icon-edit.svg'
1212import SaveIcon from '../../assets/icons/icon-save.svg'
13+ import UserAutoComplete from '../UserAutoComplete/UserAutoComplete'
1314
1415
1516export default class FileListItem extends React . Component {
@@ -19,6 +20,7 @@ export default class FileListItem extends React.Component {
1920 this . state = {
2021 title : props . title ,
2122 description : props . description ,
23+ userIds : props . userIds ,
2224 isEditing : false
2325 }
2426 this . handleSave = this . handleSave . bind ( this )
@@ -27,17 +29,19 @@ export default class FileListItem extends React.Component {
2729 this . validateForm = this . validateForm . bind ( this )
2830 this . validateTitle = this . validateTitle . bind ( this )
2931 this . onTitleChange = this . onTitleChange . bind ( this )
32+ this . onUserIdChange = this . onUserIdChange . bind ( this )
3033 }
3134
3235 onDelete ( ) {
3336 this . props . onDelete ( this . props . id )
3437 }
3538
3639 startEdit ( ) {
37- const { title, description} = this . props
40+ const { title, description, userIds } = this . props
3841 this . setState ( {
3942 title,
4043 description,
44+ userIds,
4145 isEditing : true
4246 } )
4347 }
@@ -48,7 +52,7 @@ export default class FileListItem extends React.Component {
4852 if ( ! _ . isEmpty ( errors ) ) {
4953 this . setState ( { errors } )
5054 } else {
51- this . props . onSave ( this . props . id , { title, description : this . refs . desc . value } , e )
55+ this . props . onSave ( this . props . id , { title, description : this . refs . desc . value , userIds : this . state . userIds } , e )
5256 this . setState ( { isEditing : false } )
5357 }
5458 }
@@ -74,9 +78,28 @@ export default class FileListItem extends React.Component {
7478 this . setState ( { errors } )
7579 }
7680
81+ onUserIdChange ( selectedHandles = '' ) {
82+ this . setState ( {
83+ userIds : this . handlesToUserIds ( selectedHandles . split ( ',' ) )
84+ } )
85+ }
86+
87+ userIdsToHandles ( userIds ) {
88+ const { projectMembers } = this . props
89+ userIds = userIds || [ ]
90+ return userIds . map ( userId => _ . get ( projectMembers [ userId ] , 'handle' ) )
91+ }
92+
93+ handlesToUserIds ( handles ) {
94+ const { projectMembers } = this . props
95+ const projectMembersByHandle = _ . mapKeys ( projectMembers , value => value . handle )
96+ handles = handles || [ ]
97+ return handles . filter ( handle => handle ) . map ( handle => _ . get ( projectMembersByHandle [ handle ] , 'userId' ) )
98+ }
99+
77100 renderEditing ( ) {
78- const { title, description} = this . props
79- const { errors } = this . state
101+ const { title, description, projectMembers , loggedInUser } = this . props
102+ const { errors, userIds } = this . state
80103 const onExitEdit = ( ) => this . setState ( { isEditing : false , errors : { } } )
81104 return (
82105 < div >
@@ -90,6 +113,11 @@ export default class FileListItem extends React.Component {
90113 { ( errors && errors . title ) && < div className = "error-message" > { errors . title } </ div > }
91114 < textarea defaultValue = { description } ref = "desc" maxLength = { 250 } className = "tc-textarea" />
92115 { ( errors && errors . desc ) && < div className = "error-message" > { errors . desc } </ div > }
116+ < UserAutoComplete onUpdate = { this . onUserIdChange }
117+ projectMembers = { projectMembers }
118+ loggedInUser = { loggedInUser }
119+ selectedUsers = { this . userIdsToHandles ( userIds ) . join ( ',' ) }
120+ />
93121 </ div >
94122 )
95123 }
@@ -156,6 +184,9 @@ FileListItem.propTypes = {
156184 createdAt : PropTypes . string . isRequired ,
157185 updatedByUser : PropTypes . object ,
158186 createdByUser : PropTypes . object . isRequired ,
187+ projectMembers : PropTypes . object . isRequired ,
188+ loggedInUser : PropTypes . object . isRequired ,
189+ userIds : PropTypes . array ,
159190
160191 /**
161192 * Callback fired when a save button is clicked
0 commit comments