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
STATUS_POLLING_INTERVAL = 10_000
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)
@has_ancestor_clusters = finder.has_ancestor_clusters?
end
def new
......
# frozen_string_literal: true
class ClusterAncestorsFinder
include Gitlab::Utils::StrongMemoize
def initialize(clusterable, current_user)
@clusterable = clusterable
@current_user = current_user
......@@ -12,6 +14,10 @@ class ClusterAncestorsFinder
clusterable.clusters + ancestor_clusters
end
def has_ancestor_clusters?
ancestor_clusters.any?
end
private
attr_reader :clusterable, :current_user
......@@ -20,7 +26,10 @@ class ClusterAncestorsFinder
Ability.allowed?(current_user, :read_cluster, clusterable)
end
# This unfortunately returns an Array, not a Relation!
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
......@@ -14,8 +14,4 @@ module ClustersHelper
render 'clusters/clusters/gcp_signup_offer_banner'
end
end
def render_cluster_help_content?(clusters, clusterable)
clusters.length > clusterable.clusters.length
end
end
......@@ -12,7 +12,7 @@
= s_("ClusterIntegration|Kubernetes clusters can be used to deploy applications and to provide Review Apps for this project")
= render 'clusters/clusters/buttons'
- if render_cluster_help_content?(@clusters, clusterable)
- if @has_ancestor_clusters
.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.")
%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