diff --git a/packages/ui/src/views/repo/pull-request/components/pull-request-diff-viewer.tsx b/packages/ui/src/views/repo/pull-request/components/pull-request-diff-viewer.tsx index f2753aba8..838e418f9 100644 --- a/packages/ui/src/views/repo/pull-request/components/pull-request-diff-viewer.tsx +++ b/packages/ui/src/views/repo/pull-request/components/pull-request-diff-viewer.tsx @@ -8,7 +8,7 @@ import { TranslationStore, TypesPullReqActivity } from '@/views' -import { Avatar, AvatarFallback, Layout, Text } from '@components/index' +import { Avatar, AvatarFallback, Layout } from '@components/index' import { DiffFile, DiffModeEnum, DiffView, DiffViewProps, SplitSide } from '@git-diff-view/react' import { getInitials, timeAgo } from '@utils/utils' import { DiffBlock } from 'diff2html/lib/types' @@ -49,7 +49,6 @@ interface PullRequestDiffviewerProps { useTranslationStore: () => TranslationStore commentId?: string onCopyClick?: (commentId?: number) => void - onCommentSaveAndStatusChange?: (comment: string, status: string, parentId?: number) => void suggestionsBatch?: CommitSuggestion[] onCommitSuggestion?: (suggestion: CommitSuggestion) => void addSuggestionToBatch?: (suggestion: CommitSuggestion) => void @@ -79,7 +78,6 @@ const PullRequestDiffViewer = ({ useTranslationStore, commentId, onCopyClick, - onCommentSaveAndStatusChange, suggestionsBatch, onCommitSuggestion, addSuggestionToBatch, @@ -342,7 +340,7 @@ const PullRequestDiffViewer = ({ if (!threads) return <> return ( -
+
{threads.map(thread => { const parent = thread.parent const componentId = `activity-code-${parent?.id}` @@ -356,20 +354,28 @@ const PullRequestDiffViewer = ({ parentCommentId={parent.id} handleSaveComment={handleSaveComment} isLast={true} - contentClassName="px-4 py-2 w-[calc(100%-38px)]" + contentClassName="w-[calc(100%-38px)]" header={[]} currentUser={currentUser} isComment - replyBoxClassName="py-4" + replyBoxClassName="p-4" hideReplyHere={hideReplyHeres[parent?.id]} setHideReplyHere={state => toggleReplyBox(state, parent?.id)} isResolved={!!parent.payload?.resolved} toggleConversationStatus={toggleConversationStatus} - onCommentSaveAndStatusChange={onCommentSaveAndStatusChange} onQuoteReply={handleQuoteReply} quoteReplyText={quoteReplies[parent.id]?.text || ''} + contentHeader={ + !!parent.payload?.resolved && ( +
+ {/* TODO: need to identify the author who resolved the conversation */} + {parent.author} + marked this conversation as resolved +
+ ) + } content={ -
+
- - {parentInitials} - + {parentInitials} } @@ -399,12 +403,12 @@ const PullRequestDiffViewer = ({ { name: parent.author, description: ( - - {timeAgo(parent?.created as number)} + + {timeAgo(parent?.created as number)} {parent?.deleted ? ( <> -  |  - {t('views:pullRequests.deleted')} +  |  + {t('views:pullRequests.deleted')} ) : null} @@ -474,9 +478,7 @@ const PullRequestDiffViewer = ({ icon={ - - {replyInitials} - + {replyInitials} } @@ -484,12 +486,12 @@ const PullRequestDiffViewer = ({ { name: reply.author, description: ( - - {timeAgo(reply?.created as number)} + + {timeAgo(reply?.created as number)} {reply?.deleted ? ( <> -  |  - {t('views:pullRequests.deleted')} +  |  + {t('views:pullRequests.deleted')} ) : null} @@ -505,7 +507,6 @@ const PullRequestDiffViewer = ({ { if (reply?.id) { updateComment?.(reply?.id, editComments[replyComponentId]) @@ -520,7 +521,6 @@ const PullRequestDiffViewer = ({ setComment={text => setEditComments(prev => ({ ...prev, [replyComponentId]: text })) } - onCommentSaveAndStatusChange={onCommentSaveAndStatusChange} /> ) : ( void - onCommentSaveAndStatusChange?: (comment: string, status: string, parentId?: number) => void suggestionsBatch: CommitSuggestion[] onCommitSuggestion: (suggestion: CommitSuggestion) => void addSuggestionToBatch: (suggestion: CommitSuggestion) => void @@ -82,7 +81,6 @@ const PullRequestOverview: React.FC = ({ useTranslationStore, onCopyClick, handleUpload, - onCommentSaveAndStatusChange, suggestionsBatch, onCommitSuggestion, addSuggestionToBatch, @@ -93,7 +91,6 @@ const PullRequestOverview: React.FC = ({ toCommitDetails }) => { const { t } = useTranslationStore() - const { // mode, // setMode, @@ -254,7 +251,6 @@ const PullRequestOverview: React.FC = ({ currentUser={currentUser?.display_name} replyBoxClassName="p-4" toggleConversationStatus={toggleConversationStatus} - onCommentSaveAndStatusChange={onCommentSaveAndStatusChange} isResolved={!!payload?.resolved} icon={} isLast={(data && data?.length - 1 === index) ?? false} @@ -264,13 +260,11 @@ const PullRequestOverview: React.FC = ({ { avatar: ( - {/* */} - - + {/* TODO: fix fallback string */} {getInitials((payload?.author as PayloadAuthor)?.display_name || '')} - + ), @@ -279,13 +273,9 @@ const PullRequestOverview: React.FC = ({ description: payload?.created && `reviewed ${timeAgo(payload?.created)}` } ]} + contentHeader={{(payload?.code_comment as PayloadCodeComment)?.path}} content={ -
-
- - {(payload?.code_comment as PayloadCodeComment)?.path} - -
+
{startingLine ? (
{startingLine}
@@ -334,13 +324,10 @@ const PullRequestOverview: React.FC = ({ contentClassName="border-transparent" replyBoxClassName="p-4" toggleConversationStatus={toggleConversationStatus} - onCommentSaveAndStatusChange={onCommentSaveAndStatusChange} icon={ - {/* */} - - + {/* TODO: fix fallback string */} {getInitials( ( @@ -348,7 +335,7 @@ const PullRequestOverview: React.FC = ({ ?.author as PayloadAuthor )?.display_name || '' )} - + } @@ -360,16 +347,12 @@ const PullRequestOverview: React.FC = ({ )?.display_name, // TODO: fix comment to tell between comment or code comment? description: ( - - - {timeAgo((commentItem as unknown as PayloadCreated)?.created)} - + + {timeAgo((commentItem as unknown as PayloadCreated)?.created)} {commentItem?.deleted ? ( <> -  |  - - {t('views:pullRequests.deleted')}{' '} - +  |  + {t('views:pullRequests.deleted')} ) : null} @@ -385,7 +368,6 @@ const PullRequestOverview: React.FC = ({ { if (commentItem?.id) { handleUpdateComment?.(commentItem?.id, editComments[componentId]) @@ -400,8 +382,6 @@ const PullRequestOverview: React.FC = ({ setComment={text => setEditComments(prev => ({ ...prev, [componentId]: text })) } - onCommentSaveAndStatusChange={onCommentSaveAndStatusChange} - parentCommentId={payload?.id} /> ) : ( = ({ replyBoxClassName="p-4" isResolved={!!payload?.resolved} toggleConversationStatus={toggleConversationStatus} - onCommentSaveAndStatusChange={onCommentSaveAndStatusChange} header={[ { avatar: ( - {/* */} - - + {/* TODO: fix fallback string */} {getInitials((payload?.author as PayloadAuthor)?.display_name || '')} - + ), @@ -485,7 +462,6 @@ const PullRequestOverview: React.FC = ({ onQuoteReply={handleQuoteReply} parentCommentId={payload?.id} toggleConversationStatus={toggleConversationStatus} - onCommentSaveAndStatusChange={onCommentSaveAndStatusChange} titleClassName="!flex max-w-full" currentUser={currentUser?.display_name} isLast={commentItems.length - 1 === idx} @@ -502,10 +478,8 @@ const PullRequestOverview: React.FC = ({ key={`${commentItem.id}-${commentItem.author}-pr-comment`} icon={ - {/* */} - - + {/* TODO: fix fallback string */} {getInitials( ( @@ -513,7 +487,7 @@ const PullRequestOverview: React.FC = ({ ?.author as PayloadAuthor ).display_name || '' )} - + } @@ -549,7 +523,6 @@ const PullRequestOverview: React.FC = ({ { if (commentItem?.id) { handleUpdateComment?.(commentItem?.id, editComments[componentId]) @@ -562,8 +535,6 @@ const PullRequestOverview: React.FC = ({ }} comment={editComments[componentId]} setComment={text => setEditComments(prev => ({ ...prev, [componentId]: text }))} - onCommentSaveAndStatusChange={onCommentSaveAndStatusChange} - parentCommentId={payload?.id} /> ) : ( = memo(
{avatar &&
{avatar}
} - {name && ( - - {name} - - )} - {description && ( - - {description} - - )} + {name && {name}} + {description && {description}}
{selectStatus && (
@@ -167,6 +160,7 @@ ItemHeader.displayName = 'ItemHeader' const PullRequestTimelineItem: FC = ({ header, + contentHeader, content, icon, isLast, @@ -197,11 +191,42 @@ const PullRequestTimelineItem: FC = ({ quoteReplyText }) => { const [comment, setComment] = useState('') + const [isExpanded, setIsExpanded] = useState(!isResolved) useEffect(() => { if (quoteReplyText) setComment(quoteReplyText) }, [quoteReplyText]) + useEffect(() => { + if (isResolved) { + setIsExpanded(false) + } + }, [isResolved]) + + const renderContent = () => { + if (!content) return null + + // Show full content if not resolved or expanded + if (!isResolved || isExpanded) { + return content + } + + // For resolved comments with contentHeader, hide all content when collapsed + if (contentHeader) { + return null + } + + // For resolved comments without contentHeader, show only the first comment + const contentElement = content as ReactElement + if (contentElement.props?.children?.length) { + // If content is an array of comments, take the first one + const [firstComment] = Children.toArray(contentElement.props.children) + return
{firstComment}
+ } + // If content is a single element, return as is + return content + } + return (
@@ -209,25 +234,57 @@ const PullRequestTimelineItem: FC = ({ {/* Ensure that header has at least one item */} {header.length > 0 && ( - { - setHideReplyHere?.(true) - if (parentCommentId) onQuoteReply?.(parentCommentId, data ?? '') - }} - /> +
+ { + setHideReplyHere?.(true) + if (parentCommentId) onQuoteReply?.(parentCommentId, data ?? '') + }} + /> + {isResolved && !contentHeader && ( + + )} +
)}
{content && ( - + + {contentHeader && ( +
+ {contentHeader} + {isResolved && ( + + )} +
+ )} + {isEditMode ? ( = ({ setComment={setComment} /> ) : ( - content + renderContent() )} - {!hideReplySection && ( + {!hideReplySection && (!isResolved || isExpanded) && ( <> {hideReplyHere ? ( = ({ {currentUser ? ( - - {getInitials(currentUser ?? '', 2)} - + {getInitials(currentUser ?? '', 2)} ) : null} @@ -287,7 +342,7 @@ const PullRequestTimelineItem: FC = ({ )}