@@ -44,7 +44,7 @@ export function CommentView(commentProps: Props) {
4444 const [ bodyMd , setBodyMd ] = useStateProp ( body ) ;
4545 const [ bodyHTMLState , setBodyHtml ] = useStateProp ( bodyHTML ) ;
4646 const { deleteComment, editComment, setDescription, pr } = useContext ( PullRequestContext ) ;
47- const currentDraft = pr . pendingCommentDrafts && pr . pendingCommentDrafts [ id ] ;
47+ const currentDraft = pr ? .pendingCommentDrafts && pr . pendingCommentDrafts [ id ] ;
4848 const [ inEditMode , setEditMode ] = useState ( ! ! currentDraft ) ;
4949 const [ showActionBar , setShowActionBar ] = useState ( false ) ;
5050
@@ -55,7 +55,7 @@ export function CommentView(commentProps: Props) {
5555 key = { `editComment${ id } ` }
5656 body = { currentDraft || bodyMd }
5757 onCancel = { ( ) => {
58- if ( pr . pendingCommentDrafts ) {
58+ if ( pr ? .pendingCommentDrafts ) {
5959 delete pr . pendingCommentDrafts [ id ] ;
6060 }
6161 setEditMode ( false ) ;
@@ -114,7 +114,7 @@ export function CommentView(commentProps: Props) {
114114 comment = { comment as IComment }
115115 bodyHTML = { bodyHTMLState }
116116 body = { bodyMd }
117- canApplyPatch = { pr . isCurrentlyCheckedOut }
117+ canApplyPatch = { ! ! pr ? .isCurrentlyCheckedOut }
118118 allowEmpty = { ! ! commentProps . allowEmpty }
119119 specialDisplayBodyPostfix = { ( comment as IComment ) . specialDisplayBodyPostfix }
120120 />
@@ -349,6 +349,7 @@ export function AddComment({
349349 currentUserReviewState,
350350 lastReviewType,
351351 busy,
352+ hasReviewDraft,
352353} : PullRequest ) {
353354 const { updatePR, requestChanges, approve, close, openOnGitHub, submit } = useContext ( PullRequestContext ) ;
354355 const [ isBusy , setBusy ] = useState ( false ) ;
@@ -413,8 +414,13 @@ export function AddComment({
413414 }
414415 : commentMethods ( isIssue ) ;
415416
417+ // Disable buttons when summary comment is empty AND there are no review comments
418+ // Note: Approve button is allowed even with empty content and no pending review
419+ const shouldDisableNonApproveButtons = ! pendingCommentText ?. trim ( ) && ! hasReviewDraft ;
420+ const shouldDisableApproveButton = false ; // Approve is always allowed (when not busy)
421+
416422 return (
417- < form id = "comment-form" ref = { form as React . MutableRefObject < HTMLFormElement > } className = "comment-form main-comment-form" onSubmit = { ( ) => submit ( textareaRef . current ?. value ?? '' ) } >
423+ < form id = "comment-form" ref = { form as React . MutableRefObject < HTMLFormElement > } className = "comment-form main-comment-form" >
418424 < textarea
419425 id = "comment-textarea"
420426 name = "body"
@@ -445,20 +451,20 @@ export function AddComment({
445451
446452
447453 < ContextDropdown
448- optionsContext = { ( ) => makeCommentMenuContext ( availableActions , pendingCommentText ) }
454+ optionsContext = { ( ) => makeCommentMenuContext ( availableActions , pendingCommentText , shouldDisableNonApproveButtons ) }
449455 defaultAction = { defaultSubmitAction }
450456 defaultOptionLabel = { ( ) => availableActions [ currentSelection ] ! }
451457 defaultOptionValue = { ( ) => currentSelection }
452458 allOptions = { ( ) => {
453- const actions : { label : string ; value : string ; action : ( event : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => void } [ ] = [ ] ;
459+ const actions : { label : string ; value : string ; optionDisabled : boolean ; action : ( event : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => void } [ ] = [ ] ;
454460 if ( availableActions . approve ) {
455- actions . push ( { label : availableActions [ ReviewType . Approve ] ! , value : ReviewType . Approve , action : ( ) => submitAction ( ReviewType . Approve ) } ) ;
461+ actions . push ( { label : availableActions [ ReviewType . Approve ] ! , value : ReviewType . Approve , action : ( ) => submitAction ( ReviewType . Approve ) , optionDisabled : shouldDisableApproveButton } ) ;
456462 }
457463 if ( availableActions . comment ) {
458- actions . push ( { label : availableActions [ ReviewType . Comment ] ! , value : ReviewType . Comment , action : ( ) => submitAction ( ReviewType . Comment ) } ) ;
464+ actions . push ( { label : availableActions [ ReviewType . Comment ] ! , value : ReviewType . Comment , action : ( ) => submitAction ( ReviewType . Comment ) , optionDisabled : shouldDisableNonApproveButtons } ) ;
459465 }
460466 if ( availableActions . requestChanges ) {
461- actions . push ( { label : availableActions [ ReviewType . RequestChanges ] ! , value : ReviewType . RequestChanges , action : ( ) => submitAction ( ReviewType . RequestChanges ) } ) ;
467+ actions . push ( { label : availableActions [ ReviewType . RequestChanges ] ! , value : ReviewType . RequestChanges , action : ( ) => submitAction ( ReviewType . RequestChanges ) , optionDisabled : shouldDisableNonApproveButtons } ) ;
462468 }
463469 return actions ;
464470 } }
@@ -486,7 +492,7 @@ const COMMENT_METHODS = {
486492 requestChanges : 'Request Changes' ,
487493} ;
488494
489- const makeCommentMenuContext = ( availableActions : { comment ?: string , approve ?: string , requestChanges ?: string } , pendingCommentText : string | undefined ) => {
495+ const makeCommentMenuContext = ( availableActions : { comment ?: string , approve ?: string , requestChanges ?: string } , pendingCommentText : string | undefined , shouldDisableNonApproveButtons : boolean ) => {
490496 const createMenuContexts = {
491497 'preventDefaultContextMenuItems' : true ,
492498 'github:reviewCommentMenu' : true ,
@@ -500,10 +506,16 @@ const makeCommentMenuContext = (availableActions: { comment?: string, approve?:
500506 }
501507 if ( availableActions . comment ) {
502508 createMenuContexts [ 'github:reviewCommentComment' ] = true ;
509+ if ( ! shouldDisableNonApproveButtons ) {
510+ createMenuContexts [ 'github:reviewCommentCommentEnabled' ] = true ;
511+ }
503512 }
504513 if ( availableActions . requestChanges ) {
505514 if ( availableActions . requestChanges === COMMENT_METHODS . requestChanges ) {
506515 createMenuContexts [ 'github:reviewCommentRequestChanges' ] = true ;
516+ if ( ! shouldDisableNonApproveButtons ) {
517+ createMenuContexts [ 'github:reviewRequestChangesEnabled' ] = true ;
518+ }
507519 } else {
508520 createMenuContexts [ 'github:reviewCommentRequestChangesOnDotCom' ] = true ;
509521 }
@@ -568,6 +580,11 @@ export const AddCommentSimple = (pr: PullRequest) => {
568580 }
569581 : commentMethods ( pr . isIssue ) ;
570582
583+ // Disable buttons when summary comment is empty AND there are no review comments
584+ // Note: Approve button is allowed even with empty content and no pending review
585+ const shouldDisableNonApproveButtons = ! pr . pendingCommentText ?. trim ( ) && ! pr . hasReviewDraft ;
586+ const shouldDisableApproveButton = false ; // Approve is always allowed (when not busy)
587+
571588 return (
572589 < span className = "comment-form" >
573590 < textarea
@@ -582,20 +599,20 @@ export const AddCommentSimple = (pr: PullRequest) => {
582599 />
583600 < div className = 'comment-button' >
584601 < ContextDropdown
585- optionsContext = { ( ) => makeCommentMenuContext ( availableActions , pr . pendingCommentText ) }
602+ optionsContext = { ( ) => makeCommentMenuContext ( availableActions , pr . pendingCommentText , shouldDisableNonApproveButtons ) }
586603 defaultAction = { defaultSubmitAction }
587604 defaultOptionLabel = { ( ) => availableActions [ currentSelection ] ! }
588605 defaultOptionValue = { ( ) => currentSelection }
589606 allOptions = { ( ) => {
590- const actions : { label : string ; value : string ; action : ( event : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => void } [ ] = [ ] ;
607+ const actions : { label : string ; value : string ; optionDisabled : boolean ; action : ( event : React . MouseEvent < HTMLButtonElement , MouseEvent > ) => void } [ ] = [ ] ;
591608 if ( availableActions . approve ) {
592- actions . push ( { label : availableActions [ ReviewType . Approve ] ! , value : ReviewType . Approve , action : ( ) => submitAction ( ReviewType . Approve ) } ) ;
609+ actions . push ( { label : availableActions [ ReviewType . Approve ] ! , value : ReviewType . Approve , action : ( ) => submitAction ( ReviewType . Approve ) , optionDisabled : shouldDisableApproveButton } ) ;
593610 }
594611 if ( availableActions . comment ) {
595- actions . push ( { label : availableActions [ ReviewType . Comment ] ! , value : ReviewType . Comment , action : ( ) => submitAction ( ReviewType . Comment ) } ) ;
612+ actions . push ( { label : availableActions [ ReviewType . Comment ] ! , value : ReviewType . Comment , action : ( ) => submitAction ( ReviewType . Comment ) , optionDisabled : shouldDisableNonApproveButtons } ) ;
596613 }
597614 if ( availableActions . requestChanges ) {
598- actions . push ( { label : availableActions [ ReviewType . RequestChanges ] ! , value : ReviewType . RequestChanges , action : ( ) => submitAction ( ReviewType . RequestChanges ) } ) ;
615+ actions . push ( { label : availableActions [ ReviewType . RequestChanges ] ! , value : ReviewType . RequestChanges , action : ( ) => submitAction ( ReviewType . RequestChanges ) , optionDisabled : shouldDisableNonApproveButtons } ) ;
599616 }
600617 return actions ;
601618 } }
0 commit comments