Просмотр исходного кода

Merge pull request #17667 from overleaf/em-history-comment-ids

Handle the commentIds property in project-history

GitOrigin-RevId: 39502a88f97e531b436a1b2d4f791c73e31bb401
Eric Mc Sween 2 лет назад
Родитель
Сommit
7a6b03cf7c

+ 12 - 8
services/project-history/app/js/UpdateTranslator.js

@@ -297,16 +297,19 @@ class OperationsBuilder {
             ts: new Date(update.meta.ts).toISOString(),
           },
         })
-      } else if (update.meta.tc != null) {
-        this.insert(op.i, {
-          tracking: {
+      } else {
+        const opts = {}
+        if (update.meta.tc != null) {
+          opts.tracking = {
             type: 'insert',
             userId: update.meta.user_id,
             ts: new Date(update.meta.ts).toISOString(),
-          },
-        })
-      } else {
-        this.insert(op.i)
+          }
+        }
+        if (op.commentIds != null) {
+          opts.commentIds = op.commentIds
+        }
+        this.insert(op.i, opts)
       }
     }
 
@@ -395,9 +398,10 @@ class OperationsBuilder {
    * @param {string} str
    * @param {object} opts
    * @param {TrackingProps} [opts.tracking]
+   * @param {string[]} [opts.commentIds]
    */
   insert(str, opts = {}) {
-    if (opts.tracking) {
+    if (opts.tracking || opts.commentIds) {
       this.textOperation.push({ i: str, ...opts })
     } else {
       this.textOperation.push(str)

+ 7 - 1
services/project-history/app/js/types.ts

@@ -1,4 +1,9 @@
-export type Update = TextUpdate | AddDocUpdate | AddFileUpdate | RenameUpdate | DeleteCommentUpdate
+export type Update =
+  | TextUpdate
+  | AddDocUpdate
+  | AddFileUpdate
+  | RenameUpdate
+  | DeleteCommentUpdate
 
 export type UpdateMeta = {
   user_id: string
@@ -57,6 +62,7 @@ export type InsertOp = {
   u?: boolean
   hpos?: number
   trackedDeleteRejection?: boolean
+  commentIds?: string[]
 }
 
 export type DeleteOp = {

+ 8 - 2
services/project-history/test/unit/js/UpdateTranslator/UpdateTranslatorTests.js

@@ -476,7 +476,7 @@ describe('UpdateTranslator', function () {
               doc: this.doc_id,
               op: [
                 { p: 3, i: 'foo' },
-                { p: 15, i: 'bar' },
+                { p: 15, i: 'bar', commentIds: ['comment1'] },
               ],
               v: this.version,
               meta: {
@@ -501,7 +501,13 @@ describe('UpdateTranslator', function () {
             operations: [
               {
                 pathname: 'main.tex',
-                textOperation: [3, 'foo', 9, 'bar', 8],
+                textOperation: [
+                  3,
+                  'foo',
+                  9,
+                  { i: 'bar', commentIds: ['comment1'] },
+                  8,
+                ],
               },
             ],
             v2Authors: [this.user_id],