From 76c7c3e28ef51f403b3adc625a3a55a6b8b04c46 Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Mon, 11 Nov 2024 12:28:59 +0000 Subject: [PATCH] Fix dirtyState handling in ranges context (#21724) GitOrigin-RevId: 44f3aa9efc6dbd0d34a2b0440054197398a62caf --- .../context/ranges-context.tsx | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/services/web/frontend/js/features/review-panel-new/context/ranges-context.tsx b/services/web/frontend/js/features/review-panel-new/context/ranges-context.tsx index 44ccc8f1c3..bcb94d34b4 100644 --- a/services/web/frontend/js/features/review-panel-new/context/ranges-context.tsx +++ b/services/web/frontend/js/features/review-panel-new/context/ranges-context.tsx @@ -43,13 +43,32 @@ const buildRanges = (currentDoc: DocumentContainer | null) => { const dirtyState = ranges.getDirtyState() ranges.resetDirtyState() + const changed = { + changes: new Set([ + ...Object.keys(dirtyState.change.added), + ...Object.keys(dirtyState.change.moved), + ...Object.keys(dirtyState.change.removed), + ]), + comments: new Set([ + ...Object.keys(dirtyState.comment.added), + ...Object.keys(dirtyState.comment.moved), + ...Object.keys(dirtyState.comment.removed), + ]), + } + return { - changes: ranges.changes.map(change => - change.id in dirtyState.change ? { ...change } : change - ), - comments: ranges.comments.map(comment => - comment.id in dirtyState.comment ? { ...comment } : comment - ), + changes: + changed.changes.size > 0 + ? ranges.changes.map(change => + changed.changes.has(change.id) ? { ...change } : change + ) + : ranges.changes, + comments: + changed.comments.size > 0 + ? ranges.comments.map(comment => + changed.comments.has(comment.id) ? { ...comment } : comment + ) + : ranges.comments, docId: currentDoc.doc_id, total: ranges.changes.length + ranges.comments.length, }