Sort track changes and comments in overview mode (#21099)

GitOrigin-RevId: 795d30b56e57970363512170f504ab51bd104c93
This commit is contained in:
Domagoj Kriskovic 2024-10-21 10:57:59 +02:00 committed by Copybot
parent 332e2a38c9
commit c606f04cce

View file

@ -3,9 +3,14 @@ import { MainDocument } from '../../../../../types/project-settings'
import { Ranges } from '../context/ranges-context' import { Ranges } from '../context/ranges-context'
import { ReviewPanelComment } from './review-panel-comment' import { ReviewPanelComment } from './review-panel-comment'
import { ReviewPanelChange } from './review-panel-change' import { ReviewPanelChange } from './review-panel-change'
import { isDeleteChange, isInsertChange } from '@/utils/operations' import {
isCommentOperation,
isDeleteChange,
isInsertChange,
} from '@/utils/operations'
import { import {
Change, Change,
CommentOperation,
DeleteOperation, DeleteOperation,
EditOperation, EditOperation,
} from '../../../../../types/change' } from '../../../../../types/change'
@ -44,16 +49,15 @@ export const ReviewPanelOverviewFile: FC<{
return { aggregates, changes } return { aggregates, changes }
}, [ranges]) }, [ranges])
const unresolvedComments = useMemo(() => { const entries = useMemo(() => {
return ranges.comments.filter(comment => { const unresolvedComments = ranges.comments.filter(comment => {
const thread = threads?.[comment.op.t] const thread = threads?.[comment.op.t]
return thread && thread.messages.length > 0 && !thread.resolved return thread && thread.messages.length > 0 && !thread.resolved
}) })
}, [ranges.comments, threads]) return [...changes, ...unresolvedComments].sort((a, b) => a.op.p - b.op.p)
}, [changes, ranges.comments, threads])
const numEntries = changes.length + unresolvedComments.length if (entries.length === 0) {
if (numEntries === 0) {
return null return null
} }
@ -70,31 +74,31 @@ export const ReviewPanelOverviewFile: FC<{
/> />
{doc.doc.name} {doc.doc.name}
<div className="review-panel-overview-file-entry-count"> <div className="review-panel-overview-file-entry-count">
{numEntries} {entries.length}
</div> </div>
</button> </button>
{!collapsed && ( {!collapsed && (
<div className="review-panel-overview-file-entries"> <div className="review-panel-overview-file-entries">
{changes.map(change => ( {entries.map(entry =>
isCommentOperation(entry.op) ? (
<ReviewPanelComment
key={entry.id}
comment={entry as Change<CommentOperation>}
docId={doc.doc.id}
hoverRanges={false}
/>
) : (
<ReviewPanelChange <ReviewPanelChange
key={change.id} key={entry.id}
change={change} change={entry as Change<EditOperation>}
aggregate={aggregates.get(change.id)} aggregate={aggregates.get(entry.id)}
editable={false} editable={false}
docId={doc.doc.id} docId={doc.doc.id}
hoverRanges={false} hoverRanges={false}
/> />
))} )
)}
{unresolvedComments.map(comment => (
<ReviewPanelComment
key={comment.id}
comment={comment}
docId={doc.doc.id}
hoverRanges={false}
/>
))}
</div> </div>
)} )}
</div> </div>