Fix comments disappearing in the "Comments" tab when clicking "Reply"
The "Comments" tab was changed to only show "saved" threads, which
works fine for newly created threads. But threads with unsaved replies
would also be considered "unsaved threads". That resulted in comments
disappearing when clicking "Reply".
Release-Notes: skip
Change-Id: Ibb9cf31e816276b506735eab5fea619e6d2ce589
diff --git a/polygerrit-ui/app/utils/comment-util.ts b/polygerrit-ui/app/utils/comment-util.ts
index 3800802..4646bf6 100644
--- a/polygerrit-ui/app/utils/comment-util.ts
+++ b/polygerrit-ui/app/utils/comment-util.ts
@@ -238,8 +238,12 @@
return isDraft(getLastComment(thread));
}
+/**
+ * Returns true, if the thread consists only of one comment that has not yet
+ * been saved to the backend.
+ */
export function isNewThread(thread: CommentThread): boolean {
- return isNew(getLastComment(thread));
+ return isNew(getFirstComment(thread));
}
export function isMentionedThread(
diff --git a/polygerrit-ui/app/utils/comment-util_test.ts b/polygerrit-ui/app/utils/comment-util_test.ts
index ab21c67..7bf0c1e 100644
--- a/polygerrit-ui/app/utils/comment-util_test.ts
+++ b/polygerrit-ui/app/utils/comment-util_test.ts
@@ -16,6 +16,8 @@
createUserFixSuggestion,
PROVIDED_FIX_ID,
getMentionedThreads,
+ isNewThread,
+ createNew,
} from './comment-util';
import {
createAccountWithEmail,
@@ -72,6 +74,17 @@
);
});
+ test('isNewThread', () => {
+ let thread = createCommentThread([createComment()]);
+ assert.isFalse(isNewThread(thread));
+
+ thread = createCommentThread([createComment(), createNew()]);
+ assert.isFalse(isNewThread(thread));
+
+ thread = createCommentThread([createNew()]);
+ assert.isTrue(isNewThread(thread));
+ });
+
suite('getPatchRangeForCommentUrl', () => {
test('comment created with side=PARENT does not navigate to latest ps', () => {
const comment = {