Commit d1513896 authored by Taurie Davis's avatar Taurie Davis Committed by Brandon Labuschagne

Migrate health status dropdown to use gitlab ui

Updates FE by using constant and reference from $options
parent 3cce9517
<script> <script>
import { import { GlDropdownItem, GlDropdown, GlDropdownDivider } from '@gitlab/ui';
GlButton, import { healthStatusTextMap, I18N_DROPDOWN } from '../../constants';
GlDeprecatedDropdownItem,
GlDeprecatedDropdown,
GlDeprecatedDropdownDivider,
} from '@gitlab/ui';
import { s__ } from '~/locale';
import { healthStatusTextMap } from '../../constants';
export default { export default {
components: { components: {
GlButton, GlDropdown,
GlDeprecatedDropdown, GlDropdownItem,
GlDeprecatedDropdownItem, GlDropdownDivider,
GlDeprecatedDropdownDivider,
}, },
props: { props: {
isEditable: { isEditable: {
...@@ -44,23 +37,16 @@ export default { ...@@ -44,23 +37,16 @@ export default {
}, },
computed: { computed: {
statusText() { statusText() {
return this.status ? healthStatusTextMap[this.status] : s__('Sidebar|None'); return this.status ? healthStatusTextMap[this.status] : this.$options.i18n.noneText;
}, },
dropdownText() { dropdownText() {
if (this.status === null) { if (this.status === null) {
return s__('No status'); return this.$options.i18n.noStatusText;
} }
return this.status ? healthStatusTextMap[this.status] : s__('Select health status'); return this.status
}, ? healthStatusTextMap[this.status]
tooltipText() { : this.$options.i18n.selectPlaceholderText;
let tooltipText = s__('Sidebar|Health status');
if (this.status) {
tooltipText += `: ${this.statusText}`;
}
return tooltipText;
}, },
}, },
watch: { watch: {
...@@ -81,56 +67,40 @@ export default { ...@@ -81,56 +67,40 @@ export default {
return this.status === status; return this.status === status;
}, },
}, },
i18n: I18N_DROPDOWN,
}; };
</script> </script>
<template> <template>
<div class="dropdown dropdown-menu-selectable"> <div class="dropdown">
<gl-deprecated-dropdown <gl-dropdown
ref="dropdown" ref="dropdown"
class="w-100" class="gl-w-full"
:header-text="$options.i18n.dropdownHeaderText"
:text="dropdownText" :text="dropdownText"
@keydown.esc.native="hideDropdown" @keydown.esc.native="hideDropdown"
@hide="hideDropdown" @hide="hideDropdown"
> >
<div class="dropdown-title gl-display-flex"> <gl-dropdown-item
<span class="health-title gl-ml-auto">{{ s__('Sidebar|Assign health status') }}</span> :is-check-item="true"
<gl-button :is-checked="isSelected(null)"
:aria-label="__('Close')" @click="handleDropdownClick(null)"
variant="link"
class="dropdown-title-button dropdown-menu-close gl-ml-auto gl-text-gray-200!"
icon="close"
@click="hideDropdown"
/>
</div>
<div class="dropdown-content dropdown-body">
<gl-deprecated-dropdown-item @click="handleDropdownClick(null)">
<gl-button
variant="link"
class="dropdown-item health-dropdown-item"
:class="{ 'is-active': isSelected(null) }"
> >
{{ s__('Sidebar|No status') }} {{ $options.i18n.noStatusText }}
</gl-button> </gl-dropdown-item>
</gl-deprecated-dropdown-item>
<gl-deprecated-dropdown-divider class="divider health-divider" /> <gl-dropdown-divider />
<gl-deprecated-dropdown-item <gl-dropdown-item
v-for="option in statusOptions" v-for="option in statusOptions"
:key="option.key" :key="option.key"
:is-check-item="true"
:is-checked="isSelected(option.key)"
data-testid="health-status-dropdown-item"
@click="handleDropdownClick(option.key)" @click="handleDropdownClick(option.key)"
>
<gl-button
variant="link"
class="dropdown-item health-dropdown-item"
:class="{ 'is-active': isSelected(option.key) }"
> >
{{ option.value }} {{ option.value }}
</gl-button> </gl-dropdown-item>
</gl-deprecated-dropdown-item> </gl-dropdown>
</div>
</gl-deprecated-dropdown>
</div> </div>
</template> </template>
...@@ -10,7 +10,7 @@ import { ...@@ -10,7 +10,7 @@ import {
} from '@gitlab/ui'; } from '@gitlab/ui';
import Tracking from '~/tracking'; import Tracking from '~/tracking';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { healthStatusTextMap } from '../../constants'; import { healthStatusTextMap, I18N_DROPDOWN } from '../../constants';
export default { export default {
directives: { directives: {
...@@ -62,10 +62,12 @@ export default { ...@@ -62,10 +62,12 @@ export default {
return this.isEditable && this.status; return this.isEditable && this.status;
}, },
statusText() { statusText() {
return this.status ? healthStatusTextMap[this.status] : s__('Sidebar|None'); return this.status ? healthStatusTextMap[this.status] : this.$options.i18n.noneText;
}, },
dropdownText() { dropdownText() {
return this.status ? healthStatusTextMap[this.status] : s__('Select health status'); return this.status
? healthStatusTextMap[this.status]
: this.$options.i18n.selectPlaceholderText;
}, },
statusTooltip() { statusTooltip() {
let tooltipText = s__('Sidebar|Health status'); let tooltipText = s__('Sidebar|Health status');
...@@ -137,6 +139,7 @@ export default { ...@@ -137,6 +139,7 @@ export default {
} }
}, },
}, },
i18n: I18N_DROPDOWN,
}; };
</script> </script>
...@@ -173,61 +176,43 @@ export default { ...@@ -173,61 +176,43 @@ export default {
<div <div
data-testid="dropdownWrapper" data-testid="dropdownWrapper"
class="dropdown dropdown-menu-selectable" class="dropdown"
:class="{ show: isDropdownShowing, 'gl-display-none': !isDropdownShowing }" :class="{ show: isDropdownShowing, 'gl-display-none': !isDropdownShowing }"
> >
<gl-dropdown <gl-dropdown
ref="dropdown" ref="dropdown"
class="gl-w-full" class="gl-w-full"
:header-text="$options.i18n.dropdownHeaderText"
:text="dropdownText" :text="dropdownText"
@keydown.esc.native="hideDropdown" @keydown.esc.native="hideDropdown"
@hide="hideDropdown" @hide="hideDropdown"
> >
<div class="dropdown-title gl-display-flex"> <gl-dropdown-item
<span class="health-title gl-ml-auto">{{ s__('Sidebar|Assign health status') }}</span> :is-check-item="true"
<gl-button :is-checked="isSelected(null)"
:aria-label="__('Close')" @click="handleDropdownClick(null)"
variant="link"
class="dropdown-title-button dropdown-menu-close gl-ml-auto gl-text-gray-200!"
icon="close"
@click="hideDropdown"
/>
</div>
<div class="dropdown-content dropdown-body">
<gl-dropdown-item @click="handleDropdownClick(null)">
<gl-button
variant="link"
class="dropdown-item health-dropdown-item gl-px-8!"
:class="{ 'is-active': isSelected(null) }"
> >
{{ s__('Sidebar|No status') }} {{ $options.i18n.noStatusText }}
</gl-button>
</gl-dropdown-item> </gl-dropdown-item>
<gl-dropdown-divider class="divider health-divider" /> <gl-dropdown-divider />
<gl-dropdown-item <gl-dropdown-item
v-for="option in statusOptions" v-for="option in statusOptions"
:key="option.key" :key="option.key"
:is-check-item="true"
:is-checked="isSelected(option.key)"
@click="handleDropdownClick(option.key)" @click="handleDropdownClick(option.key)"
>
<gl-button
variant="link"
class="dropdown-item health-dropdown-item gl-px-8!"
:class="{ 'is-active': isSelected(option.key) }"
> >
{{ option.value }} {{ option.value }}
</gl-button>
</gl-dropdown-item> </gl-dropdown-item>
</div>
</gl-dropdown> </gl-dropdown>
</div> </div>
<gl-loading-icon v-if="isFetching" :inline="true" /> <gl-loading-icon v-if="isFetching" :inline="true" />
<p v-else-if="!isDropdownShowing" class="value gl-m-0" :class="{ 'no-value': !status }"> <p v-else-if="!isDropdownShowing" class="value gl-m-0" :class="{ 'no-value': !status }">
<span v-if="status" class="text-plain gl-font-weight-bold">{{ statusText }}</span> <span v-if="status" class="text-plain gl-font-weight-bold">{{ statusText }}</span>
<span v-else>{{ __('None') }}</span> <span v-else>{{ $options.i18n.noneText }}</span>
</p> </p>
</div> </div>
</div> </div>
......
import { __ } from '~/locale'; import { s__, __ } from '~/locale';
export const healthStatus = { export const healthStatus = {
ON_TRACK: 'onTrack', ON_TRACK: 'onTrack',
...@@ -29,3 +29,10 @@ export const healthStatusForRestApi = { ...@@ -29,3 +29,10 @@ export const healthStatusForRestApi = {
}; };
export const MAX_DISPLAY_WEIGHT = 99999; export const MAX_DISPLAY_WEIGHT = 99999;
export const I18N_DROPDOWN = {
dropdownHeaderText: s__('Sidebar|Assign health status'),
noStatusText: s__('Sidebar|No status'),
noneText: s__('Sidebar|None'),
selectPlaceholderText: s__('Select health status'),
};
---
title: Migrate health status dropdown to use gitlab ui
merge_request: 52273
author:
type: changed
...@@ -113,7 +113,7 @@ RSpec.describe 'Issues > Health status bulk assignment' do ...@@ -113,7 +113,7 @@ RSpec.describe 'Issues > Health status bulk assignment' do
page.within('.issues-bulk-update') do page.within('.issues-bulk-update') do
click_button 'Select health status' click_button 'Select health status'
items.map do |item| items.map do |item|
find('.gl-button-text', text: item).click find('[data-testid="health-status-dropdown-item"]', text: item).click
end end
end end
end end
......
import { GlDropdown, GlDropdownItem, GlLoadingIcon } from '@gitlab/ui'; import { GlDropdown, GlDropdownItem, GlLoadingIcon } from '@gitlab/ui';
import { mount, shallowMount } from '@vue/test-utils'; import { mount, shallowMount } from '@vue/test-utils';
import Status from 'ee/sidebar/components/status/status.vue'; import Status from 'ee/sidebar/components/status/status.vue';
import { healthStatus, healthStatusTextMap } from 'ee/sidebar/constants'; import { healthStatus, healthStatusTextMap, I18N_DROPDOWN } from 'ee/sidebar/constants';
import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive';
const getStatusText = (wrapper) => wrapper.find('.value .text-plain').text(); const getStatusText = (wrapper) => wrapper.find('.value .text-plain').text();
...@@ -182,7 +182,7 @@ describe('Status', () => { ...@@ -182,7 +182,7 @@ describe('Status', () => {
}); });
it('shows "None"', () => { it('shows "None"', () => {
expect(wrapper.find('.no-value').text()).toBe('None'); expect(wrapper.find('.no-value').text()).toBe(I18N_DROPDOWN.noneText);
}); });
it('shows "Status" in the tooltip', () => { it('shows "Status" in the tooltip', () => {
...@@ -258,9 +258,9 @@ describe('Status', () => { ...@@ -258,9 +258,9 @@ describe('Status', () => {
}); });
it('shows text to ask the user to pick an option', () => { it('shows text to ask the user to pick an option', () => {
const message = 'Assign health status'; expect(getDropdownElement(wrapper).props('headerText')).toBe(
I18N_DROPDOWN.dropdownHeaderText,
expect(getDropdownElement(wrapper).find('.health-title').text()).toContain(message); );
}); });
it('hides form when the `edit` button is clicked', async () => { it('hides form when the `edit` button is clicked', async () => {
......
...@@ -19516,9 +19516,6 @@ msgstr "" ...@@ -19516,9 +19516,6 @@ msgstr ""
msgid "No start date" msgid "No start date"
msgstr "" msgstr ""
msgid "No status"
msgstr ""
msgid "No template" msgid "No template"
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