Remove patchset level comments from patchset dropdown count

The patchset dropdown selector shows the count of comments of that
particular patchset but given that we have no file entry for patchset
level comments(both human and robot), we should not have them
contribute to the count.

The comment summary chip which directs to the comments tab is the
primary source for tracking patchset level comments.

Change-Id: Ib4fc43e0c3797834b72a765ae2afce6f70871e9d
diff --git a/polygerrit-ui/app/elements/diff/gr-comment-api/gr-comment-api.ts b/polygerrit-ui/app/elements/diff/gr-comment-api/gr-comment-api.ts
index b382495..8cc7a3f 100644
--- a/polygerrit-ui/app/elements/diff/gr-comment-api/gr-comment-api.ts
+++ b/polygerrit-ui/app/elements/diff/gr-comment-api/gr-comment-api.ts
@@ -45,6 +45,7 @@
   isDraftThread,
   isInBaseOfPatchRange,
   isInRevisionOfPatchRange,
+  isPatchsetLevel,
 } from '../../../utils/comment-util';
 import {PatchSetFile, PatchNumOnly, isPatchSetFile} from '../../../types/types';
 import {appContext} from '../../../services/app-context';
@@ -484,7 +485,10 @@
   /**
    * Computes the number of comment threads in a given file or patch.
    */
-  computeCommentThreadCount(file: PatchSetFile | PatchNumOnly) {
+  computeCommentThreadCount(
+    file: PatchSetFile | PatchNumOnly,
+    ignorePatchsetLevelComments?: boolean
+  ) {
     let comments: Comment[] = [];
     if (isPatchSetFile(file)) {
       comments = this.getAllCommentsForFile(file);
@@ -493,8 +497,10 @@
         this.getAllPublishedComments(file.patchNum)
       );
     }
-
-    return createCommentThreads(comments).length;
+    let threads = createCommentThreads(comments);
+    if (ignorePatchsetLevelComments)
+      threads = threads.filter(thread => !isPatchsetLevel(thread));
+    return threads.length;
   }
 
   /**
diff --git a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.ts b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.ts
index 4b53269..3544834 100644
--- a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.ts
+++ b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select.ts
@@ -372,9 +372,12 @@
       return;
     }
 
-    const commentThreadCount = changeComments.computeCommentThreadCount({
-      patchNum,
-    });
+    const commentThreadCount = changeComments.computeCommentThreadCount(
+      {
+        patchNum,
+      },
+      true
+    );
     const commentThreadString = pluralize(commentThreadCount, 'comment');
 
     const unresolvedCount = changeComments.computeUnresolvedNum({patchNum});
diff --git a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.js b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.js
index 956f087..9af7e05 100644
--- a/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.js
+++ b/polygerrit-ui/app/elements/diff/gr-patch-range-select/gr-patch-range-select_test.js
@@ -27,6 +27,7 @@
 import {ChangeComments} from '../gr-comment-api/gr-comment-api.js';
 import {stubRestApi} from '../../../test/test-utils.js';
 import {EditPatchSetNum} from '../../../types/common.js';
+import {SpecialFilePath} from '../../../constants/constants.js';
 
 const commentApiMockElement = createCommentApiMockWithTemplateElement(
     'gr-patch-range-select-comment-api-mock', html`
@@ -363,19 +364,29 @@
         unresolved: true,
         updated: '2017-10-11 20:48:40.000000000',
       }],
-      bar: [{
-        id: '27dcee4d_f7b77cfa',
-        message: 'test',
-        patch_set: 1,
-        updated: '2017-10-12 20:48:40.000000000',
-      },
-      {
-        id: '27dcee4d_f7b77cfa',
-        message: 'test',
-        patch_set: 1,
-        updated: '2017-10-13 20:48:40.000000000',
-      }],
+      bar: [
+        {
+          id: '27dcee4d_f7b77cfa',
+          message: 'test',
+          patch_set: 1,
+          updated: '2017-10-12 20:48:40.000000000',
+        },
+        {
+          id: '27dcee4d_f7b77cfa',
+          message: 'test',
+          patch_set: 1,
+          updated: '2017-10-13 20:48:40.000000000',
+        },
+      ],
       abc: [],
+      // Patchset level comment does not contribute to the count
+      [SpecialFilePath.PATCHSET_LEVEL_COMMENTS]: {
+        id: '27dcee4d_f7b77cfa',
+        message: 'test',
+        patch_set: 1,
+        unresolved: true,
+        updated: '2017-10-11 20:48:40.000000000',
+      },
     };
     element.changeComments = new ChangeComments(comments, {}, {}, 123);
 
diff --git a/polygerrit-ui/app/utils/comment-util.ts b/polygerrit-ui/app/utils/comment-util.ts
index 048206b..2d5f66e 100644
--- a/polygerrit-ui/app/utils/comment-util.ts
+++ b/polygerrit-ui/app/utils/comment-util.ts
@@ -28,7 +28,7 @@
   BasePatchSetNum,
   RevisionPatchSetNum,
 } from '../types/common';
-import {CommentSide, Side} from '../constants/constants';
+import {CommentSide, Side, SpecialFilePath} from '../constants/constants';
 import {parseDate} from './date-util';
 import {LineNumber} from '../elements/diff/gr-diff/gr-diff-line';
 import {CommentIdToCommentThreadMap} from '../elements/diff/gr-comment-api/gr-comment-api';
@@ -185,6 +185,10 @@
   return thread?.comments?.length ?? 0;
 }
 
+export function isPatchsetLevel(thread?: CommentThread): boolean {
+  return thread?.path === SpecialFilePath.PATCHSET_LEVEL_COMMENTS;
+}
+
 export function isUnresolved(thread?: CommentThread): boolean {
   return !isResolved(thread);
 }