From c6bf8030317b2f4d8c0ae2b776b18ffc2a2de7cf Mon Sep 17 00:00:00 2001 From: Kat Date: Thu, 16 Nov 2023 15:26:11 +0000 Subject: [PATCH] Clear filter for a specific organisation --- app/controllers/sessions_controller.rb | 6 +++++- app/views/logs/_log_filters.html.erb | 2 +- spec/requests/organisations_controller_spec.rb | 10 ++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 1e350829a..868b4936d 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,7 +3,11 @@ class SessionsController < ApplicationController session[session_name_for(params[:filter_type])] = "{}" path_params = params[:path_params].presence || {} - redirect_to send("#{params[:filter_type]}_path", scheme_id: path_params[:scheme_id], search: path_params[:search]) + if path_params[:organisation_id].present? + redirect_to send("#{params[:filter_type]}_organisation_path", id: path_params[:organisation_id], scheme_id: path_params[:scheme_id], search: path_params[:search]) + else + redirect_to send("#{params[:filter_type]}_path", scheme_id: path_params[:scheme_id], search: path_params[:search]) + end end private diff --git a/app/views/logs/_log_filters.html.erb b/app/views/logs/_log_filters.html.erb index 96e9eeeff..72f73e47c 100644 --- a/app/views/logs/_log_filters.html.erb +++ b/app/views/logs/_log_filters.html.erb @@ -12,7 +12,7 @@ <%= filters_applied_text(@filter_type) %>

- <%= reset_filters_link(@filter_type, { search: request.params["search"] }.compact) %> + <%= reset_filters_link(@filter_type, { search: request.params["search"], organisation_id: @organisation&.id }.compact) %>

<% if bulk_upload_options(@bulk_upload).present? %> diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index 340f1facf..4bd6e0eb6 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -1440,6 +1440,16 @@ RSpec.describe OrganisationsController, type: :request do }.to enqueue_job(EmailCsvJob).with(user, nil, {}, false, organisation, codes_only_export_type) end end + + context "when filters are applied" do + before do + get lettings_logs_organisation_path(organisation, status: %w[completed]) + end + + it "has clear filters link" do + expect(page).to have_link("Clear", href: clear_filters_path(filter_type: "lettings_logs", path_params: { organisation_id: organisation.id })) + end + end end context "when they view the sales logs tab" do