Commit 02e3bcc7 authored by anna_vovchenko's avatar anna_vovchenko Committed by charlie ablett

Cleaned up clusters_helper and cluster index haml

As we now use the same Vue app for the cluster page on all levels,
we can clean up the clusters helper and cluster index template.
It also fixes the duplicate connect cluster button.

Changelog: fixed
parent a6f4e0bb
......@@ -5,6 +5,14 @@ module ClustersHelper
clusterable.is_a?(Project)
end
def default_branch_name(clusterable)
return clusterable.default_branch if clusterable.is_a?(Project)
end
def clusterable_project_path(clusterable)
return clusterable.full_path if clusterable.is_a?(Project)
end
def js_clusters_list_data(clusterable)
{
ancestor_help_path: help_page_path('user/group/clusters/index', anchor: 'cluster-precedence'),
......@@ -15,24 +23,19 @@ module ClustersHelper
gcp: { path: image_path('illustrations/logos/google_gke.svg'), text: s_('ClusterIntegration|Google GKE') }
},
clusters_empty_state_image: image_path('illustrations/empty-state/empty-state-clusters.svg'),
empty_state_image: image_path('illustrations/empty-state/empty-state-agents.svg'),
empty_state_help_text: clusterable.empty_state_help_text,
new_cluster_path: clusterable.new_path,
add_cluster_path: clusterable.connect_path,
can_add_cluster: clusterable.can_add_cluster?.to_s,
can_admin_cluster: clusterable.can_admin_cluster?.to_s,
display_cluster_agents: display_cluster_agents?(clusterable).to_s,
certificate_based_clusters_enabled: Feature.enabled?(:certificate_based_clusters, clusterable, default_enabled: :yaml, type: :ops).to_s
}
end
def js_clusters_data(clusterable)
{
default_branch_name: clusterable.default_branch,
empty_state_image: image_path('illustrations/empty-state/empty-state-agents.svg'),
project_path: clusterable.full_path,
certificate_based_clusters_enabled: Feature.enabled?(:certificate_based_clusters, clusterable, default_enabled: :yaml, type: :ops).to_s,
default_branch_name: default_branch_name(clusterable),
project_path: clusterable_project_path(clusterable),
kas_address: Gitlab::Kas.external_url,
gitlab_version: Gitlab.version_info
}.merge(js_clusters_list_data(clusterable))
}
end
def js_cluster_form_data(cluster, can_edit)
......
......@@ -4,9 +4,5 @@
= render_gcp_signup_offer
.clusters-container
- if display_cluster_agents?(clusterable)
.gl-my-6
.js-clusters-main-view{ data: js_clusters_data(clusterable) }
- else
.gl-my-6
.js-clusters-main-view{ data: js_clusters_list_data(clusterable) }
......@@ -58,6 +58,7 @@ RSpec.describe ClustersHelper do
it 'displays empty image path' do
expect(subject[:clusters_empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-clusters|svg))
expect(subject[:empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-agents|svg))
end
it 'displays create cluster using certificate path' do
......@@ -68,6 +69,22 @@ RSpec.describe ClustersHelper do
expect(subject[:add_cluster_path]).to eq("#{project_path(project)}/-/clusters/connect")
end
it 'displays project default branch' do
expect(subject[:default_branch_name]).to eq(project.default_branch)
end
it 'displays project path' do
expect(subject[:project_path]).to eq(project.full_path)
end
it 'displays kas address' do
expect(subject[:kas_address]).to eq(Gitlab::Kas.external_url)
end
it 'displays GitLab version' do
expect(subject[:gitlab_version]).to eq(Gitlab.version_info)
end
context 'user has no permissions to create a cluster' do
it 'displays that user can\'t add cluster' do
expect(subject[:can_add_cluster]).to eq("false")
......@@ -132,34 +149,6 @@ RSpec.describe ClustersHelper do
end
end
describe '#js_clusters_data' do
let_it_be(:current_user) { create(:user) }
let_it_be(:project) { build(:project) }
let_it_be(:clusterable) { ClusterablePresenter.fabricate(project, current_user: current_user) }
subject { helper.js_clusters_data(clusterable) }
it 'displays project default branch' do
expect(subject[:default_branch_name]).to eq(project.default_branch)
end
it 'displays image path' do
expect(subject[:empty_state_image]).to match(%r(/illustrations/empty-state/empty-state-agents|svg))
end
it 'displays project path' do
expect(subject[:project_path]).to eq(project.full_path)
end
it 'displays kas address' do
expect(subject[:kas_address]).to eq(Gitlab::Kas.external_url)
end
it 'displays GitLab version' do
expect(subject[:gitlab_version]).to eq(Gitlab.version_info)
end
end
describe '#js_cluster_new' do
subject { helper.js_cluster_new }
......
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