From f6f8fb20bf2db777d79381ab165dcf2996560ccf Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 29 Apr 2019 14:12:32 +1000 Subject: [PATCH] feat(dashboard): sort items by most recent activity --- lib/pact_broker/api/decorators/dashboard_decorator.rb | 6 +++++- lib/pact_broker/domain/index_item.rb | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/pact_broker/api/decorators/dashboard_decorator.rb b/lib/pact_broker/api/decorators/dashboard_decorator.rb index fd617a0e3..785c4f997 100644 --- a/lib/pact_broker/api/decorators/dashboard_decorator.rb +++ b/lib/pact_broker/api/decorators/dashboard_decorator.rb @@ -26,11 +26,15 @@ def to_hash(options) attr_reader :index_items def items(index_items, base_url) - index_items.collect do | index_item | + sorted_index_items.collect do | index_item | index_item_hash(index_item.consumer, index_item.provider, index_item.consumer_version, index_item, base_url) end end + def sorted_index_items + index_items.sort{ |i1, i2| i2.last_activity_date <=> i1.last_activity_date } + end + def index_item_hash(consumer, provider, consumer_version, index_item, base_url) { consumer: consumer_hash(index_item, consumer, consumer_version, base_url), diff --git a/lib/pact_broker/domain/index_item.rb b/lib/pact_broker/domain/index_item.rb index f1eb5a7d1..22b54dd41 100644 --- a/lib/pact_broker/domain/index_item.rb +++ b/lib/pact_broker/domain/index_item.rb @@ -135,6 +135,9 @@ def to_a [consumer, provider] end + def last_activity_date + @last_activity_date ||= [latest_pact.created_at, latest_verification ? latest_verification.execution_date : nil].compact.max + end end end end