Commit 32c997ca authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab master

parents bbbf4b87 9477cff7
<script> <script>
import { GlButton, GlLoadingIcon, GlIcon, GlLink, GlBadge, GlSafeHtmlDirective } from '@gitlab/ui'; import { GlButton, GlLoadingIcon, GlLink, GlBadge, GlSafeHtmlDirective } from '@gitlab/ui';
import SmartVirtualList from '~/vue_shared/components/smart_virtual_list.vue'; import SmartVirtualList from '~/vue_shared/components/smart_virtual_list.vue';
import { EXTENSION_ICON_CLASS } from '../../constants'; import { EXTENSION_ICON_CLASS } from '../../constants';
import StatusIcon from './status_icon.vue'; import StatusIcon from './status_icon.vue';
...@@ -14,7 +14,6 @@ export default { ...@@ -14,7 +14,6 @@ export default {
components: { components: {
GlButton, GlButton,
GlLoadingIcon, GlLoadingIcon,
GlIcon,
GlLink, GlLink,
GlBadge, GlBadge,
SmartVirtualList, SmartVirtualList,
...@@ -139,9 +138,7 @@ export default { ...@@ -139,9 +138,7 @@ export default {
class="report-block-container" class="report-block-container"
> >
<li v-for="data in fullData" :key="data.id" class="d-flex align-items-center"> <li v-for="data in fullData" :key="data.id" class="d-flex align-items-center">
<div v-if="data.icon" :class="data.icon.class" class="d-flex"> <status-icon v-if="data.icon" :icon-name="data.icon.name" :size="12" />
<gl-icon :name="data.icon.name" :size="24" />
</div>
<div <div
class="gl-mt-2 gl-mb-2 align-content-around align-items-start flex-wrap align-self-center d-flex" class="gl-mt-2 gl-mb-2 align-content-around align-items-start flex-wrap align-self-center d-flex"
> >
......
<script> <script>
import { GlLoadingIcon, GlIcon } from '@gitlab/ui'; import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
import { capitalizeFirstCharacter } from '~/lib/utils/text_utility'; import { capitalizeFirstCharacter } from '~/lib/utils/text_utility';
import { EXTENSION_ICON_CLASS, EXTENSION_ICONS } from '../../constants'; import { EXTENSION_ICON_CLASS, EXTENSION_ICON_NAMES } from '../../constants';
export default { export default {
components: { components: {
...@@ -11,41 +11,48 @@ export default { ...@@ -11,41 +11,48 @@ export default {
props: { props: {
name: { name: {
type: String, type: String,
required: true, required: false,
default: '',
}, },
isLoading: { isLoading: {
type: Boolean, type: Boolean,
required: true, required: false,
default: false,
}, },
iconName: { iconName: {
type: String, type: String,
required: false, required: false,
default: null, default: null,
}, },
size: {
type: Number,
required: false,
default: 16,
},
}, },
computed: { computed: {
iconAriaLabel() { iconAriaLabel() {
const statusLabel = Object.keys(EXTENSION_ICONS).find( return `${capitalizeFirstCharacter(this.iconName)} ${this.name}`;
(k) => EXTENSION_ICONS[k] === this.iconName,
);
return `${capitalizeFirstCharacter(statusLabel)} ${this.name}`;
}, },
}, },
EXTENSION_ICON_NAMES,
EXTENSION_ICON_CLASS, EXTENSION_ICON_CLASS,
}; };
</script> </script>
<template> <template>
<div <div
:class="[$options.EXTENSION_ICON_CLASS[iconName], { 'mr-widget-extension-icon': !isLoading }]" :class="[
$options.EXTENSION_ICON_CLASS[iconName],
{ 'mr-widget-extension-icon': !isLoading && size === 16 },
]"
class="align-self-center gl-rounded-full gl-mr-3 gl-relative gl-p-2" class="align-self-center gl-rounded-full gl-mr-3 gl-relative gl-p-2"
> >
<gl-loading-icon v-if="isLoading" size="md" inline class="gl-display-block" /> <gl-loading-icon v-if="isLoading" size="md" inline class="gl-display-block" />
<gl-icon <gl-icon
v-else v-else
:name="iconName" :name="$options.EXTENSION_ICON_NAMES[iconName]"
:size="16" :size="size"
:aria-label="iconAriaLabel" :aria-label="iconAriaLabel"
class="gl-display-block" class="gl-display-block"
/> />
......
...@@ -93,17 +93,30 @@ export const stateToComponentMap = { ...@@ -93,17 +93,30 @@ export const stateToComponentMap = {
}; };
export const EXTENSION_ICONS = { export const EXTENSION_ICONS = {
failed: 'failed',
warning: 'warning',
success: 'success',
neutral: 'neutral',
error: 'error',
notice: 'notice',
};
export const EXTENSION_ICON_NAMES = {
failed: 'status-failed', failed: 'status-failed',
warning: 'status-alert', warning: 'status-alert',
success: 'status-success', success: 'status-success',
neutral: 'status-neutral', neutral: 'status-neutral',
error: 'status-alert',
notice: 'status-alert',
}; };
export const EXTENSION_ICON_CLASS = { export const EXTENSION_ICON_CLASS = {
[EXTENSION_ICONS.failed]: 'gl-text-red-500', failed: 'gl-text-red-500',
[EXTENSION_ICONS.warning]: 'gl-text-orange-500', warning: 'gl-text-orange-500',
[EXTENSION_ICONS.success]: 'gl-text-green-500', success: 'gl-text-green-500',
[EXTENSION_ICONS.neutral]: 'gl-text-gray-400', neutral: 'gl-text-gray-400',
error: 'gl-text-red-500',
notice: 'gl-text-gray-500',
}; };
export { STATE_MACHINE }; export { STATE_MACHINE };
...@@ -45,10 +45,7 @@ export default { ...@@ -45,10 +45,7 @@ export default {
// Icon to get rendered on the side of each row // Icon to get rendered on the side of each row
icon: { icon: {
// Required: Name maps to an icon in GitLabs SVG // Required: Name maps to an icon in GitLabs SVG
name: name: issue.state === 'closed' ? EXTENSION_ICONS.error : EXTENSION_ICONS.success,
issue.state === 'closed' ? 'status_failed_borderless' : 'status_success_borderless',
// Optional: An extra class to be added to the icon for additional styling
class: issue.state === 'closed' ? 'text-danger' : 'text-success',
}, },
// Badges get rendered next to the text on each row // Badges get rendered next to the text on each row
badge: issue.state === 'closed' && { badge: issue.state === 'closed' && {
......
...@@ -146,7 +146,7 @@ it('does not display a dropdown if no metricTypes exist', () => { ...@@ -146,7 +146,7 @@ it('does not display a dropdown if no metricTypes exist', () => {
}); });
``` ```
Keep an eye out for these kinds of tests, as they just make updating logic more fragile and tedious than it needs to be. This is also true for other libraries. A rule of thumb here is: if you are checking a `wrapper.vm` property, you should probably stop and rethink the test to check the rendered template instead. Keep an eye out for these kinds of tests, as they just make updating logic more fragile and tedious than it needs to be. This is also true for other libraries. A suggestion here is: if you are checking a `wrapper.vm` property, you should probably stop and rethink the test to check the rendered template instead.
Some more examples can be found in the [Frontend unit tests section](testing_levels.md#frontend-unit-tests) Some more examples can be found in the [Frontend unit tests section](testing_levels.md#frontend-unit-tests)
......
.badge.compliance-framework-pill { .badge.compliance-framework-pill {
border-radius: $label-border-radius; border-radius: $label-border-radius;
color: $gray-light;
display: inline-block; display: inline-block;
font-size: $gl-font-size-sm; font-size: $gl-font-size-sm;
font-weight: $gl-font-weight-normal; font-weight: $gl-font-weight-normal;
......
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
- if show_compliance_framework_badge?(project) - if show_compliance_framework_badge?(project)
- framework = project.compliance_framework_setting.compliance_management_framework - framework = project.compliance_framework_setting.compliance_management_framework
%span.badge.compliance-framework-pill.ml-2.has-tooltip{ style: "background-color: #{framework.color}", data: { container: 'body' }, title: framework.description } %span.badge.compliance-framework-pill.ml-2.has-tooltip{ style: "background-color: #{framework.color}", class: text_color_class_for_bg(framework.color), data: { container: 'body' }, title: framework.description }
= framework.name = framework.name
...@@ -16,20 +16,20 @@ describe('MR widget extensions status icon', () => { ...@@ -16,20 +16,20 @@ describe('MR widget extensions status icon', () => {
}); });
it('renders loading icon', () => { it('renders loading icon', () => {
factory({ name: 'test', isLoading: true, iconName: 'status-failed' }); factory({ name: 'test', isLoading: true, iconName: 'failed' });
expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true); expect(wrapper.findComponent(GlLoadingIcon).exists()).toBe(true);
}); });
it('renders status icon', () => { it('renders status icon', () => {
factory({ name: 'test', isLoading: false, iconName: 'status-failed' }); factory({ name: 'test', isLoading: false, iconName: 'failed' });
expect(wrapper.findComponent(GlIcon).exists()).toBe(true); expect(wrapper.findComponent(GlIcon).exists()).toBe(true);
expect(wrapper.findComponent(GlIcon).props('name')).toBe('status-failed'); expect(wrapper.findComponent(GlIcon).props('name')).toBe('status-failed');
}); });
it('sets aria-label for status icon', () => { it('sets aria-label for status icon', () => {
factory({ name: 'test', isLoading: false, iconName: 'status-failed' }); factory({ name: 'test', isLoading: false, iconName: 'failed' });
expect(wrapper.findComponent(GlIcon).props('ariaLabel')).toBe('Failed test'); expect(wrapper.findComponent(GlIcon).props('ariaLabel')).toBe('Failed test');
}); });
......
...@@ -919,7 +919,7 @@ describe('MrWidgetOptions', () => { ...@@ -919,7 +919,7 @@ describe('MrWidgetOptions', () => {
// Renders icon in the row // Renders icon in the row
expect(collapsedSection.find(GlIcon).exists()).toBe(true); expect(collapsedSection.find(GlIcon).exists()).toBe(true);
expect(collapsedSection.find(GlIcon).props('name')).toBe('status_failed_borderless'); expect(collapsedSection.find(GlIcon).props('name')).toBe('status-failed');
// Renders badge in the row // Renders badge in the row
expect(collapsedSection.find(GlBadge).exists()).toBe(true); expect(collapsedSection.find(GlBadge).exists()).toBe(true);
......
...@@ -21,8 +21,7 @@ export default { ...@@ -21,8 +21,7 @@ export default {
id: 1, id: 1,
text: 'Hello world', text: 'Hello world',
icon: { icon: {
name: 'status_failed_borderless', name: EXTENSION_ICONS.failed,
class: 'text-danger',
}, },
badge: { badge: {
text: 'Closed', text: 'Closed',
......
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