Skip to content

Commit

Permalink
feat(dashboard): sort items by most recent activity
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Apr 29, 2019
1 parent 8b9f953 commit f6f8fb2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/pact_broker/api/decorators/dashboard_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
3 changes: 3 additions & 0 deletions lib/pact_broker/domain/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f6f8fb2

Please sign in to comment.