Fix: comments thread does not necessarily belong to current document

This commit is contained in:
yu-i-i
2025-09-22 15:05:34 +02:00
parent b6f30c9f88
commit c227643bb2
4 changed files with 22 additions and 19 deletions

View File

@@ -44,7 +44,7 @@ export const ReviewPanelComment = memo<{
const handleResolveComment = useCallback(async () => {
setProcessing(true)
try {
await resolveThread(comment.op.t)
await resolveThread(comment.op.t, docId)
} catch (err) {
debugConsole.error(err)
showGenericMessageModal(
@@ -54,7 +54,7 @@ export const ReviewPanelComment = memo<{
} finally {
setProcessing(false)
}
}, [comment.op.t, resolveThread, showGenericMessageModal, t])
}, [comment.op.t, docId, resolveThread, showGenericMessageModal, t])
const handleEditMessage = useCallback(
async (commentId: CommentId, content: string) => {
@@ -110,7 +110,7 @@ export const ReviewPanelComment = memo<{
async (commentId: ThreadId) => {
setProcessing(true)
try {
await deleteThread(commentId)
await deleteThread(commentId, docId)
} catch (err) {
debugConsole.error(err)
showGenericMessageModal(
@@ -121,7 +121,7 @@ export const ReviewPanelComment = memo<{
setProcessing(false)
}
},
[deleteThread, showGenericMessageModal, t]
[deleteThread, docId, showGenericMessageModal, t]
)
const handleSubmitReply = useCallback(

View File

@@ -17,7 +17,8 @@ export const ReviewPanelResolvedThread: FC<{
id: ThreadId
comment: Change<CommentOperation>
docName: string
}> = ({ id, comment, docName }) => {
docId: string
}> = ({ id, comment, docName, docId }) => {
const { t } = useTranslation()
const { reopenThread, deleteThread } = useThreadsActionsContext()
const [processing, setProcessing] = useState(false)
@@ -33,7 +34,7 @@ export const ReviewPanelResolvedThread: FC<{
const handleReopenThread = useCallback(async () => {
setProcessing(true)
try {
await reopenThread(id)
await reopenThread(id, docId)
} catch (err) {
debugConsole.error(err)
showGenericMessageModal(
@@ -43,12 +44,12 @@ export const ReviewPanelResolvedThread: FC<{
} finally {
setProcessing(false)
}
}, [id, reopenThread, showGenericMessageModal, t])
}, [id, docId, reopenThread, showGenericMessageModal, t])
const handleDeleteThread = useCallback(async () => {
setProcessing(true)
try {
await deleteThread(id)
await deleteThread(id, docId)
} catch (err) {
debugConsole.error(err)
showGenericMessageModal(
@@ -58,7 +59,7 @@ export const ReviewPanelResolvedThread: FC<{
} finally {
setProcessing(false)
}
}, [id, deleteThread, showGenericMessageModal, t])
}, [id, docId, deleteThread, showGenericMessageModal, t])
return (
<div

View File

@@ -18,7 +18,7 @@ export const ReviewPanelResolvedThreadsMenu: FC = () => {
const { projectRanges, loading } = useProjectRanges()
const docNameForThread = useMemo(() => {
const docNameForThread = new Map<string, string>()
const docNameForThread = new Map<string, { docId: string; docName: string }>()
const otMigrationStage = getMeta('ol-otMigrationStage')
for (const [docId, ranges] of projectRanges?.entries() ?? []) {
@@ -28,7 +28,7 @@ export const ReviewPanelResolvedThreadsMenu: FC = () => {
if (docName !== undefined) {
for (const comment of ranges.comments) {
const threadId = comment.op.t
docNameForThread.set(threadId, docName)
docNameForThread.set(threadId, { docId, docName })
}
}
}
@@ -112,7 +112,8 @@ export const ReviewPanelResolvedThreadsMenu: FC = () => {
key={thread.id}
id={thread.id as ThreadId}
comment={comment}
docName={docNameForThread.get(thread.id) ?? t('unknown')}
docName={docNameForThread.get(thread.id)?.docName ?? t('unknown')}
docId={docNameForThread.get(thread.id)?.docId}
/>
)
})}

View File

@@ -289,23 +289,24 @@ export const ThreadsProvider: FC<React.PropsWithChildren> = ({ children }) => {
currentDocument.submitOp(op)
},
async resolveThread(threadId: string) {
async resolveThread(threadId: string, docId: string) {
await postJSON(
`/project/${projectId}/doc/${currentDocument.doc_id}/thread/${threadId}/resolve`
`/project/${projectId}/doc/${docId}/thread/${threadId}/resolve`
)
sendEvent('rp-comment-resolve', { view: reviewPanelView })
},
async reopenThread(threadId: string) {
async reopenThread(threadId: string, docId: string) {
await postJSON(
`/project/${projectId}/doc/${currentDocument.doc_id}/thread/${threadId}/reopen`
`/project/${projectId}/doc/${docId}/thread/${threadId}/reopen`
)
sendEvent('rp-comment-reopen')
},
async deleteThread(threadId: string) {
async deleteThread(threadId: string, docId: string) {
await deleteJSON(
`/project/${projectId}/doc/${currentDocument.doc_id}/thread/${threadId}`
`/project/${projectId}/doc/${docId}/thread/${threadId}`
)
currentDocument.ranges?.removeCommentId(threadId)
// Is looks like it's not necessary
// currentDocument.ranges?.removeCommentId(threadId)
sendEvent('rp-comment-delete')
},
async addMessage(threadId: ThreadId, content: string) {