b62db917de
Client UI for agent comment suggestions. - IComment gains suggestedText / suggestionAppliedAt / suggestionAppliedById. - comment-list-item shows a "было → стало" block (old selection struck/red, new suggestedText green) for a top-level comment with a suggestion, plus an Apply button — gated by canShowApply(comment, canEdit): edit permission AND a suggestion AND not applied AND not resolved AND top-level. Once applied, an "Applied" badge replaces the button. - canEdit comes from page.permissions.canEdit (real edit permission, NOT the looser canComment) and is threaded through CommentListItem and nested ChildComments; fail-closed when undefined. - useApplySuggestionMutation posts to /comments/apply-suggestion; on success it writes the applied + server auto-resolve fields into the react-query cache (UI flips to Applied + resolved without a refetch); on 409 it shows a specific message with the server's currentText, else a generic error. - i18n keys added in en-US + ru-RU. Tests (comment-list-item.test.tsx + canShowApply unit suite): Apply visibility across canEdit/applied/resolved/reply, click dispatches the mutation, diff rendering. 34 passed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
15 lines
539 B
TypeScript
15 lines
539 B
TypeScript
import { IComment } from "@/features/comment/types/comment.types";
|
|
|
|
// Whether the suggested-edit (#315) "Apply" button should be shown for a
|
|
// comment: it must carry a suggestion, not already be applied or resolved, be a
|
|
// top-level comment, and the viewer must be able to edit the page.
|
|
export function canShowApply(comment: IComment, canEdit?: boolean): boolean {
|
|
return Boolean(
|
|
canEdit &&
|
|
comment.suggestedText &&
|
|
!comment.suggestionAppliedAt &&
|
|
!comment.resolvedAt &&
|
|
!comment.parentCommentId,
|
|
);
|
|
}
|