Skip to content

Filter on reported comments#10

Open
tomerqodo wants to merge 4 commits intocopilot_only-issues-20260113-qodo-grep-copilot_base_filter_on_reported_comments_pr98from
copilot_only-issues-20260113-qodo-grep-copilot_head_filter_on_reported_comments_pr98
Open

Filter on reported comments#10
tomerqodo wants to merge 4 commits intocopilot_only-issues-20260113-qodo-grep-copilot_base_filter_on_reported_comments_pr98from
copilot_only-issues-20260113-qodo-grep-copilot_head_filter_on_reported_comments_pr98

Conversation

@tomerqodo
Copy link

Benchmark PR from qodo-benchmark#98

Copilot AI review requested due to automatic review settings January 14, 2026 15:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds filtering functionality for reported comments in the Ghost admin interface. It enables admins to filter comments by report count and displays the report count in the UI.

Changes:

  • Added count.reports field to admin API responses and filtering capability
  • Implemented SQL-based filtering for report counts with various operators (>, >=, =, etc.)
  • Added UI components to display report counts and filter by reported status

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
ghost/core/test/e2e-api/members-comments/comments.test.js Added test to verify reports count is not exposed in public API
ghost/core/test/e2e-api/admin/comments.test.js Added tests for report count filtering with various operators and combinations
ghost/core/test/e2e-api/admin/snapshots/comments.test.js.snap Updated snapshots to include reports count in admin API responses
ghost/core/core/server/services/comments/CommentsService.js Updated service to include count relations and pass through report filtering options
ghost/core/core/server/services/comments/CommentsController.js Added report count filter extraction logic to parse NQL filters
ghost/core/core/server/models/comment.js Added SQL subquery for report count filtering and count relation
ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/comments.js Added logic to include reports in count fields for admin requests
apps/posts/src/views/comments/components/comments-list.tsx Added UI to display report count with icon
apps/posts/src/views/comments/components/comments-header.tsx Added "Reported" filter option in UI
apps/posts/src/views/comments/comments.tsx Added filter building logic for reported/non-reported comments
apps/admin-x-framework/src/api/comments.ts Added reports field to Comment type definition

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


if (jsonModel.count) {
response.count = _.pick(jsonModel.count, countFields);
response.count = _.pick(jsonModel.count, isPublicRequest ? countFieldsAdmin : countFields);
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ternary logic is inverted. When isPublicRequest is true (members API), it uses countFieldsAdmin which includes reports. It should use countFields (without reports) for public requests and countFieldsAdmin for admin requests. Change to !isPublicRequest ? countFieldsAdmin : countFields.

Copilot uses AI. Check for mistakes.
Comment on lines +71 to +74
if (filter.values[0] === 'true') {
parts.push('count.reports:0');
} else if (filter.values[0] === 'false') {
parts.push('count.reports:>0');
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The filter logic is inverted. When the user selects 'reported: Yes' (value='true'), the code filters for count.reports:0 which means zero reports (not reported). Similarly, 'reported: No' (value='false') filters for count.reports:>0 (has reports). The conditions should be swapped: 'true' should map to count.reports:>0 and 'false' should map to count.reports:0.

Copilot uses AI. Check for mistakes.
Comment on lines +1420 to +1421
const res = await adminApi.get('/comments/');
assert.equal(res.body.comments[0].count.reports, 2);
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn't guarantee that the first comment in the response is the one with reports, as the API returns comments in created_at desc order by default. Multiple tests create comments, and the order isn't controlled here. Consider either: 1) Filtering the response to find the specific comment by HTML content, or 2) Using the specific comment ID to fetch and verify.

Copilot uses AI. Check for mistakes.
Comment on lines +1430 to +1431
const res = await adminApi.get('/comments/');
assert.equal(res.body.comments[0].count.reports, 0);
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test assumes the first comment in the response is the newly created one, but doesn't verify it. The response could include other comments created in previous tests (though there's a beforeEach truncate). Consider filtering the response by HTML content to ensure you're checking the correct comment.

Copilot uses AI. Check for mistakes.
Comment on lines +1471 to +1473
const res = await adminApi.get('/comments/?filter=' + encodeURIComponent('count.reports:0'));
assert.equal(res.body.comments.length, 1);
assert.equal(res.body.comments[0].html, '<p>Non-reported comment</p>');
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test may be fragile because it doesn't account for other non-reported comments that might exist. While beforeEach truncates the tables, if the test suite structure changes or runs in isolation, this could fail. Consider adding an assertion about which specific comment is returned or ensuring stricter test isolation.

Copilot uses AI. Check for mistakes.
async getAdminAllComments({includeNested, filter, mongoTransformer, reportCount, order, page, limit}) {
return await this.models.Comment.findPage({
withRelated: ['member', 'post'],
withRelated: ['member', 'post', 'count.replies', 'count.likes'],
Copy link

Copilot AI Jan 14, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The count.reports relation is missing from the withRelated array. The tests expect reports count to be included in admin responses, but it's not being explicitly loaded here. This should include 'count.reports' as well.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants