Commit 7e4f76ea authored by Thong Kuah's avatar Thong Kuah

Show clusters of ancestors in cluster list page

Show both the cluster(s) of the clusterable, and the cluster(s) of
ancestor groups.
parent 8b460204
...@@ -18,8 +18,8 @@ class Clusters::ClustersController < Clusters::BaseController ...@@ -18,8 +18,8 @@ class Clusters::ClustersController < Clusters::BaseController
STATUS_POLLING_INTERVAL = 10_000 STATUS_POLLING_INTERVAL = 10_000
def index def index
clusters = ClustersFinder.new(clusterable, current_user, :all).execute clusters = ClusterAncestorsFinder.new(clusterable.subject, current_user).execute
@clusters = clusters.page(params[:page]).per(20) @clusters = Kaminari.paginate_array(clusters).page(params[:page]).per(20)
end end
def new def new
......
# frozen_string_literal: true
class ClusterAncestorsFinder
def initialize(clusterable, user)
@clusterable = clusterable
@user = user
end
def execute
clusterable.clusters + ancestor_clusters
end
private
attr_reader :clusterable, :user
def ancestor_clusters
Clusters::Cluster.ancestor_clusters_for_clusterable(clusterable)
end
end
---
title: Show clusters of ancestors in cluster list page
merge_request: 22996
author:
type: changed
# frozen_string_literal: true
require 'spec_helper'
describe ClusterAncestorsFinder, '#execute' do
let(:group) { create(:group) }
let(:project) { create(:project, group: group) }
let(:user) { create(:user) }
let!(:project_cluster) do
create(:cluster, :provided_by_user, cluster_type: :project_type, projects: [project])
end
let!(:group_cluster) do
create(:cluster, :provided_by_user, cluster_type: :group_type, groups: [group])
end
subject { described_class.new(clusterable, user).execute }
context 'for a project' do
let(:clusterable) { project }
it 'returns the project clusters followed by group clusters' do
is_expected.to eq([project_cluster, group_cluster])
end
context 'nested groups', :nested_groups do
let(:group) { create(:group, parent: parent_group) }
let(:parent_group) { create(:group) }
let!(:parent_group_cluster) do
create(:cluster, :provided_by_user, cluster_type: :group_type, groups: [parent_group])
end
it 'returns the project clusters followed by group clusters ordered ascending the hierarchy' do
is_expected.to eq([project_cluster, group_cluster, parent_group_cluster])
end
end
end
context 'for a group' do
let(:clusterable) { group }
it 'returns the list of group clusters' do
is_expected.to eq([group_cluster])
end
context 'nested groups', :nested_groups do
let(:group) { create(:group, parent: parent_group) }
let(:parent_group) { create(:group) }
let!(:parent_group_cluster) do
create(:cluster, :provided_by_user, cluster_type: :group_type, groups: [parent_group])
end
it 'returns the list of group clusters ordered ascending the hierarchy' do
is_expected.to eq([group_cluster, parent_group_cluster])
end
end
end
end
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