From 00f243250cf46d03d1a127197a3aebca9d8f4294 Mon Sep 17 00:00:00 2001 From: Karishma Chadha Date: Wed, 12 Jan 2022 13:44:21 -0500 Subject: [PATCH] Forward fix for regression introduced by changing the number of replies we fetch. This change updates the number of comment replies we fetch on project comments from 20 to 25 to be consistent with studio page. Also updates the code that controls whether to display the 'See more replies' button on comment threads. --- src/redux/comments.js | 10 ++++++++-- src/redux/project-comment-actions.js | 3 ++- test/unit-legacy/redux/comments-test.js | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/redux/comments.js b/src/redux/comments.js index e51291858..7ef1940a3 100644 --- a/src/redux/comments.js +++ b/src/redux/comments.js @@ -2,7 +2,13 @@ const keyMirror = require('keymirror'); const mergeWith = require('lodash.mergewith'); const uniqBy = require('lodash.uniqby'); -const COMMENT_LIMIT = 20; +// Number of replies to fetch at a time. +// The way this code is currently structured, it expects +// this number to be the same for project comment reply threads +// as well as studio comment reply threads. +// These could be decoupled in the future. +const REPLY_FETCH_LIMIT = 25; + module.exports.Status = keyMirror({ FETCHED: null, @@ -108,7 +114,7 @@ module.exports.commentsReducer = (state, action) => { comments: state.comments.map(comment => { if (action.replies[comment.id]) { return Object.assign({}, comment, { - moreRepliesToLoad: action.replies[comment.id].length === COMMENT_LIMIT + moreRepliesToLoad: action.replies[comment.id].length === REPLY_FETCH_LIMIT }); } return comment; diff --git a/src/redux/project-comment-actions.js b/src/redux/project-comment-actions.js index 2b47cc452..180fc475a 100644 --- a/src/redux/project-comment-actions.js +++ b/src/redux/project-comment-actions.js @@ -4,6 +4,7 @@ const api = require('../lib/api'); const log = require('../lib/log'); const COMMENT_LIMIT = 20; +const REPLY_LIMIT = 25; // Number of replies to fetch at a time const { addNewComment, @@ -28,7 +29,7 @@ const getReplies = (projectId, commentIds, offset, ownerUsername, isAdmin, token api({ uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${projectId}/comments/${parentId}/replies`, authentication: token ? token : null, - params: {offset: offset || 0, limit: COMMENT_LIMIT} + params: {offset: offset || 0, limit: REPLY_LIMIT} }, (err, body, res) => { if (err) { return callback(`Error fetching comment replies: ${err}`); diff --git a/test/unit-legacy/redux/comments-test.js b/test/unit-legacy/redux/comments-test.js index 33c13d942..aa4b74b16 100644 --- a/test/unit-legacy/redux/comments-test.js +++ b/test/unit-legacy/redux/comments-test.js @@ -140,9 +140,9 @@ tap.test('setReplies', t => { t.equal(state.comments[0].moreRepliesToLoad, false); t.equal(state.comments[1].moreRepliesToLoad, false); - // Getting 20 (COMMENT_LIMIT) replies sets moreRepliesToLoad to true + // Getting 25 (REPLY_FETCH_LIMIT) replies sets moreRepliesToLoad to true state = reducer(state, Comments.setReplies({ - id3: (new Array(20)).map((_, i) => ({id: `id${i + 1}`})) + id3: (new Array(25)).map((_, i) => ({id: `id${i + 1}`})) })); t.equal(state.comments[0].moreRepliesToLoad, false); t.equal(state.comments[1].moreRepliesToLoad, false);