Commit 66e03dc9 authored by Brandon Labuschagne's avatar Brandon Labuschagne Committed by Fatih Acet

Refactor group authentication checkox into toggle

Replace the checkob input with a toggle button by making use of the
toggle_button class.
parent 37bf7ba2
...@@ -5,7 +5,9 @@ export default class DirtyFormChecker { ...@@ -5,7 +5,9 @@ export default class DirtyFormChecker {
this.isDirty = false; this.isDirty = false;
this.editableInputs = Array.from(this.form.querySelectorAll('input[name]')).filter( this.editableInputs = Array.from(this.form.querySelectorAll('input[name]')).filter(
el => el.type !== 'submit' && el.type !== 'hidden', el =>
(el.type !== 'submit' && el.type !== 'hidden') ||
el.classList.contains('js-project-feature-toggle-input'),
); );
this.startingStates = {}; this.startingStates = {};
......
import $ from 'jquery'; import $ from 'jquery';
import { __ } from '~/locale'; import { __ } from '~/locale';
import DirtyFormChecker from './dirty_form_checker'; import DirtyFormChecker from './dirty_form_checker';
import setupToggleButtons from '~/toggle_buttons';
import { parseBoolean } from '~/lib/utils/common_utils';
export default class SamlSettingsForm { export default class SamlSettingsForm {
constructor(formSelector) { constructor(formSelector) {
this.form = document.querySelector(formSelector); this.form = document.querySelector(formSelector);
this.samlToggleArea = this.form.querySelector('.js-group-saml-enable-toggle-area');
this.enabledToggle = this.form.querySelector('#saml_provider_enabled'); this.enabledToggle = this.form.querySelector('#saml_provider_enabled');
this.testButtonTooltipWrapper = this.form.querySelector('#js-saml-test-button'); this.testButtonTooltipWrapper = this.form.querySelector('#js-saml-test-button');
this.testButton = this.testButtonTooltipWrapper.querySelector('a'); this.testButton = this.testButtonTooltipWrapper.querySelector('a');
...@@ -13,10 +16,12 @@ export default class SamlSettingsForm { ...@@ -13,10 +16,12 @@ export default class SamlSettingsForm {
init() { init() {
this.dirtyFormChecker.init(); this.dirtyFormChecker.init();
setupToggleButtons(this.samlToggleArea);
$(this.enabledToggle).on('trigger-change', () => this.onEnableToggle());
this.updateEnabled(); this.updateEnabled();
this.updateView(); this.updateView();
this.enabledToggle.addEventListener('change', () => this.onEnableToggle());
} }
onEnableToggle() { onEnableToggle() {
...@@ -25,7 +30,7 @@ export default class SamlSettingsForm { ...@@ -25,7 +30,7 @@ export default class SamlSettingsForm {
} }
updateEnabled() { updateEnabled() {
this.enabled = this.enabledToggle.checked; this.enabled = parseBoolean(this.enabledToggle.value);
} }
testButtonTooltip() { testButtonTooltip() {
......
%section.saml_provider#js-saml-settings-form %section.saml_provider#js-saml-settings-form
= form_for [group, saml_provider], url: group_saml_providers_path do |f| = form_for [group, saml_provider], url: group_saml_providers_path do |f|
.form-group.row .form-group
= form_errors(saml_provider) = form_errors(saml_provider)
= f.label :enabled, _("Enabled"), class: 'col-form-label col-sm-2' .js-group-saml-enable-toggle-area
.col-sm-10 %button{ type: 'button',
.form-check class: "js-project-feature-toggle project-feature-toggle d-inline #{'is-checked' if saml_provider.enabled?}",
= f.check_box :enabled, class: 'form-check-input' "aria-label": s_("GroupSAML|Toggle SAML authentication") }
= f.label :enabled, class: 'form-check-label' do = f.hidden_field :enabled, { class: 'js-project-feature-toggle-input'}
= _("Enable SAML authentication for this group") %span.toggle-icon
= sprite_icon('status_success_borderless', size: 16, css_class: 'toggle-icon-svg toggle-status-checked')
= sprite_icon('status_failed_borderless', size: 16, css_class: 'toggle-icon-svg toggle-status-unchecked')
.form-text.d-inline.ml-3.align-text-bottom= s_('GroupSAML|Enable SAML authentication for this group')
- if Feature.enabled?(:enforced_sso, group) - if Feature.enabled?(:enforced_sso, group)
.form-group.row .form-group.row
= f.label :enforced_sso, _("Enforced SSO"), class: 'col-form-label col-sm-2' = f.label :enforced_sso, _("Enforced SSO"), class: 'col-form-label col-sm-2'
......
- if saml_provider.persisted? = saml_link_for_provider _('Test SAML SSO'), saml_provider, redirect: request.url, html_class: "btn qa-saml-settings-test-button #{ 'd-none' unless saml_provider.persisted? }"
= saml_link_for_provider _('Test SAML SSO'), saml_provider, redirect: request.url, html_class: 'btn qa-saml-settings-test-button'
---
title: Convert enable group authentication checkbox to toggle button
merge_request: 9816
author:
type: changed
...@@ -79,10 +79,10 @@ describe 'SAML provider settings' do ...@@ -79,10 +79,10 @@ describe 'SAML provider settings' do
context 'with existing SAML provider' do context 'with existing SAML provider' do
let!(:saml_provider) { create(:saml_provider, group: group) } let!(:saml_provider) { create(:saml_provider, group: group) }
it 'allows provider to be disabled' do it 'allows provider to be disabled', :js do
visit group_saml_providers_path(group) visit group_saml_providers_path(group)
find('input#saml_provider_enabled').click find('.js-group-saml-enable-toggle-area button').click
expect { submit }.to change { saml_provider.reload.enabled }.to false expect { submit }.to change { saml_provider.reload.enabled }.to false
end end
......
...@@ -25,7 +25,7 @@ describe('DirtyFormChecker', () => { ...@@ -25,7 +25,7 @@ describe('DirtyFormChecker', () => {
it('tracks starting states for editable inputs', () => { it('tracks starting states for editable inputs', () => {
const enabledStartState = dirtyFormChecker.startingStates['saml_provider[enabled]']; const enabledStartState = dirtyFormChecker.startingStates['saml_provider[enabled]'];
expect(enabledStartState).toEqual('1'); expect(enabledStartState).toEqual('true');
}); });
}); });
......
...@@ -5184,6 +5184,12 @@ msgstr "" ...@@ -5184,6 +5184,12 @@ msgstr ""
msgid "GroupRoadmap|Until %{dateWord}" msgid "GroupRoadmap|Until %{dateWord}"
msgstr "" msgstr ""
msgid "GroupSAML|Enable SAML authentication for this group"
msgstr ""
msgid "GroupSAML|Toggle SAML authentication"
msgstr ""
msgid "GroupSettings|Auto DevOps pipeline was updated for the group" msgid "GroupSettings|Auto DevOps pipeline was updated for the group"
msgstr "" msgstr ""
......
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