Fix delete comment/thread in the new review panel (#21199)

GitOrigin-RevId: 95d4db64d2f837322d84a81cbd129ec02ee135a2
This commit is contained in:
Domagoj Kriskovic 2024-10-21 10:58:39 +02:00 committed by Copybot
parent 1e16de13bc
commit 64460681b8
3 changed files with 47 additions and 11 deletions

View file

@ -7,14 +7,18 @@ import AutoExpandingTextArea from '@/shared/components/auto-expanding-text-area'
import ReviewPanelResolvedMessage from './review-panel-resolved-message' import ReviewPanelResolvedMessage from './review-panel-resolved-message'
import { ReviewPanelResolvedCommentThread } from '../../../../../types/review-panel/comment-thread' import { ReviewPanelResolvedCommentThread } from '../../../../../types/review-panel/comment-thread'
import useSubmittableTextInput from '../hooks/use-submittable-text-input' import useSubmittableTextInput from '../hooks/use-submittable-text-input'
import { CommentId } from '../../../../../types/review-panel/review-panel' import {
CommentId,
ThreadId,
} from '../../../../../types/review-panel/review-panel'
export const ReviewPanelCommentContent = memo<{ export const ReviewPanelCommentContent = memo<{
comment: Change<CommentOperation> comment: Change<CommentOperation>
isResolved: boolean isResolved: boolean
onEdit?: (commentId: CommentId, content: string) => Promise<void> onEdit?: (commentId: CommentId, content: string) => Promise<void>
onReply?: (content: string) => Promise<void> onReply?: (content: string) => Promise<void>
onDelete?: (commentId: CommentId) => Promise<void> onDeleteMessage?: (commentId: CommentId) => Promise<void>
onDeleteThread?: (threadId: ThreadId) => Promise<void>
onResolve?: () => Promise<void> onResolve?: () => Promise<void>
onLeave?: () => void onLeave?: () => void
onEnter?: () => void onEnter?: () => void
@ -23,7 +27,8 @@ export const ReviewPanelCommentContent = memo<{
comment, comment,
isResolved, isResolved,
onResolve, onResolve,
onDelete, onDeleteMessage,
onDeleteThread,
onEdit, onEdit,
onReply, onReply,
onLeave, onLeave,
@ -65,7 +70,11 @@ export const ReviewPanelCommentContent = memo<{
hasReplies={!isReply && thread.messages.length > 1} hasReplies={!isReply && thread.messages.length > 1}
onResolve={onResolve} onResolve={onResolve}
onEdit={onEdit} onEdit={onEdit}
onDelete={onDelete} onDelete={() =>
isReply
? onDeleteMessage?.(message.id)
: onDeleteThread?.(comment.op.t)
}
isThreadResolved={isResolved} isThreadResolved={isResolved}
/> />
</div> </div>

View file

@ -8,7 +8,10 @@ import classnames from 'classnames'
import { ReviewPanelEntry } from './review-panel-entry' import { ReviewPanelEntry } from './review-panel-entry'
import MaterialIcon from '@/shared/components/material-icon' import MaterialIcon from '@/shared/components/material-icon'
import { ReviewPanelCommentContent } from './review-panel-comment-content' import { ReviewPanelCommentContent } from './review-panel-comment-content'
import { CommentId } from '../../../../../types/review-panel/review-panel' import {
CommentId,
ThreadId,
} from '../../../../../types/review-panel/review-panel'
import { useModalsContext } from '@/features/ide-react/context/modals-context' import { useModalsContext } from '@/features/ide-react/context/modals-context'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { debugConsole } from '@/utils/debugging' import { debugConsole } from '@/utils/debugging'
@ -23,8 +26,13 @@ export const ReviewPanelComment = memo<{
hovered?: boolean hovered?: boolean
}>(({ comment, top, hovered, onEnter, onLeave, docId, hoverRanges }) => { }>(({ comment, top, hovered, onEnter, onLeave, docId, hoverRanges }) => {
const threads = useThreadsContext() const threads = useThreadsContext()
const { resolveThread, editMessage, deleteMessage, addMessage } = const {
useThreadsActionsContext() resolveThread,
editMessage,
deleteMessage,
deleteThread,
addMessage,
} = useThreadsActionsContext()
const { showGenericMessageModal } = useModalsContext() const { showGenericMessageModal } = useModalsContext()
const { t } = useTranslation() const { t } = useTranslation()
@ -81,6 +89,24 @@ export const ReviewPanelComment = memo<{
[comment.op.t, deleteMessage, showGenericMessageModal, t] [comment.op.t, deleteMessage, showGenericMessageModal, t]
) )
const handleDeleteThread = useCallback(
async (commentId: ThreadId) => {
setProcessing(true)
try {
await deleteThread(commentId)
} catch (err) {
debugConsole.error(err)
showGenericMessageModal(
t('delete_comment_error_title'),
t('delete_comment_error_message')
)
} finally {
setProcessing(false)
}
},
[deleteThread, showGenericMessageModal, t]
)
const handleSubmitReply = useCallback( const handleSubmitReply = useCallback(
async (content: string) => { async (content: string) => {
setProcessing(true) setProcessing(true)
@ -132,7 +158,8 @@ export const ReviewPanelComment = memo<{
onEnter={onEnter} onEnter={onEnter}
onResolve={handleResolveComment} onResolve={handleResolveComment}
onEdit={handleEditMessage} onEdit={handleEditMessage}
onDelete={handleDeleteMessage} onDeleteMessage={handleDeleteMessage}
onDeleteThread={handleDeleteThread}
onReply={handleSubmitReply} onReply={handleSubmitReply}
/> />
</ReviewPanelEntry> </ReviewPanelEntry>

View file

@ -20,7 +20,7 @@ export const ReviewPanelMessage: FC<{
isReply: boolean isReply: boolean
onResolve?: () => Promise<void> onResolve?: () => Promise<void>
onEdit?: (commentId: CommentId, content: string) => Promise<void> onEdit?: (commentId: CommentId, content: string) => Promise<void>
onDelete?: (CommentId: CommentId) => Promise<void> onDelete?: () => void
isThreadResolved: boolean isThreadResolved: boolean
}> = ({ }> = ({
message, message,
@ -47,9 +47,9 @@ export const ReviewPanelMessage: FC<{
}, [content, message.id, onEdit]) }, [content, message.id, onEdit])
const handleDelete = useCallback(() => { const handleDelete = useCallback(() => {
onDelete?.(message.id) onDelete?.()
setDeleting(false) setDeleting(false)
}, [message.id, onDelete]) }, [onDelete])
if (editing) { if (editing) {
return ( return (