diff --git a/app/controllers/deployments_controller.rb b/app/controllers/deployments_controller.rb index bca0990b9..46f3eb2c8 100644 --- a/app/controllers/deployments_controller.rb +++ b/app/controllers/deployments_controller.rb @@ -15,7 +15,10 @@ def show end def recent - @deployments = Deployment.includes(:application).newest_first.limit(25) + env = recent_deployment_params[:environment_filter] + + filtered_deployments = env ? Deployment.where(environment: [env, "#{env} EKS"]) : Deployment + @deployments = filtered_deployments.includes(:application).newest_first.limit(25) end def new @@ -131,4 +134,10 @@ def new_deployment_params :environment, ) end + + def recent_deployment_params + params.permit( + :environment_filter, + ) + end end diff --git a/app/views/deployments/recent.html.erb b/app/views/deployments/recent.html.erb index 30e61547c..241da1784 100644 --- a/app/views/deployments/recent.html.erb +++ b/app/views/deployments/recent.html.erb @@ -13,5 +13,27 @@ title: "Recent deployments" } %> +<%= form_tag(activity_path, method: :get) do %> +
+ <%= render "govuk_publishing_components/components/label", { + text: "Filter environment", + html_for: "deployment-environment-filter", + bold: true + } %> + + <%= select_tag "environment_filter", + options_for_select(Application::ENVIRONMENTS_ORDER.map(&:capitalize), [params[:environment_filter]]), + include_blank: true, + id: "deployment-environment-filter", + class: "govuk-select" + %> +
+ + <%= render "govuk_publishing_components/components/button", { + text: "Filter", + margin_bottom: true + } %> +<% end %> + <%= render "deployments_list", deploys: @deployments %> diff --git a/test/functional/deployments_controller_test.rb b/test/functional/deployments_controller_test.rb index c95f136b1..d1482716e 100644 --- a/test/functional/deployments_controller_test.rb +++ b/test/functional/deployments_controller_test.rb @@ -24,6 +24,15 @@ class DeploymentsControllerTest < ActionController::TestCase assert_equal 10, assigns(:deployments).size end + + should "assign only filtered environments" do + FactoryBot.create(:deployment, application_id: @application.id, environment: "integration EKS") + FactoryBot.create(:deployment, application_id: @application.id, environment: "integration") + + get :recent, params: { environment_filter: "Integration" } + + assert_equal 2, assigns(:deployments).size + end end context "GET new" do