Commit ca451cb7 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch 'cngo-add-gl-toggle-labels' into 'master'

Add labels to UI toggles

See merge request gitlab-org/gitlab!56848
parents c1757f06 1eb11771
<script> <script>
import { GlToggle } from '@gitlab/ui'; import { GlToggle } from '@gitlab/ui';
import AccessorUtilities from '~/lib/utils/accessor'; import AccessorUtilities from '~/lib/utils/accessor';
import { __ } from '~/locale';
import { disableShortcuts, enableShortcuts, shouldDisableShortcuts } from './shortcuts_toggle'; import { disableShortcuts, enableShortcuts, shouldDisableShortcuts } from './shortcuts_toggle';
export default { export default {
i18n: {
toggleLabel: __('Keyboard shortcuts'),
},
components: { components: {
GlToggle, GlToggle,
}, },
...@@ -31,7 +35,7 @@ export default { ...@@ -31,7 +35,7 @@ export default {
<gl-toggle <gl-toggle
v-model="shortcutsEnabled" v-model="shortcutsEnabled"
aria-describedby="shortcutsToggle" aria-describedby="shortcutsToggle"
label="Keyboard shortcuts" :label="$options.i18n.toggleLabel"
label-position="left" label-position="left"
@change="onChange" @change="onChange"
/> />
......
...@@ -29,6 +29,9 @@ import EnvironmentsDropdown from './environments_dropdown.vue'; ...@@ -29,6 +29,9 @@ import EnvironmentsDropdown from './environments_dropdown.vue';
import Strategy from './strategy.vue'; import Strategy from './strategy.vue';
export default { export default {
i18n: {
statusLabel: s__('FeatureFlags|Status'),
},
components: { components: {
GlButton, GlButton,
GlBadge, GlBadge,
...@@ -396,12 +399,14 @@ export default { ...@@ -396,12 +399,14 @@ export default {
<div class="table-section section-20 text-center" role="gridcell"> <div class="table-section section-20 text-center" role="gridcell">
<div class="table-mobile-header" role="rowheader"> <div class="table-mobile-header" role="rowheader">
{{ s__('FeatureFlags|Status') }} {{ $options.i18n.statusLabel }}
</div> </div>
<div class="table-mobile-content gl-display-flex gl-justify-content-center"> <div class="table-mobile-content gl-display-flex gl-justify-content-center">
<gl-toggle <gl-toggle
:value="scope.active" :value="scope.active"
:disabled="!active || !canUpdateScope(scope)" :disabled="!active || !canUpdateScope(scope)"
:label="$options.i18n.statusLabel"
label-position="hidden"
@change="(status) => (scope.active = status)" @change="(status) => (scope.active = status)"
/> />
</div> </div>
...@@ -529,11 +534,13 @@ export default { ...@@ -529,11 +534,13 @@ export default {
<div class="table-section section-20 text-center" role="gridcell"> <div class="table-section section-20 text-center" role="gridcell">
<div class="table-mobile-header" role="rowheader"> <div class="table-mobile-header" role="rowheader">
{{ s__('FeatureFlags|Status') }} {{ $options.i18n.statusLabel }}
</div> </div>
<div class="table-mobile-content gl-display-flex gl-justify-content-center"> <div class="table-mobile-content gl-display-flex gl-justify-content-center">
<gl-toggle <gl-toggle
:disabled="!active" :disabled="!active"
:label="$options.i18n.statusLabel"
label-position="hidden"
:value="false" :value="false"
@change="createNewScope({ active: true })" @change="createNewScope({ active: true })"
/> />
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
import { GlSprintf, GlToggle, GlFormGroup, GlFormInput } from '@gitlab/ui'; import { GlSprintf, GlToggle, GlFormGroup, GlFormInput } from '@gitlab/ui';
import { import {
MAVEN_TOGGLE_LABEL,
MAVEN_TITLE, MAVEN_TITLE,
MAVEN_SETTINGS_SUBTITLE, MAVEN_SETTINGS_SUBTITLE,
MAVEN_DUPLICATES_ALLOWED_DISABLED, MAVEN_DUPLICATES_ALLOWED_DISABLED,
...@@ -15,6 +16,7 @@ import { ...@@ -15,6 +16,7 @@ import {
export default { export default {
name: 'MavenSettings', name: 'MavenSettings',
i18n: { i18n: {
MAVEN_TOGGLE_LABEL,
MAVEN_TITLE, MAVEN_TITLE,
MAVEN_SETTINGS_SUBTITLE, MAVEN_SETTINGS_SUBTITLE,
MAVEN_SETTING_EXCEPTION_TITLE, MAVEN_SETTING_EXCEPTION_TITLE,
...@@ -80,6 +82,8 @@ export default { ...@@ -80,6 +82,8 @@ export default {
<div class="gl-display-flex"> <div class="gl-display-flex">
<gl-toggle <gl-toggle
data-qa-selector="allow_duplicates_toggle" data-qa-selector="allow_duplicates_toggle"
:label="$options.i18n.MAVEN_TOGGLE_LABEL"
label-position="hidden"
:value="mavenDuplicatesAllowed" :value="mavenDuplicatesAllowed"
@change="update($options.modelNames.MAVEN_DUPLICATES_ALLOWED, $event)" @change="update($options.modelNames.MAVEN_DUPLICATES_ALLOWED, $event)"
/> />
......
...@@ -8,6 +8,7 @@ export const PACKAGE_SETTINGS_DESCRIPTION = s__( ...@@ -8,6 +8,7 @@ export const PACKAGE_SETTINGS_DESCRIPTION = s__(
export const MAVEN_TITLE = s__('PackageRegistry|Maven'); export const MAVEN_TITLE = s__('PackageRegistry|Maven');
export const MAVEN_SETTINGS_SUBTITLE = s__('PackageRegistry|Settings for Maven packages'); export const MAVEN_SETTINGS_SUBTITLE = s__('PackageRegistry|Settings for Maven packages');
export const MAVEN_TOGGLE_LABEL = s__('PackageRegistry|Allow duplicates');
export const MAVEN_DUPLICATES_ALLOWED_DISABLED = s__( export const MAVEN_DUPLICATES_ALLOWED_DISABLED = s__(
'PackageRegistry|%{boldStart}Do not allow duplicates%{boldEnd} - Packages with the same name and version are rejected.', 'PackageRegistry|%{boldStart}Do not allow duplicates%{boldEnd} - Packages with the same name and version are rejected.',
); );
......
...@@ -12,6 +12,11 @@ export default { ...@@ -12,6 +12,11 @@ export default {
event: 'change', event: 'change',
}, },
props: { props: {
label: {
type: String,
required: false,
default: '',
},
name: { name: {
type: String, type: String,
required: false, required: false,
...@@ -82,6 +87,8 @@ export default { ...@@ -82,6 +87,8 @@ export default {
class="gl-mr-3" class="gl-mr-3"
:value="featureEnabled" :value="featureEnabled"
:disabled="disabledInput" :disabled="disabledInput"
:label="label"
label-position="hidden"
@change="toggleFeature" @change="toggleFeature"
/> />
<div class="select-wrapper gl-flex-fill-1"> <div class="select-wrapper gl-flex-fill-1">
......
---
title: Add labels to UI toggles
merge_request: 56848
author:
type: fixed
...@@ -129,7 +129,7 @@ export default { ...@@ -129,7 +129,7 @@ export default {
target="_blank" target="_blank"
class="gl-display-flex gl-align-items-center gl-ml-2 gl-text-gray-500" class="gl-display-flex gl-align-items-center gl-ml-2 gl-text-gray-500"
> >
<gl-icon name="question" :size="12" role="text" /> <gl-icon name="question" :size="12" />
</gl-link> </gl-link>
<span <span
class="gl-display-inline-flex gl-align-items-center gl-ml-4" class="gl-display-inline-flex gl-align-items-center gl-ml-4"
......
...@@ -21798,6 +21798,9 @@ msgstr "" ...@@ -21798,6 +21798,9 @@ msgstr ""
msgid "PackageRegistry|Add composer registry" msgid "PackageRegistry|Add composer registry"
msgstr "" msgstr ""
msgid "PackageRegistry|Allow duplicates"
msgstr ""
msgid "PackageRegistry|An error occurred while saving the settings" msgid "PackageRegistry|An error occurred while saving the settings"
msgstr "" msgstr ""
......
...@@ -123,6 +123,10 @@ describe('feature flag form', () => { ...@@ -123,6 +123,10 @@ describe('feature flag form', () => {
}); });
}); });
it('has label', () => {
expect(findGlToggle().props('label')).toBe(Form.i18n.statusLabel);
});
it('should be disabled if the feature flag is not active', (done) => { it('should be disabled if the feature flag is not active', (done) => {
wrapper.setProps({ active: false }); wrapper.setProps({ active: false });
wrapper.vm.$nextTick(() => { wrapper.vm.$nextTick(() => {
......
...@@ -59,7 +59,10 @@ describe('Maven Settings', () => { ...@@ -59,7 +59,10 @@ describe('Maven Settings', () => {
mountComponent(); mountComponent();
expect(findToggle().exists()).toBe(true); expect(findToggle().exists()).toBe(true);
expect(findToggle().props('value')).toBe(defaultProps.mavenDuplicatesAllowed); expect(findToggle().props()).toMatchObject({
label: component.i18n.MAVEN_TOGGLE_LABEL,
value: defaultProps.mavenDuplicatesAllowed,
});
}); });
it('toggle emits an update event', () => { it('toggle emits an update event', () => {
......
...@@ -46,6 +46,7 @@ const defaultProps = { ...@@ -46,6 +46,7 @@ const defaultProps = {
pagesHelpPath: '/help/user/project/pages/introduction#gitlab-pages-access-control', pagesHelpPath: '/help/user/project/pages/introduction#gitlab-pages-access-control',
packagesAvailable: false, packagesAvailable: false,
packagesHelpPath: '/help/user/packages/index', packagesHelpPath: '/help/user/packages/index',
requestCveAvailable: true,
}; };
describe('Settings Panel', () => { describe('Settings Panel', () => {
...@@ -76,6 +77,7 @@ describe('Settings Panel', () => { ...@@ -76,6 +77,7 @@ describe('Settings Panel', () => {
const findRepositoryFeatureSetting = () => const findRepositoryFeatureSetting = () =>
findRepositoryFeatureProjectRow().find(projectFeatureSetting); findRepositoryFeatureProjectRow().find(projectFeatureSetting);
const findProjectVisibilitySettings = () => wrapper.find({ ref: 'project-visibility-settings' }); const findProjectVisibilitySettings = () => wrapper.find({ ref: 'project-visibility-settings' });
const findIssuesSettingsRow = () => wrapper.find({ ref: 'issues-settings' });
const findAnalyticsRow = () => wrapper.find({ ref: 'analytics-settings' }); const findAnalyticsRow = () => wrapper.find({ ref: 'analytics-settings' });
const findProjectVisibilityLevelInput = () => wrapper.find('[name="project[visibility_level]"]'); const findProjectVisibilityLevelInput = () => wrapper.find('[name="project[visibility_level]"]');
const findRequestAccessEnabledInput = () => const findRequestAccessEnabledInput = () =>
...@@ -174,6 +176,16 @@ describe('Settings Panel', () => { ...@@ -174,6 +176,16 @@ describe('Settings Panel', () => {
}); });
}); });
describe('Issues settings', () => {
it('has label for CVE request toggle', () => {
wrapper = mountComponent();
expect(findIssuesSettingsRow().findComponent(GlToggle).props('label')).toBe(
settingsPanel.i18n.cve_request_toggle_label,
);
});
});
describe('Repository', () => { describe('Repository', () => {
it('should set the repository help text when the visibility level is set to private', () => { it('should set the repository help text when the visibility level is set to private', () => {
wrapper = mountComponent({ currentSettings: { visibilityLevel: visibilityOptions.PRIVATE } }); wrapper = mountComponent({ currentSettings: { visibilityLevel: visibilityOptions.PRIVATE } });
...@@ -304,6 +316,17 @@ describe('Settings Panel', () => { ...@@ -304,6 +316,17 @@ describe('Settings Panel', () => {
expect(findContainerRegistryEnabledInput().props('disabled')).toBe(true); expect(findContainerRegistryEnabledInput().props('disabled')).toBe(true);
}); });
it('has label for the toggle', () => {
wrapper = mountComponent({
currentSettings: { visibilityLevel: visibilityOptions.PUBLIC },
registryAvailable: true,
});
expect(findContainerRegistrySettings().findComponent(GlToggle).props('label')).toBe(
settingsPanel.i18n.containerRegistryLabel,
);
});
}); });
describe('Git Large File Storage', () => { describe('Git Large File Storage', () => {
...@@ -342,6 +365,15 @@ describe('Settings Panel', () => { ...@@ -342,6 +365,15 @@ describe('Settings Panel', () => {
expect(findLFSFeatureToggle().props('disabled')).toBe(true); expect(findLFSFeatureToggle().props('disabled')).toBe(true);
}); });
it('has label for toggle', () => {
wrapper = mountComponent({
currentSettings: { repositoryAccessLevel: featureAccessLevel.EVERYONE },
lfsAvailable: true,
});
expect(findLFSFeatureToggle().props('label')).toBe(settingsPanel.i18n.lfsLabel);
});
it('should not change lfsEnabled when disabling the repository', async () => { it('should not change lfsEnabled when disabling the repository', async () => {
// mount over shallowMount, because we are aiming to test rendered state of toggle // mount over shallowMount, because we are aiming to test rendered state of toggle
wrapper = mountComponent({ currentSettings: { lfsEnabled: true } }, mount); wrapper = mountComponent({ currentSettings: { lfsEnabled: true } }, mount);
...@@ -432,6 +464,17 @@ describe('Settings Panel', () => { ...@@ -432,6 +464,17 @@ describe('Settings Panel', () => {
expect(findPackagesEnabledInput().props('disabled')).toBe(true); expect(findPackagesEnabledInput().props('disabled')).toBe(true);
}); });
it('has label for toggle', () => {
wrapper = mountComponent({
currentSettings: { repositoryAccessLevel: featureAccessLevel.EVERYONE },
packagesAvailable: true,
});
expect(findPackagesEnabledInput().findComponent(GlToggle).props('label')).toBe(
settingsPanel.i18n.packagesLabel,
);
});
}); });
describe('Pages', () => { describe('Pages', () => {
......
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