A platform for community discussion. Free, open, simple.
FIX: ensures loading more doesn’t erase filter on browse (#19675)
Joffrey JAFFEUXb97fff444eea
diff --git a/plugins/chat/app/controllers/api/chat_channels_controller.rb b/plugins/chat/app/controllers/api/chat_channels_controller.rbindex 9e70a95d015..0a0d77590d5 100644--- a/plugins/chat/app/controllers/api/chat_channels_controller.rb+++ b/plugins/chat/app/controllers/api/chat_channels_controller.rb@@ -5,16 +5,14 @@ CATEGORY_CHANNEL_EDITABLE_PARAMS = %i[auto_join_users allow_channel_wide_mentionclass Chat::Api::ChatChannelsController < Chat::Apidef index- options = { status: params[:status] ? ChatChannel.statuses[params[:status]] : nil }.merge(- params.permit(:filter, :limit, :offset),- ).symbolize_keys!+ permitted = params.permit(:filter, :limit, :offset, :status)- options[:offset] = options[:offset].to_i- options[:limit] = (options[:limit] || 25).to_i+ options = { filter: permitted[:filter], limit: (permitted[:limit] || 25).to_i }+ options[:offset] = permitted[:offset].to_i+ options[:status] = ChatChannel.statuses[permitted[:status]] ? permitted[:status] : nilmemberships = Chat::ChatChannelMembershipManager.all_for_user(current_user)channels = Chat::ChatChannelFetcher.secured_public_channels(guardian, memberships, options)-serialized_channels =channels.map do |channel|ChatChannelSerializer.new(@@ -24,14 +22,10 @@ class Chat::Api::ChatChannelsController < Chat::Api)end- pagination_options =- options.slice(:offset, :limit, :filter).merge(offset: options[:offset] + options[:limit])- pagination_params = pagination_options.map { |k, v| "#{k}=#{v}" }.join("&")- render json: serialized_channels,- root: "channels",- meta: {- load_more_url: "/chat/api/channels?#{pagination_params}",- }+ load_more_params = options.merge(offset: options[:offset] + options[:limit]).to_query+ load_more_url = URI::HTTP.build(path: "/chat/api/channels", query: load_more_params)++ render json: serialized_channels, root: "channels", meta: { load_more_url: load_more_url }enddef destroydiff --git a/plugins/chat/spec/system/browse_page_spec.rb b/plugins/chat/spec/system/browse_page_spec.rbindex 9022ca05245..704e6e2f1be 100644--- a/plugins/chat/spec/system/browse_page_spec.rb+++ b/plugins/chat/spec/system/browse_page_spec.rb@@ -149,6 +149,18 @@ RSpec.describe "Browse page", type: :system, js: true doexpect(browse_view).to have_no_content(category_channel_4.name)end+ context "when loading more" do+ fab!(:valid_channel) { Fabricate(:chat_channel, status: :open) }+ fab!(:invalid_channel) { Fabricate(:chat_channel, status: :closed) }++ it "keeps the filter" do+ visit("/chat/browse/open")++ expect(page).to have_content(valid_channel.title)+ expect(page).to have_no_content(invalid_channel.title)+ end+ end+include_examples "never visible channels" dobefore { visit("/chat/browse/open") }end@@ -164,6 +176,18 @@ RSpec.describe "Browse page", type: :system, js: true doexpect(browse_view).to have_no_content(category_channel_4.name)end+ context "when loading more" do+ fab!(:valid_channel) { Fabricate(:chat_channel, status: :closed) }+ fab!(:invalid_channel) { Fabricate(:chat_channel, status: :open) }++ it "keeps the filter" do+ visit("/chat/browse/closed")++ expect(page).to have_content(valid_channel.title)+ expect(page).to have_no_content(invalid_channel.title)+ end+ end+include_examples "never visible channels" dobefore { visit("/chat/browse/closed") }end@@ -181,6 +205,18 @@ RSpec.describe "Browse page", type: :system, js: true doexpect(browse_view).to have_content(category_channel_4.name)end+ context "when loading more" do+ fab!(:valid_channel) { Fabricate(:chat_channel, status: :archived) }+ fab!(:invalid_channel) { Fabricate(:chat_channel, status: :open) }++ it "keeps the filter" do+ visit("/chat/browse/archived")++ expect(page).to have_content(valid_channel.title)+ expect(page).to have_no_content(invalid_channel.title)+ end+ end+include_examples "never visible channels" dobefore { visit("/chat/browse/archived") }end