Skip to content

Commit

Permalink
feat(dashboard): show tooltip explaining auto created branches
Browse files Browse the repository at this point in the history
  • Loading branch information
bethesque committed Oct 5, 2021
1 parent 7461371 commit cdaf7f6
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 9 deletions.
9 changes: 9 additions & 0 deletions lib/pact_broker/domain/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def consumer_version_branches
consumer_version.branch_heads.collect(&:branch_name)
end

def consumer_version_branch_heads
consumer_version.branch_heads
end

def consumer_version_environment_names
(consumer_version.current_deployed_versions.collect(&:environment).collect(&:name) + consumer_version.current_supported_released_versions.collect(&:environment).collect(&:name)).uniq
end
Expand All @@ -90,6 +94,11 @@ def provider_version_number
@latest_verification ? @latest_verification.provider_version_number : nil
end

def provider_version_branch_heads
provider_version&.branch_heads || []
end


def provider_version_branches
provider_version&.branch_heads&.collect(&:branch_name) || []
end
Expand Down
4 changes: 2 additions & 2 deletions lib/pact_broker/index/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ def self.find_index_items_for_api(consumer_name: nil, provider_name: nil, page_n
pact_publications = head_pact_publications(consumer_name: consumer_name, provider_name: provider_name, tags: true, page_number: page_number, page_size: page_size)
.eager(:consumer)
.eager(:provider)
.eager(pact_version: { latest_verification: { provider_version: [{ current_deployed_versions: :environment }, { current_supported_released_versions: :environment }, :branch_heads, { tags: :head_tag }]} })
.eager(consumer_version: [{ current_deployed_versions: :environment }, { current_supported_released_versions: :environment }, :branch_heads, { tags: :head_tag }])
.eager(pact_version: { latest_verification: { provider_version: [{ current_deployed_versions: :environment }, { current_supported_released_versions: :environment }, { branch_heads: :branch_version }, { tags: :head_tag }]} })
.eager(consumer_version: [{ current_deployed_versions: :environment }, { current_supported_released_versions: :environment }, { branch_heads: :branch_version }, { tags: :head_tag }])
.eager(:head_pact_publications_for_tags)

pact_publications.all.collect do | pact_publication |
Expand Down
14 changes: 14 additions & 0 deletions lib/pact_broker/ui/view_models/index_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require "pact_broker/date_helper"
require "pact_broker/versions/abbreviate_number"
require "pact_broker/configuration"
require "pact_broker/ui/view_models/index_item_branch_head"
require "pact_broker/ui/view_models/index_item_provider_branch_head"
require "forwardable"

module PactBroker
Expand Down Expand Up @@ -66,6 +68,12 @@ def latest?
@relationship.latest?
end

def consumer_version_branch_heads
@relationship.consumer_version_branch_heads.collect do | branch_head |
IndexItemBranchHead.new(branch_head, consumer_name)
end
end

def consumer_version_latest_tag_names
@relationship.tag_names
end
Expand All @@ -74,6 +82,12 @@ def provider_version_latest_tag_names
@relationship.latest_verification_latest_tags.collect(&:name)
end

def provider_version_branch_heads
@relationship.provider_version_branch_heads.collect do | branch_head |
IndexItemProviderBranchHead.new(branch_head, provider_name)
end
end

def consumer_group_url
Helpers::URLHelper.group_url(consumer_name, base_url)
end
Expand Down
39 changes: 39 additions & 0 deletions lib/pact_broker/ui/view_models/index_item_branch_head.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "pact_broker/api/pact_broker_urls"
require "pact_broker/ui/helpers/url_helper"
require "pact_broker/date_helper"

module PactBroker
module UI
module ViewDomain
class IndexItemBranchHead

include PactBroker::Api::PactBrokerUrls

def initialize branch_head, pacticipant_name
@branch_head = branch_head
@pacticipant_name = pacticipant_name
end

def branch_name
branch_head.branch_name
end

def tooltip
if branch_head.branch_version.auto_created
"This is the latest pact from branch \"#{branch_name}\". This branch was automatically inferred from the first tag because the Pact Broker configuration setting `use_first_tag_as_branch` was true."
else
"This is the latest pact from branch \"#{branch_name}\"."
end
end

def latest?
true
end

private

attr_reader :branch_head, :pacticipant_name
end
end
end
end
39 changes: 39 additions & 0 deletions lib/pact_broker/ui/view_models/index_item_provider_branch_head.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
require "pact_broker/api/pact_broker_urls"
require "pact_broker/ui/helpers/url_helper"
require "pact_broker/date_helper"

module PactBroker
module UI
module ViewDomain
class IndexItemProviderBranchHead

include PactBroker::Api::PactBrokerUrls

def initialize branch_head, pacticipant_name
@branch_head = branch_head
@pacticipant_name = pacticipant_name
end

def branch_name
branch_head.branch_name
end

def tooltip
if branch_head.branch_version.auto_created
"The latest verification is from branch \"#{branch_name}\". This branch was automatically inferred from the first tag because the Pact Broker configuration setting `use_first_tag_as_branch` was true."
else
"The latest verification is from branch \"#{branch_name}\"."
end
end

def latest?
true
end

private

attr_reader :branch_head, :pacticipant_name
end
end
end
end
21 changes: 14 additions & 7 deletions lib/pact_broker/ui/views/dashboard/show.haml
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@
%button.clippy.invisible{ title: "Copy to clipboard" }
%span.copy-icon
- if view == "branch" || view == "all"
- index_item.consumer_version_branches.each do | branch_name |
%div{"class": "tag badge badge-dark"}
= "branch: " + branch_name
- index_item.consumer_version_branch_heads.each do | branch_head |
%div{"class": "tag badge badge-dark", "title": branch_head.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
= "branch: " + branch_head.branch_name
- if view == "tag" || view == "all"
- index_item.consumer_version_latest_tag_names.each do | tag_name |
.tag.badge.badge-primary
Expand All @@ -106,9 +106,9 @@
%button.clippy.invisible{ title: "Copy to clipboard" }
%span.copy-icon
- if view == "branch" || view == "all"
- index_item.provider_version_branches.each do | branch_name |
%div{"class": "tag badge badge-dark"}
= "branch: " + branch_name
- index_item.provider_version_branch_heads.each do | branch_head |
%div{"class": "tag badge badge-dark", "title": branch_head.tooltip, "data-toggle": "tooltip", "data-placement": "right"}
= "branch: " + branch_head.branch_name
- if view == "tag" || view == "all"
- index_item.provider_version_latest_tag_names.each do | tag_name |
.tag.badge.badge-primary
Expand Down Expand Up @@ -159,8 +159,15 @@
$('td[data-toggle="tooltip"]').each(function(index, td){
//appended tooltip div screws up table if it's appended after a
//td, so need to append it to a div
$(td).tooltip({container: $(td).first()});
$(td).tooltip({ container: $(td).first() });
});

// https://www.w3schools.com/bootstrap/bootstrap_ref_js_tooltip.asp
$('div[data-toggle="tooltip"]').each(function(index, div){
$(div).tooltip()
});

});

$(".reset-search").on("click", function() {
Expand Down
5 changes: 5 additions & 0 deletions public/stylesheets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -241,3 +241,8 @@ span.copy-success-icon {
div.top-of-group {
margin-top: 20px;
}


div[data-toggle="tooltip"] {
cursor: pointer;
}
1 change: 1 addition & 0 deletions script/data/auto-create-things-for-tags.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.deploy_to_prod(pacticipant: "AutoDetectTestProvider", version: "1")
.publish_pact(consumer: "AutoDetectTestConsumer", provider: "AutoDetectTestProvider", consumer_version: "1", tag: "feat/x", content_id: "2111")
.publish_pact(consumer: "AutoDetectTestConsumer", provider: "AutoDetectTestProvider", consumer_version: "2", tag: "feat/y", content_id: "21asdfd")
.deploy_to_prod(pacticipant: "AutoDetectTestConsumer", version: "1")

rescue StandardError => e
puts "#{e.class} #{e.message}"
Expand Down

0 comments on commit cdaf7f6

Please sign in to comment.