Commit 23232ccc authored by Mike Greiling's avatar Mike Greiling

Merge branch 'je-separate-namespace-fe' into 'master'

Add namespace label toggle

See merge request gitlab-org/gitlab-ce!30935
parents 9eea3623 f0b2ef0b
import ClustersBundle from '~/clusters/clusters_bundle';
import initGkeNamespace from '~/projects/gke_cluster_namespace';
document.addEventListener('DOMContentLoaded', () => {
new ClustersBundle(); // eslint-disable-line no-new
initGkeNamespace();
});
import initGkeDropdowns from '~/projects/gke_cluster_dropdowns';
import initGkeNamespace from '~/projects/gke_cluster_namespace';
import PersistentUserCallout from '../../persistent_user_callout';
import Project from './project';
import ShortcutsNavigation from '../../behaviors/shortcuts/shortcuts_navigation';
......@@ -16,6 +17,7 @@ document.addEventListener('DOMContentLoaded', () => {
PersistentUserCallout.factory(callout);
initGkeDropdowns();
initGkeNamespace();
}
new Project(); // eslint-disable-line no-new
......
/**
* Disables & hides the namespace inputs when the gitlab-managed checkbox is checked/unchecked.
*/
const setDisabled = (el, isDisabled) => {
if (isDisabled) {
el.classList.add('hidden');
el.querySelector('input').setAttribute('disabled', true);
} else {
el.classList.remove('hidden');
el.querySelector('input').removeAttribute('disabled');
}
};
const setState = glManagedCheckbox => {
const glManaged = document.querySelector('.js-namespace-prefixed');
const selfManaged = document.querySelector('.js-namespace');
if (glManagedCheckbox.checked) {
setDisabled(glManaged, false);
setDisabled(selfManaged, true);
} else {
setDisabled(glManaged, true);
setDisabled(selfManaged, false);
}
};
const initGkeNamespace = () => {
const glManagedCheckbox = document.querySelector('.js-gl-managed');
setState(glManagedCheckbox); // this is needed in order to set the initial state
glManagedCheckbox.addEventListener('change', () => setState(glManagedCheckbox));
};
export default initGkeNamespace;
- managed_namespace_help_text = s_('ClusterIntegration|Choose a prefix to be used for your namespaces. Defaults to your project path.')
- non_managed_namespace_help_text = s_('ClusterIntegration|The namespace associated with your project. This will be used for deploy boards, pod logs, and Web terminals.')
- managed_namespace_help_link = link_to _('More information'), help_page_path('user/project/clusters/index.md',
anchor: 'gitlab-managed-clusters'), target: '_blank'
.js-namespace-prefixed
= platform_field.text_field :namespace,
label: s_('ClusterIntegration|Project namespace prefix (optional, unique)'), label_class: 'label-bold',
help: '%{help_text} %{help_link}'.html_safe % { help_text: managed_namespace_help_text, help_link: managed_namespace_help_link }
.js-namespace.hidden
= platform_field.text_field :namespace,
label: s_('ClusterIntegration|Project namespace (optional, unique)'), label_class: 'label-bold',
help: '%{help_text}'.html_safe % { help_text: non_managed_namespace_help_text },
disabled: true
......@@ -34,10 +34,6 @@
autocomplete: 'off', label_class: 'label-bold',
help: '%{help_text} %{help_link}'.html_safe % { help_text: token_help_text, help_link: more_info_link }
- if @user_cluster.allow_user_defined_namespace?
= platform_kubernetes_field.text_field :namespace,
label: s_('ClusterIntegration|Project namespace (optional, unique)'), label_class: 'label-bold'
= platform_kubernetes_field.form_group :authorization_type,
{ help: '%{help_text} %{help_link}'.html_safe % { help_text: rbac_help_text, help_link: rbac_help_link } } do
= platform_kubernetes_field.check_box :authorization_type,
......@@ -46,10 +42,15 @@
.form-group
= field.check_box :managed, { label: s_('ClusterIntegration|GitLab-managed cluster'),
class: 'js-gl-managed',
label_class: 'label-bold' }
.form-text.text-muted
= s_('ClusterIntegration|Allow GitLab to manage namespace and service accounts for this cluster.')
= link_to _('More information'), help_page_path('user/project/clusters/index.md', anchor: 'gitlab-managed-clusters'), target: '_blank'
= field.fields_for :platform_kubernetes, @user_cluster.platform_kubernetes do |platform_kubernetes_field|
- if @user_cluster.allow_user_defined_namespace?
= render('clusters/clusters/namespace', platform_field: platform_kubernetes_field)
.form-group
= field.submit s_('ClusterIntegration|Add Kubernetes cluster'), class: 'btn btn-success'
......@@ -36,10 +36,6 @@
label: s_('ClusterIntegration|Service Token'), label_class: 'label-bold',
input_group_class: 'gl-field-error-anchor', append: show_token_btn + copy_token_btn
- if cluster.allow_user_defined_namespace?
= platform_field.text_field :namespace, label: s_('ClusterIntegration|Project namespace (optional, unique)'),
label_class: 'label-bold'
= platform_field.form_group :authorization_type do
= platform_field.check_box :authorization_type, { disabled: true, label: s_('ClusterIntegration|RBAC-enabled cluster'),
label_class: 'label-bold', inline: true }, 'rbac', 'abac'
......@@ -49,10 +45,14 @@
.form-group
= field.check_box :managed, { label: s_('ClusterIntegration|GitLab-managed cluster'),
class: 'js-gl-managed',
label_class: 'label-bold' }
.form-text.text-muted
= s_('ClusterIntegration|Allow GitLab to manage namespace and service accounts for this cluster.')
= link_to _('More information'), help_page_path('user/project/clusters/index.md', anchor: 'gitlab-managed-clusters'), target: '_blank'
- if cluster.allow_user_defined_namespace?
= render('clusters/clusters/namespace', platform_field: platform_field)
.form-group
= field.submit s_('ClusterIntegration|Save changes'), class: 'btn btn-success'
---
title: Update namespace label for GitLab-managed clusters
merge_request: 30935
author:
type: added
......@@ -2383,6 +2383,9 @@ msgstr ""
msgid "ClusterIntegration|Certificate Authority bundle (PEM format)"
msgstr ""
msgid "ClusterIntegration|Choose a prefix to be used for your namespaces. Defaults to your project path."
msgstr ""
msgid "ClusterIntegration|Choose which applications to install on your Kubernetes cluster. Helm Tiller is required to install any of the following applications."
msgstr ""
......@@ -2620,6 +2623,9 @@ msgstr ""
msgid "ClusterIntegration|Project namespace (optional, unique)"
msgstr ""
msgid "ClusterIntegration|Project namespace prefix (optional, unique)"
msgstr ""
msgid "ClusterIntegration|Prometheus"
msgstr ""
......@@ -2728,6 +2734,9 @@ msgstr ""
msgid "ClusterIntegration|The endpoint is in the process of being assigned. Please check your Kubernetes cluster or Quotas on Google Kubernetes Engine if it takes a long time."
msgstr ""
msgid "ClusterIntegration|The namespace associated with your project. This will be used for deploy boards, pod logs, and Web terminals."
msgstr ""
msgid "ClusterIntegration|There was a problem authenticating with your cluster. Please ensure your CA Certificate and Token are valid."
msgstr ""
......
import initGkeNamespace from '~/projects/gke_cluster_namespace';
describe('GKE cluster namespace', () => {
const changeEvent = new Event('change');
const isHidden = el => el.classList.contains('hidden');
const hasDisabledInput = el => el.querySelector('input').disabled;
let glManagedCheckbox;
let selfManaged;
let glManaged;
beforeEach(() => {
setFixtures(`
<input class="js-gl-managed" type="checkbox" value="1" checked />
<div class="js-namespace">
<input type="text" />
</div>
<div class="js-namespace-prefixed">
<input type="text" />
</div>
`);
glManagedCheckbox = document.querySelector('.js-gl-managed');
selfManaged = document.querySelector('.js-namespace');
glManaged = document.querySelector('.js-namespace-prefixed');
initGkeNamespace();
});
describe('GKE cluster namespace toggles', () => {
it('initially displays the GitLab-managed label and input', () => {
expect(isHidden(glManaged)).toEqual(false);
expect(hasDisabledInput(glManaged)).toEqual(false);
expect(isHidden(selfManaged)).toEqual(true);
expect(hasDisabledInput(selfManaged)).toEqual(true);
});
it('displays the self-managed label and input when the Gitlab-managed checkbox is unchecked', () => {
glManagedCheckbox.checked = false;
glManagedCheckbox.dispatchEvent(changeEvent);
expect(isHidden(glManaged)).toEqual(true);
expect(hasDisabledInput(glManaged)).toEqual(true);
expect(isHidden(selfManaged)).toEqual(false);
expect(hasDisabledInput(selfManaged)).toEqual(false);
});
it('displays the GitLab-managed label and input when the Gitlab-managed checkbox is checked', () => {
glManagedCheckbox.checked = true;
glManagedCheckbox.dispatchEvent(changeEvent);
expect(isHidden(glManaged)).toEqual(false);
expect(hasDisabledInput(glManaged)).toEqual(false);
expect(isHidden(selfManaged)).toEqual(true);
expect(hasDisabledInput(selfManaged)).toEqual(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