@@ -11,11 +11,13 @@ import ActivityTimestamp from '../common/activity-timestamp';
1111import Avatar from '../Avatar' ;
1212import Checkmark16 from '../../../../icon/line/Checkmark16' ;
1313import CommentForm from '../comment-form' ;
14+ import CreateReply from './CreateReply' ;
1415import DeleteConfirmation from '../common/delete-confirmation' ;
1516import LoadingIndicator from '../../../../components/loading-indicator' ;
1617import Media from '../../../../components/media' ;
1718import messages from './messages' ;
1819import Pencil16 from '../../../../icon/line/Pencil16' ;
20+ import RepliesToggle from './RepliesToggle' ;
1921import Trash16 from '../../../../icon/line/Trash16' ;
2022import UserLink from '../common/user-link' ;
2123import X16 from '../../../../icon/fill/X16' ;
@@ -61,10 +63,13 @@ type BaseCommentProps = {
6163 onSuccess : ?Function ,
6264 onError : ?Function ,
6365 ) => void ,
64- onReplySelect ?: ( isSelected : boolean ) => void ,
66+ onHideReplies ?: ( shownReplies : CommentType [ ] ) => void ,
67+ onReplyCreate ?: ( reply : string ) => void ,
6568 onSelect : ( isSelected : boolean ) => void ,
69+ onShowReplies ?: ( ) => void ,
6670 permissions : BoxCommentPermission ,
6771 replies ?: CommentType [ ] ,
72+ repliesTotalCount ? : number ,
6873 status ? : FeedItemStatus ,
6974 tagged_message : string ,
7075 translatedTaggedMessage ? : string ,
@@ -78,7 +83,7 @@ const BaseComment = (props: BaseCommentProps) => {
7883 created_at,
7984 permissions = { } ,
8085 id,
81- isPending,
86+ isPending = false ,
8287 isRepliesLoading = false ,
8388 error,
8489 tagged_message = '' ,
@@ -95,66 +100,61 @@ const BaseComment = (props: BaseCommentProps) => {
95100 onDelete,
96101 onEdit,
97102 onSelect,
98- onReplySelect = noop ,
103+ onReplyCreate,
104+ onShowReplies,
105+ onHideReplies,
99106 replies = [ ] ,
107+ repliesTotalCount = 0 ,
100108 status,
101109 } = props ;
102110
103111 const [ isConfirmingDelete , setIsConfirmingDelete ] = React . useState < boolean > ( false ) ;
104112 const [ isEditing , setIsEditing ] = React . useState < boolean > ( false ) ;
105113 const [ isInputOpen , setIsInputOpen ] = React . useState < boolean > ( false ) ;
106114
107- const selectComment = ( isSelected : boolean = true ) : void => {
108- onSelect ( isSelected ) ;
109- } ;
110-
111115 const handleDeleteConfirm = ( ) : void => {
112116 onDelete ( { id, permissions } ) ;
113- selectComment ( false ) ;
117+ onSelect ( false ) ;
114118 } ;
115119
116120 const handleDeleteCancel = ( ) : void => {
117121 setIsConfirmingDelete ( false ) ;
118- selectComment ( false ) ;
122+ onSelect ( false ) ;
119123 } ;
120124
121125 const handleDeleteClick = ( ) : void => {
122126 setIsConfirmingDelete ( true ) ;
123- selectComment ( ) ;
127+ onSelect ( true ) ;
124128 } ;
125129
126130 const handleEditClick = ( ) : void => {
127131 setIsEditing ( true ) ;
128132 setIsInputOpen ( true ) ;
129- selectComment ( ) ;
133+ onSelect ( true ) ;
130134 } ;
131135
132136 const handleMenuClose = ( ) : void => {
133137 if ( isConfirmingDelete || isEditing || isInputOpen ) {
134138 return ;
135139 }
136- selectComment ( false ) ;
137- } ;
138-
139- const handleMenuOpen = ( ) : void => {
140- selectComment ( ) ;
140+ onSelect ( false ) ;
141141 } ;
142142
143143 const commentFormFocusHandler = ( ) : void => {
144144 setIsInputOpen ( true ) ;
145- selectComment ( ) ;
145+ onSelect ( true ) ;
146146 } ;
147147
148148 const commentFormCancelHandler = ( ) : void => {
149149 setIsInputOpen ( false ) ;
150150 setIsEditing ( false ) ;
151- selectComment ( false ) ;
151+ onSelect ( false ) ;
152152 } ;
153153
154154 const commentFormSubmitHandler = ( ) : void => {
155155 setIsInputOpen ( false ) ;
156156 setIsEditing ( false ) ;
157- selectComment ( false ) ;
157+ onSelect ( false ) ;
158158 } ;
159159
160160 const handleMessageUpdate = ( {
@@ -214,7 +214,7 @@ const BaseComment = (props: BaseCommentProps) => {
214214 isDisabled = { isConfirmingDelete }
215215 data-testid = "comment-actions-menu"
216216 dropdownProps = { {
217- onMenuOpen : handleMenuOpen ,
217+ onMenuOpen : ( ) => onSelect ( true ) ,
218218 onMenuClose : handleMenuClose ,
219219 } }
220220 menuProps = { {
@@ -323,9 +323,14 @@ const BaseComment = (props: BaseCommentProps) => {
323323 { hasReplies && (
324324 < Replies
325325 { ...commentProps }
326+ isParentPending = { isPending }
326327 isRepliesLoading = { isRepliesLoading }
327- onReplySelect = { onReplySelect }
328+ onHideReplies = { onHideReplies }
329+ onReplyCreate = { onReplyCreate }
330+ onReplySelect = { onSelect }
331+ onShowReplies = { onShowReplies }
328332 replies = { replies }
333+ repliesTotalCount = { repliesTotalCount }
329334 />
330335 ) }
331336 </ div >
@@ -338,10 +343,15 @@ type RepliesProps = {
338343 getAvatarUrl : GetAvatarUrlCallback ,
339344 getMentionWithQuery ?: ( searchStr : string ) => void ,
340345 getUserProfileUrl ?: GetProfileUrlCallback ,
346+ isParentPending ? : boolean ,
341347 isRepliesLoading ? : boolean ,
342348 mentionSelectorContacts ?: SelectorItems < > ,
349+ onHideReplies ?: ( shownReplies : CommentType [ ] ) => void ,
350+ onReplyCreate ?: ( reply : string ) => void ,
343351 onReplySelect ?: ( isSelected : boolean ) => void ,
352+ onShowReplies ?: ( ) => void ,
344353 replies : CommentType [ ] ,
354+ repliesTotalCount ? : number ,
345355 translations ? : Translations ,
346356} ;
347357
@@ -350,12 +360,18 @@ const Replies = ({
350360 getAvatarUrl,
351361 getMentionWithQuery,
352362 getUserProfileUrl,
363+ isParentPending = false ,
353364 isRepliesLoading = false ,
354365 mentionSelectorContacts,
366+ onReplyCreate,
355367 onReplySelect = noop ,
368+ onShowReplies,
369+ onHideReplies,
356370 replies,
371+ repliesTotalCount = 0 ,
357372 translations,
358373} : RepliesProps ) => {
374+ const [ showReplyForm , setShowReplyForm ] = React . useState ( false ) ;
359375 const getReplyPermissions = ( reply : CommentType ) : BoxCommentPermission => {
360376 const { permissions : { can_delete = false , can_edit = false , can_resolve = false } = { } } = reply ;
361377 return {
@@ -365,8 +381,31 @@ const Replies = ({
365381 } ;
366382 } ;
367383
384+ const handleNewReplyButton = ( ) => {
385+ setShowReplyForm ( true ) ;
386+ onReplySelect ( true ) ;
387+ } ;
388+
389+ const handleCancelNewReply = ( ) => {
390+ setShowReplyForm ( false ) ;
391+ onReplySelect ( false ) ;
392+ } ;
393+
394+ const handleSubmitNewReply = ( reply : string , replyCreate : ( reply : string ) => void ) => {
395+ setShowReplyForm ( false ) ;
396+ replyCreate ( reply ) ;
397+ } ;
398+
368399 return (
369400 < div className = "bcs-Replies" >
401+ { ! ! onShowReplies && ! ! onHideReplies && (
402+ < RepliesToggle
403+ onHideReplies = { index => onHideReplies ( [ replies [ index ] ] ) }
404+ onShowReplies = { onShowReplies }
405+ repliesShownCount = { replies . length }
406+ repliesTotalCount = { repliesTotalCount }
407+ />
408+ ) }
370409 < div className = "bcs-Replies-content" >
371410 { isRepliesLoading && (
372411 < div className = "bcs-Replies-loading" data-testid = "replies-loading" >
@@ -385,6 +424,7 @@ const Replies = ({
385424 getAvatarUrl = { getAvatarUrl }
386425 getMentionWithQuery = { getMentionWithQuery }
387426 getUserProfileUrl = { getUserProfileUrl }
427+ isPending = { isParentPending || reply . isPending }
388428 mentionSelectorContacts = { mentionSelectorContacts }
389429 onSelect = { onReplySelect }
390430 onDelete = { noop }
@@ -397,6 +437,18 @@ const Replies = ({
397437 } ) }
398438 </ ol >
399439 </ div >
440+ { ! ! onReplyCreate && (
441+ < CreateReply
442+ getMentionWithQuery = { getMentionWithQuery }
443+ isDisabled = { isParentPending }
444+ mentionSelectorContacts = { mentionSelectorContacts }
445+ onCancel = { handleCancelNewReply }
446+ onClick = { handleNewReplyButton }
447+ onFocus = { ( ) => onReplySelect ( true ) }
448+ onSubmit = { reply => handleSubmitNewReply ( reply , onReplyCreate ) }
449+ showReplyForm = { showReplyForm }
450+ />
451+ ) }
400452 </ div >
401453 ) ;
402454} ;
0 commit comments