Commit ca12428c authored by Nicolò Maria Mezzopera's avatar Nicolò Maria Mezzopera

Merge branch 'cluster-application-disable-cleanup-managed' into 'master'

Remove cleanup button for clusters with management project

See merge request gitlab-org/gitlab!35576
parents 6402762d 71be7961
...@@ -222,7 +222,7 @@ export default class Clusters { ...@@ -222,7 +222,7 @@ export default class Clusters {
initRemoveClusterActions() { initRemoveClusterActions() {
const el = document.querySelector('#js-cluster-remove-actions'); const el = document.querySelector('#js-cluster-remove-actions');
if (el && el.dataset) { if (el && el.dataset) {
const { clusterName, clusterPath } = el.dataset; const { clusterName, clusterPath, hasManagementProject } = el.dataset;
this.removeClusterAction = new Vue({ this.removeClusterAction = new Vue({
el, el,
...@@ -231,6 +231,7 @@ export default class Clusters { ...@@ -231,6 +231,7 @@ export default class Clusters {
props: { props: {
clusterName, clusterName,
clusterPath, clusterPath,
hasManagementProject,
}, },
}); });
}, },
......
<script> <script>
import { escape } from 'lodash'; import { escape } from 'lodash';
import SplitButton from '~/vue_shared/components/split_button.vue'; import SplitButton from '~/vue_shared/components/split_button.vue';
import { GlModal, GlDeprecatedButton, GlFormInput } from '@gitlab/ui'; import { GlModal, GlButton, GlDeprecatedButton, GlFormInput } from '@gitlab/ui';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
import csrf from '~/lib/utils/csrf'; import csrf from '~/lib/utils/csrf';
...@@ -27,6 +27,7 @@ export default { ...@@ -27,6 +27,7 @@ export default {
components: { components: {
SplitButton, SplitButton,
GlModal, GlModal,
GlButton,
GlDeprecatedButton, GlDeprecatedButton,
GlFormInput, GlFormInput,
}, },
...@@ -39,6 +40,10 @@ export default { ...@@ -39,6 +40,10 @@ export default {
type: String, type: String,
required: true, required: true,
}, },
hasManagementProject: {
type: Boolean,
required: false,
},
}, },
data() { data() {
return { return {
...@@ -90,6 +95,9 @@ export default { ...@@ -90,6 +95,9 @@ export default {
canSubmit() { canSubmit() {
return this.enteredClusterName === this.clusterName; return this.enteredClusterName === this.clusterName;
}, },
canCleanupResources() {
return !this.hasManagementProject;
},
}, },
methods: { methods: {
handleClickRemoveCluster(cleanup = false) { handleClickRemoveCluster(cleanup = false) {
...@@ -112,12 +120,21 @@ export default { ...@@ -112,12 +120,21 @@ export default {
<template> <template>
<div> <div>
<split-button <split-button
v-if="canCleanupResources"
:action-items="$options.splitButtonActionItems" :action-items="$options.splitButtonActionItems"
menu-class="dropdown-menu-large" menu-class="dropdown-menu-large"
variant="danger" variant="danger"
@remove-cluster="handleClickRemoveCluster(false)" @remove-cluster="handleClickRemoveCluster(false)"
@remove-cluster-and-cleanup="handleClickRemoveCluster(true)" @remove-cluster-and-cleanup="handleClickRemoveCluster(true)"
/> />
<gl-button
v-else
variant="danger"
data-testid="btnRemove"
@click="handleClickRemoveCluster(false)"
>
{{ s__('ClusterIntegration|Remove integration') }}
</gl-button>
<gl-modal <gl-modal
ref="modal" ref="modal"
size="lg" size="lg"
......
...@@ -40,4 +40,6 @@ ...@@ -40,4 +40,6 @@
%p %p
= s_("ClusterIntegration|Remove this Kubernetes cluster's configuration from this project. This will not delete your actual Kubernetes cluster.") = s_("ClusterIntegration|Remove this Kubernetes cluster's configuration from this project. This will not delete your actual Kubernetes cluster.")
#js-cluster-remove-actions{ data: { cluster_path: clusterable.cluster_path(@cluster), cluster_name: @cluster.name } } #js-cluster-remove-actions{ data: { cluster_path: clusterable.cluster_path(@cluster),
cluster_name: @cluster.name,
has_management_project: @cluster.management_project_id? } }
---
title: Hide cleanup button for clusters with management project
merge_request: 35576
author:
type: changed
...@@ -28,7 +28,7 @@ describe('Remove cluster confirmation modal', () => { ...@@ -28,7 +28,7 @@ describe('Remove cluster confirmation modal', () => {
describe('split button dropdown', () => { describe('split button dropdown', () => {
const findModal = () => wrapper.find(GlModal).vm; const findModal = () => wrapper.find(GlModal).vm;
const findSplitButton = () => wrapper.find(SplitButton).vm; const findSplitButton = () => wrapper.find(SplitButton);
beforeEach(() => { beforeEach(() => {
createComponent({ clusterName: 'my-test-cluster' }); createComponent({ clusterName: 'my-test-cluster' });
...@@ -36,7 +36,7 @@ describe('Remove cluster confirmation modal', () => { ...@@ -36,7 +36,7 @@ describe('Remove cluster confirmation modal', () => {
}); });
it('opens modal with "cleanup" option', () => { it('opens modal with "cleanup" option', () => {
findSplitButton().$emit('remove-cluster-and-cleanup'); findSplitButton().vm.$emit('remove-cluster-and-cleanup');
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(findModal().show).toHaveBeenCalled(); expect(findModal().show).toHaveBeenCalled();
...@@ -45,12 +45,23 @@ describe('Remove cluster confirmation modal', () => { ...@@ -45,12 +45,23 @@ describe('Remove cluster confirmation modal', () => {
}); });
it('opens modal without "cleanup" option', () => { it('opens modal without "cleanup" option', () => {
findSplitButton().$emit('remove-cluster'); findSplitButton().vm.$emit('remove-cluster');
return wrapper.vm.$nextTick().then(() => { return wrapper.vm.$nextTick().then(() => {
expect(findModal().show).toHaveBeenCalled(); expect(findModal().show).toHaveBeenCalled();
expect(wrapper.vm.confirmCleanup).toEqual(false); expect(wrapper.vm.confirmCleanup).toEqual(false);
}); });
}); });
describe('with cluster management project', () => {
beforeEach(() => {
createComponent({ hasManagementProject: true });
});
it('renders regular button instead', () => {
expect(findSplitButton().exists()).toBe(false);
expect(wrapper.find('[data-testid="btnRemove"]').exists()).toBe(true);
});
});
}); });
}); });
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