From cdaf7f6e31fd18fa697fd849dcc9a410b3b599ae Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Tue, 5 Oct 2021 14:48:09 +1100 Subject: [PATCH] feat(dashboard): show tooltip explaining auto created branches --- lib/pact_broker/domain/index_item.rb | 9 +++++ lib/pact_broker/index/service.rb | 4 +- lib/pact_broker/ui/view_models/index_item.rb | 14 +++++++ .../ui/view_models/index_item_branch_head.rb | 39 +++++++++++++++++++ .../index_item_provider_branch_head.rb | 39 +++++++++++++++++++ lib/pact_broker/ui/views/dashboard/show.haml | 21 ++++++---- public/stylesheets/index.css | 5 +++ script/data/auto-create-things-for-tags.rb | 1 + 8 files changed, 123 insertions(+), 9 deletions(-) create mode 100644 lib/pact_broker/ui/view_models/index_item_branch_head.rb create mode 100644 lib/pact_broker/ui/view_models/index_item_provider_branch_head.rb diff --git a/lib/pact_broker/domain/index_item.rb b/lib/pact_broker/domain/index_item.rb index 5952c77bc..19015eb29 100644 --- a/lib/pact_broker/domain/index_item.rb +++ b/lib/pact_broker/domain/index_item.rb @@ -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 @@ -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 diff --git a/lib/pact_broker/index/service.rb b/lib/pact_broker/index/service.rb index 508cc961d..dccaeb481 100644 --- a/lib/pact_broker/index/service.rb +++ b/lib/pact_broker/index/service.rb @@ -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 | diff --git a/lib/pact_broker/ui/view_models/index_item.rb b/lib/pact_broker/ui/view_models/index_item.rb index 161fea9f2..aa1391faa 100644 --- a/lib/pact_broker/ui/view_models/index_item.rb +++ b/lib/pact_broker/ui/view_models/index_item.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/pact_broker/ui/view_models/index_item_branch_head.rb b/lib/pact_broker/ui/view_models/index_item_branch_head.rb new file mode 100644 index 000000000..a6ecb5983 --- /dev/null +++ b/lib/pact_broker/ui/view_models/index_item_branch_head.rb @@ -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 diff --git a/lib/pact_broker/ui/view_models/index_item_provider_branch_head.rb b/lib/pact_broker/ui/view_models/index_item_provider_branch_head.rb new file mode 100644 index 000000000..043a108c0 --- /dev/null +++ b/lib/pact_broker/ui/view_models/index_item_provider_branch_head.rb @@ -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 diff --git a/lib/pact_broker/ui/views/dashboard/show.haml b/lib/pact_broker/ui/views/dashboard/show.haml index cb415b8ff..f1a6c91ab 100644 --- a/lib/pact_broker/ui/views/dashboard/show.haml +++ b/lib/pact_broker/ui/views/dashboard/show.haml @@ -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 @@ -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 @@ -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() { diff --git a/public/stylesheets/index.css b/public/stylesheets/index.css index ac45db71e..f6f60b370 100644 --- a/public/stylesheets/index.css +++ b/public/stylesheets/index.css @@ -241,3 +241,8 @@ span.copy-success-icon { div.top-of-group { margin-top: 20px; } + + +div[data-toggle="tooltip"] { + cursor: pointer; +} diff --git a/script/data/auto-create-things-for-tags.rb b/script/data/auto-create-things-for-tags.rb index b1c9cb669..7bcff2f0d 100755 --- a/script/data/auto-create-things-for-tags.rb +++ b/script/data/auto-create-things-for-tags.rb @@ -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}"