Skip to content

Commit

Permalink
fix: mr review comments line index display optimization (#3982)
Browse files Browse the repository at this point in the history
  • Loading branch information
hujiahao-hjh authored Dec 28, 2023
1 parent cfd0eb9 commit d92fdd7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
42 changes: 33 additions & 9 deletions shell/app/modules/application/pages/repo/components/file-diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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))}
</div>
</IF>

Expand Down Expand Up @@ -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,
),
)}
</div>
</IF>
<CommentEditBox
Expand Down Expand Up @@ -795,8 +800,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,
),
)}
</div>
</IF>

Expand Down Expand Up @@ -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;
4 changes: 2 additions & 2 deletions shell/app/modules/application/types/repo.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ declare namespace REPOSITORY {
oldCommitId: string;
newCommitId: string;
aiSessionID?: string;
newLineTo: string;
oldLineTo: string;
newLineTo: number;
oldLineTo: number;
};
authorId: string;
author: {
Expand Down

0 comments on commit d92fdd7

Please sign in to comment.