Skip to content

Commit

Permalink
Merge pull request #1278 from alphagov/filtering_recent_deployments_b…
Browse files Browse the repository at this point in the history
…y_environment

Filter Recent Deployments by Environments
  • Loading branch information
robinjam authored Sep 5, 2023
2 parents bac61f5 + 913b4e9 commit 53f2370
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
11 changes: 10 additions & 1 deletion app/controllers/deployments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -131,4 +134,10 @@ def new_deployment_params
:environment,
)
end

def recent_deployment_params
params.permit(
:environment_filter,
)
end
end
22 changes: 22 additions & 0 deletions app/views/deployments/recent.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,27 @@
title: "Recent deployments"
} %>
<%= form_tag(activity_path, method: :get) do %>
<div class="govuk-form-group">
<%= 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"
%>
</div>

<%= render "govuk_publishing_components/components/button", {
text: "Filter",
margin_bottom: true
} %>
<% end %>
<%= render "deployments_list", deploys: @deployments %>
</section>
9 changes: 9 additions & 0 deletions test/functional/deployments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 53f2370

Please sign in to comment.