From 8d72a51ae195dc795e67ce1b95c2e8f7ed2bad8c Mon Sep 17 00:00:00 2001 From: Alan Guo Xiang Tan Date: Thu, 24 Aug 2023 08:50:20 +0800 Subject: [PATCH] FIX: Infinite loading broken on group members list (#23214) This regressed in 5a9924362906040e5511a72e66bf946c2554080e where the condition to load more members into the list on the client side was inverted. --- .../discourse/app/controllers/group-index.js | 2 +- app/controllers/groups_controller.rb | 5 +++-- spec/system/viewing_group_members_spec.rb | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 spec/system/viewing_group_members_spec.rb diff --git a/app/assets/javascripts/discourse/app/controllers/group-index.js b/app/assets/javascripts/discourse/app/controllers/group-index.js index eaf170d63d4..86898b04937 100644 --- a/app/assets/javascripts/discourse/app/controllers/group-index.js +++ b/app/assets/javascripts/discourse/app/controllers/group-index.js @@ -23,7 +23,7 @@ export default Controller.extend({ bulkSelection: null, get canLoadMore() { - return this.get("model.members")?.length >= this.get("model.user_count"); + return this.get("model.members")?.length < this.get("model.user_count"); }, @observes("filterInput") diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index bbd465858a2..e11904ea11b 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -230,14 +230,15 @@ class GroupsController < ApplicationController render "posts/latest", formats: [:rss] end - MEMBERS_LIMIT = 1_000 + MEMBERS_MAX_PAGE_SIZE = 1_000 + MEMBERS_DEFAULT_PAGE_SIZE = 50 def members group = find_group(:group_id) guardian.ensure_can_see_group_members!(group) - limit = fetch_limit_from_params(default: 50, max: MEMBERS_LIMIT) + limit = fetch_limit_from_params(default: MEMBERS_DEFAULT_PAGE_SIZE, max: MEMBERS_MAX_PAGE_SIZE) offset = params[:offset].to_i raise Discourse::InvalidParameters.new(:offset) if offset < 0 diff --git a/spec/system/viewing_group_members_spec.rb b/spec/system/viewing_group_members_spec.rb new file mode 100644 index 00000000000..a743a4256ce --- /dev/null +++ b/spec/system/viewing_group_members_spec.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +RSpec.describe "Viewing group members", type: :system do + fab!(:group) { Fabricate(:group) } + fab!(:user_in_group_1) { Fabricate(:user).tap { |u| group.add(u) } } + fab!(:user_in_group_2) { Fabricate(:user).tap { |u| group.add(u) } } + fab!(:user_in_group_3) { Fabricate(:user).tap { |u| group.add(u) } } + + it "loads more group members when a user scrolls to the bottom of the list" do + stub_const(GroupsController, "MEMBERS_DEFAULT_PAGE_SIZE", 2) do + visit("/g/#{group.name}/members") + + expect(page).to have_selector(".group-member", count: 3) + end + end +end