From 9ee4846923c41b09532e0f4481023e473849c8db Mon Sep 17 00:00:00 2001 From: Shaurya Kalia <113332561+shaurya-harness@users.noreply.github.com> Date: Fri, 28 Feb 2025 11:34:39 +0530 Subject: [PATCH] fix: [PIPE-25374,PIPE-25382]: PR diff comments in MFE and PR panel icon (#1168) * fix: [PIPE-25374]: ellipsis icon for PR panel * fix: [PIPE-25382]: PR diff comments proxy objects * fix: [PIPE-25382]: PR diff comments proxy objects --- .../components/pull-request-diff-viewer.tsx | 13 +++++++++++-- .../components/common/pull-request-comment-view.tsx | 13 +++++-------- .../components/conversation/pull-request-panel.tsx | 2 +- .../details/pull-request-details-types.ts | 4 ++++ 4 files changed, 21 insertions(+), 11 deletions(-) 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 1086f5132..78484c294 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 @@ -2,6 +2,7 @@ import { useCallback, useEffect, useRef, useState } from 'react' import { Avatar, Layout } from '@/components' import { + activitiesToDiffCommentItems, CommentItem, CommitSuggestion, CreateCommentPullReqRequest, @@ -215,7 +216,11 @@ const PullRequestDiffViewer = ({ updated: parentComment.updated, deleted: parentComment.deleted, outdated: parentComment.outdated, - payload: parentComment.payload + payload: parentComment.payload, + codeBlockContent: activitiesToDiffCommentItems(parentComment).codeBlockContent, + appliedCheckSum: parentComment.payload?.metadata?.suggestions?.applied_check_sum, + appliedCommitSha: parentComment.payload?.metadata?.suggestions?.applied_commit_sha, + checkSums: parentComment.payload?.metadata?.suggestions?.check_sums } const replies = threadArr.slice(1).map(reply => ({ @@ -227,7 +232,11 @@ const PullRequestDiffViewer = ({ edited: reply.edited, updated: reply.updated, deleted: reply.deleted, - outdated: reply.outdated + outdated: reply.outdated, + codeBlockContent: activitiesToDiffCommentItems(reply).codeBlockContent, + appliedCheckSum: reply.payload?.metadata?.suggestions?.applied_check_sum, + appliedCommitSha: reply.payload?.metadata?.suggestions?.applied_commit_sha, + checkSums: reply.payload?.metadata?.suggestions?.check_sums })) if (!newExtend[side][lineNumber]) { diff --git a/packages/ui/src/views/repo/pull-request/details/components/common/pull-request-comment-view.tsx b/packages/ui/src/views/repo/pull-request/details/components/common/pull-request-comment-view.tsx index eab4e2600..729af0e03 100644 --- a/packages/ui/src/views/repo/pull-request/details/components/common/pull-request-comment-view.tsx +++ b/packages/ui/src/views/repo/pull-request/details/components/common/pull-request-comment-view.tsx @@ -4,10 +4,8 @@ import { FC } from 'react' import { Button, MarkdownViewer } from '@/components' import { CommitSuggestion } from '@views/repo/pull-request/pull-request.types' -import { get } from 'lodash-es' import { CommentItem, TypesPullReqActivity } from '../../pull-request-details-types' -import { activitiesToDiffCommentItems } from '../../pull-request-utils' export interface PRCommentViewProps { commentItem: CommentItem @@ -29,12 +27,11 @@ const PRCommentView: FC = ({ const pathSegments = commentItem?.payload?.code_comment?.path?.split('/') || [] const fileLang = filenameToLanguage?.(pathSegments.pop() || '') || '' - const appliedCheckSum = get(commentItem, 'payload.metadata.suggestions.applied_check_sum', '') - const checkSums = get(commentItem, 'payload.metadata.suggestions.check_sums', []) as string[] - const isSuggestion = !!checkSums.length + const appliedCheckSum = commentItem.appliedCheckSum ?? '' + const checkSums = commentItem.checkSums ?? [] + const isSuggestion = !!checkSums?.length const isApplied = appliedCheckSum === checkSums?.[0] const isInBatch = suggestionsBatch?.some(suggestion => suggestion.comment_id === commentItem.id) - const diffCommentItem = activitiesToDiffCommentItems(commentItem) return ( <> @@ -42,11 +39,11 @@ const PRCommentView: FC = ({ markdownClassName="comment" source={commentItem?.payload?.text || ''} suggestionBlock={{ - source: diffCommentItem.codeBlockContent || '', + source: commentItem.codeBlockContent || '', lang: fileLang, commentId: commentItem.id, appliedCheckSum: appliedCheckSum, - appliedCommitSha: get(commentItem, 'payload.metadata.suggestions.applied_commit_sha', '') + appliedCommitSha: commentItem.appliedCommitSha || '' }} suggestionCheckSum={checkSums?.[0] || ''} isSuggestion={isSuggestion} diff --git a/packages/ui/src/views/repo/pull-request/details/components/conversation/pull-request-panel.tsx b/packages/ui/src/views/repo/pull-request/details/components/conversation/pull-request-panel.tsx index b0ce1a009..928709780 100644 --- a/packages/ui/src/views/repo/pull-request/details/components/conversation/pull-request-panel.tsx +++ b/packages/ui/src/views/repo/pull-request/details/components/conversation/pull-request-panel.tsx @@ -256,7 +256,7 @@ const PullRequestPanel = ({ diff --git a/packages/ui/src/views/repo/pull-request/details/pull-request-details-types.ts b/packages/ui/src/views/repo/pull-request/details/pull-request-details-types.ts index 165492956..552e0237a 100644 --- a/packages/ui/src/views/repo/pull-request/details/pull-request-details-types.ts +++ b/packages/ui/src/views/repo/pull-request/details/pull-request-details-types.ts @@ -339,6 +339,10 @@ export interface CommentItem { outdated: boolean content: string payload?: T // optional payload for callers to handle on callback calls + appliedCheckSum?: string + checkSums?: string[] + codeBlockContent?: string + appliedCommitSha?: string } export interface DiffFileEntry extends DiffFile {