diff --git a/app/views/projects/clusters/_banner.html.haml b/app/views/projects/clusters/_banner.html.haml new file mode 100644 index 00000000000..a1cc66eac92 --- /dev/null +++ b/app/views/projects/clusters/_banner.html.haml @@ -0,0 +1,21 @@ +%h4= s_('ClusterIntegration|Enable cluster integration') +.settings-content + + .hidden.js-cluster-error.alert.alert-danger.alert-block.append-bottom-10{ role: 'alert' } + = s_('ClusterIntegration|Something went wrong while creating your cluster on Google Container Engine') + %p.js-error-reason + + .hidden.js-cluster-creating.alert.alert-info.alert-block.append-bottom-10{ role: 'alert' } + = s_('ClusterIntegration|Cluster is being created on Google Container Engine...') + + .hidden.js-cluster-success.alert.alert-success.alert-block.append-bottom-10{ role: 'alert' } + = s_('ClusterIntegration|Cluster was successfully created on Google Container Engine. Refresh the page to see cluster\'s details') + + %p + - if @cluster.enabled? + - if can?(current_user, :update_cluster, @cluster) + = s_('ClusterIntegration|Cluster integration is enabled for this project. Disabling this integration will not affect your cluster, it will only temporarily turn off GitLab\'s connection to it.') + - else + = s_('ClusterIntegration|Cluster integration is enabled for this project.') + - else + = s_('ClusterIntegration|Cluster integration is disabled for this project.') diff --git a/app/views/projects/clusters/_details.html.haml b/app/views/projects/clusters/_details.html.haml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/app/views/projects/clusters/_enabled.html.haml b/app/views/projects/clusters/_enabled.html.haml new file mode 100644 index 00000000000..6f7ae71de06 --- /dev/null +++ b/app/views/projects/clusters/_enabled.html.haml @@ -0,0 +1,16 @@ += form_for @cluster, url: namespace_project_cluster_path(@project.namespace, @project, @cluster), as: :cluster do |field| + = form_errors(@cluster) + .form-group.append-bottom-20 + %label.append-bottom-10 + = field.hidden_field :enabled, { class: 'js-toggle-input'} + + %button{ type: 'button', + class: "js-toggle-cluster project-feature-toggle #{'checked' unless !@cluster.enabled?} #{'disabled' unless can?(current_user, :update_cluster, @cluster)}", + 'aria-label': s_('ClusterIntegration|Toggle Cluster'), + disabled: !can?(current_user, :update_cluster, @cluster), + data: { 'enabled-text': 'Enabled', 'disabled-text': 'Disabled' } } + + - if can?(current_user, :update_cluster, @cluster) + .form-group + = field.submit _('Save'), class: 'btn btn-success' + \ No newline at end of file diff --git a/app/views/projects/clusters/gcp/_form.html.haml b/app/views/projects/clusters/gcp/_form.html.haml index 3bc1abefc8f..0f6bae97571 100644 --- a/app/views/projects/clusters/gcp/_form.html.haml +++ b/app/views/projects/clusters/gcp/_form.html.haml @@ -1,4 +1,3 @@ - %p - link_to_help_page = link_to(s_('ClusterIntegration|help page'), help_page_path('user/project/clusters/index'), target: '_blank', rel: 'noopener noreferrer') = s_('ClusterIntegration|Read our %{link_to_help_page} on cluster integration.').html_safe % { link_to_help_page: link_to_help_page} diff --git a/app/views/projects/clusters/show.html.haml b/app/views/projects/clusters/show.html.haml index d73324b8863..e7f6e95aa50 100644 --- a/app/views/projects/clusters/show.html.haml +++ b/app/views/projects/clusters/show.html.haml @@ -13,48 +13,12 @@ cluster_status_reason: @cluster.status_reason, help_path: help_page_path('user/project/clusters/index.md', anchor: 'installing-applications') } } - .js-cluster-application-notice .flash-container %section.settings.no-animate.expanded - %h4= s_('ClusterIntegration|Enable cluster integration') - .settings-content - - .hidden.js-cluster-error.alert.alert-danger.alert-block.append-bottom-10{ role: 'alert' } - = s_('ClusterIntegration|Something went wrong while creating your cluster on Google Container Engine') - %p.js-error-reason - - .hidden.js-cluster-creating.alert.alert-info.alert-block.append-bottom-10{ role: 'alert' } - = s_('ClusterIntegration|Cluster is being created on Google Container Engine...') - - .hidden.js-cluster-success.alert.alert-success.alert-block.append-bottom-10{ role: 'alert' } - = s_('ClusterIntegration|Cluster was successfully created on Google Container Engine. Refresh the page to see cluster\'s details') - - %p - - if @cluster.enabled? - - if can?(current_user, :update_cluster, @cluster) - = s_('ClusterIntegration|Cluster integration is enabled for this project. Disabling this integration will not affect your cluster, it will only temporarily turn off GitLab\'s connection to it.') - - else - = s_('ClusterIntegration|Cluster integration is enabled for this project.') - - else - = s_('ClusterIntegration|Cluster integration is disabled for this project.') - - = form_for @cluster, url: namespace_project_cluster_path(@project.namespace, @project, @cluster), as: :cluster do |field| - = form_errors(@cluster) - .form-group.append-bottom-20 - %label.append-bottom-10 - = field.hidden_field :enabled, { class: 'js-toggle-input'} - - %button{ type: 'button', - class: "js-toggle-cluster project-feature-toggle #{'checked' unless !@cluster.enabled?} #{'disabled' unless can?(current_user, :update_cluster, @cluster)}", - 'aria-label': s_('ClusterIntegration|Toggle Cluster'), - disabled: !can?(current_user, :update_cluster, @cluster), - data: { 'enabled-text': 'Enabled', 'disabled-text': 'Disabled' } } - - - if can?(current_user, :update_cluster, @cluster) - .form-group - = field.submit _('Save'), class: 'btn btn-success' + = render 'banner' + = render 'enabled' .cluster-applications-table#js-cluster-applications diff --git a/app/views/projects/clusters/user/_show.html.haml b/app/views/projects/clusters/user/_show.html.haml index afdea391de0..5931e0b7f17 100644 --- a/app/views/projects/clusters/user/_show.html.haml +++ b/app/views/projects/clusters/user/_show.html.haml @@ -1,6 +1,5 @@ = form_for @cluster, url: namespace_project_cluster_path(@project.namespace, @project, @cluster), as: :cluster do |field| = form_errors(@cluster) - .form-group = field.label :name, s_('ClusterIntegration|Cluster name') = field.text_field :name, class: 'form-control', placeholder: s_('ClusterIntegration|Cluster name') diff --git a/spec/factories/clusters/cluster.rb b/spec/factories/clusters/cluster.rb index c4261178f2d..81866845a20 100644 --- a/spec/factories/clusters/cluster.rb +++ b/spec/factories/clusters/cluster.rb @@ -13,27 +13,20 @@ FactoryGirl.define do provider_type :user platform_type :kubernetes - platform_kubernetes do - create(:cluster_platform_kubernetes, :configured) - end + platform_kubernetes factory: [:cluster_platform_kubernetes, :configured] end trait :provided_by_gcp do provider_type :gcp platform_type :kubernetes - before(:create) do |cluster, evaluator| - cluster.platform_kubernetes = build(:cluster_platform_kubernetes, :configured) - cluster.provider_gcp = build(:cluster_provider_gcp, :created) - end + provider_gcp factory: [:cluster_provider_gcp, :created] + platform_kubernetes factory: [:cluster_platform_kubernetes, :configured] end trait :providing_by_gcp do provider_type :gcp - - provider_gcp do - create(:cluster_provider_gcp, :creating) - end + provider_gcp factory: [:cluster_provider_gcp, :creating] end end end diff --git a/spec/features/projects/clusters/user_spec.rb b/spec/features/projects/clusters/user_spec.rb index 1c0a88749bd..2e368387830 100644 --- a/spec/features/projects/clusters/user_spec.rb +++ b/spec/features/projects/clusters/user_spec.rb @@ -21,11 +21,10 @@ feature 'User Cluster', :js do context 'when user filled form with valid parameters' do before do - fill_in 'cluster_provider_gcp_attributes_gcp_project_id', with: 'gcp-project-123' fill_in 'cluster_platform_kubernetes_attributes_api_url', with: 'http://example.com' fill_in 'cluster_platform_kubernetes_attributes_token', with: 'my-token' fill_in 'cluster_name', with: 'dev-cluster' - click_button 'Create cluster' + click_button 'Add cluster' end it 'user sees a cluster details page and creation status' do @@ -35,7 +34,7 @@ feature 'User Cluster', :js do context 'when user filled form with invalid parameters' do before do - click_button 'Create cluster' + click_button 'Add cluster' end it 'user sees a validation error' do @@ -76,7 +75,7 @@ feature 'User Cluster', :js do it 'user sees the successful message' do expect(page).to have_content('Cluster was successfully updated.') - expect(cluster.reload.cluster_name).to eq('my-dev-cluster') + expect(cluster.reload.name).to eq('my-dev-cluster') end end @@ -89,7 +88,7 @@ feature 'User Cluster', :js do it 'user sees creation form with the successful message' do expect(page).to have_content('Cluster integration was successfully removed.') - expect(page).to have_link('Create on GKE') + expect(page).to have_link('Add an existing cluster') end end end