From d92fdd72613f0684a1ac1b973e53d1a6a906bc69 Mon Sep 17 00:00:00 2001 From: hujiahao-hjh <82502479+hujiahao-hjh@users.noreply.github.com> Date: Thu, 28 Dec 2023 19:01:34 +0800 Subject: [PATCH] fix: mr review comments line index display optimization (#3982) --- .../pages/repo/components/file-diff.tsx | 42 +++++++++++++++---- shell/app/modules/application/types/repo.d.ts | 4 +- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/shell/app/modules/application/pages/repo/components/file-diff.tsx b/shell/app/modules/application/pages/repo/components/file-diff.tsx index 359f2d579..3bd227178 100644 --- a/shell/app/modules/application/pages/repo/components/file-diff.tsx +++ b/shell/app/modules/application/pages/repo/components/file-diff.tsx @@ -99,11 +99,8 @@ const CommentListBox = ({ comments }: { comments: REPOSITORY.IComment[] }) => { {i18n.t('comment')} {i18n.t('line')}{' '} {`${newLineTo}` === '0' && `${oldLineTo}` === '0' - ? `${oldLine}_${newLine}` - : i18n.t('from {start} to {end}', { - start: `${oldLine}_${newLine}`, - end: `${oldLineTo}_${newLineTo}`, - })} + ? getSingleLineIndex(oldLine, newLine) + : i18n.t('from {start} to {end}', getTwoLineIndex(oldLine, newLine, oldLineTo, newLineTo))} @@ -676,8 +673,16 @@ export const FileDiff = ({ {i18n.t('comment')} {i18n.t('line')}{' '} {endRowIndex === 0 - ? startLineKey - : i18n.t('from {start} to {end}', { start: startLineKey, end: endLineKey })} + ? getSingleLineIndex(startLine?.oldLineNo, startLine?.newLineNo) + : i18n.t( + 'from {start} to {end}', + getTwoLineIndex( + startLine?.oldLineNo, + startLine?.newLineNo, + endLine?.oldLineNo, + endLine?.newLineNo, + ), + )} @@ -1168,4 +1181,15 @@ const CommentEditBox = ({ markdownValue, onPostComment, onCancel, onStartAI }: C ); }; +const getSingleLineIndex = (oldLine: number, newLine: number) => { + return oldLine !== -1 ? `-${oldLine}` : `+${newLine}`; +}; + +const getTwoLineIndex = (oldLine: number, newLine: number, oldLineTo: number, newLineTo: number) => { + return { + start: oldLine !== -1 ? `-${oldLine}` : `+${newLine}`, + end: oldLineTo !== -1 ? `-${oldLineTo}` : `+${newLineTo}`, + }; +}; + export default FilesDiff; diff --git a/shell/app/modules/application/types/repo.d.ts b/shell/app/modules/application/types/repo.d.ts index 74652fc21..183d94a05 100644 --- a/shell/app/modules/application/types/repo.d.ts +++ b/shell/app/modules/application/types/repo.d.ts @@ -80,8 +80,8 @@ declare namespace REPOSITORY { oldCommitId: string; newCommitId: string; aiSessionID?: string; - newLineTo: string; - oldLineTo: string; + newLineTo: number; + oldLineTo: number; }; authorId: string; author: {