Commit f82c9dbe authored by Thong Kuah's avatar Thong Kuah

Use finder to decide to show note to user

Given the note is about how to interpret ancestor clusters, use the
finder which actually knows if there are any ancestor clusters to find
out if the note should be shown, rather than passing the same info via a
view to a helper

Added note about Kaminari.paginate_array

Link to followup issue too
parent 2ad5f999
...@@ -18,8 +18,20 @@ class Clusters::ClustersController < Clusters::BaseController ...@@ -18,8 +18,20 @@ class Clusters::ClustersController < Clusters::BaseController
STATUS_POLLING_INTERVAL = 10_000 STATUS_POLLING_INTERVAL = 10_000
def index def index
clusters = ClusterAncestorsFinder.new(clusterable.subject, current_user).execute finder = ClusterAncestorsFinder.new(clusterable.subject, current_user)
clusters = finder.execute
# Note: We are paginating through an array here but this should OK as:
#
# In CE, we can have a maximum group nesting depth of 21, so including
# project cluster, we can have max 22 clusters for a group hierachy.
# In EE (Premium) we can have any number, as multiple clusters are
# supported, but the number of clusters are fairly low currently.
#
# See https://gitlab.com/gitlab-org/gitlab-ce/issues/55260 also.
@clusters = Kaminari.paginate_array(clusters).page(params[:page]).per(20) @clusters = Kaminari.paginate_array(clusters).page(params[:page]).per(20)
@has_ancestor_clusters = finder.has_ancestor_clusters?
end end
def new def new
......
# frozen_string_literal: true # frozen_string_literal: true
class ClusterAncestorsFinder class ClusterAncestorsFinder
include Gitlab::Utils::StrongMemoize
def initialize(clusterable, current_user) def initialize(clusterable, current_user)
@clusterable = clusterable @clusterable = clusterable
@current_user = current_user @current_user = current_user
...@@ -12,6 +14,10 @@ class ClusterAncestorsFinder ...@@ -12,6 +14,10 @@ class ClusterAncestorsFinder
clusterable.clusters + ancestor_clusters clusterable.clusters + ancestor_clusters
end end
def has_ancestor_clusters?
ancestor_clusters.any?
end
private private
attr_reader :clusterable, :current_user attr_reader :clusterable, :current_user
...@@ -20,7 +26,10 @@ class ClusterAncestorsFinder ...@@ -20,7 +26,10 @@ class ClusterAncestorsFinder
Ability.allowed?(current_user, :read_cluster, clusterable) Ability.allowed?(current_user, :read_cluster, clusterable)
end end
# This unfortunately returns an Array, not a Relation!
def ancestor_clusters def ancestor_clusters
Clusters::Cluster.ancestor_clusters_for_clusterable(clusterable) strong_memoize(:ancestor_clusters) do
Clusters::Cluster.ancestor_clusters_for_clusterable(clusterable)
end
end end
end end
...@@ -14,8 +14,4 @@ module ClustersHelper ...@@ -14,8 +14,4 @@ module ClustersHelper
render 'clusters/clusters/gcp_signup_offer_banner' render 'clusters/clusters/gcp_signup_offer_banner'
end end
end end
def render_cluster_help_content?(clusters, clusterable)
clusters.length > clusterable.clusters.length
end
end end
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
= s_("ClusterIntegration|Kubernetes clusters can be used to deploy applications and to provide Review Apps for this project") = s_("ClusterIntegration|Kubernetes clusters can be used to deploy applications and to provide Review Apps for this project")
= render 'clusters/clusters/buttons' = render 'clusters/clusters/buttons'
- if render_cluster_help_content?(@clusters, clusterable) - if @has_ancestor_clusters
.bs-callout.bs-callout-info .bs-callout.bs-callout-info
= s_("ClusterIntegration|Clusters are utilized by selecting the nearest ancestor with a matching environment scope. For example, project clusters will override group clusters.") = s_("ClusterIntegration|Clusters are utilized by selecting the nearest ancestor with a matching environment scope. For example, project clusters will override group clusters.")
%strong %strong
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment