Commit 9adb7fe9 authored by Alexander Turinske's avatar Alexander Turinske

Simplify dynamic count text

- create computed property for it
- update tests
parent ccb9310a
...@@ -6,10 +6,9 @@ import { ...@@ -6,10 +6,9 @@ import {
GlFormGroup, GlFormGroup,
GlIcon, GlIcon,
GlSearchBoxByType, GlSearchBoxByType,
GlSprintf,
GlTruncate, GlTruncate,
} from '@gitlab/ui'; } from '@gitlab/ui';
import { s__ } from '~/locale'; import { sprintf, s__, __ } from '~/locale';
import { ALL, DEBOUNCE, STATUSES } from './constants'; import { ALL, DEBOUNCE, STATUSES } from './constants';
export default { export default {
...@@ -23,7 +22,6 @@ export default { ...@@ -23,7 +22,6 @@ export default {
GlFormGroup, GlFormGroup,
GlIcon, GlIcon,
GlSearchBoxByType, GlSearchBoxByType,
GlSprintf,
GlTruncate, GlTruncate,
}, },
props: { props: {
...@@ -54,6 +52,9 @@ export default { ...@@ -54,6 +52,9 @@ export default {
const firstOption = this.filters.statuses?.length ? this.filters.statuses[0] : undefined; const firstOption = this.filters.statuses?.length ? this.filters.statuses[0] : undefined;
return this.$options.i18n.STATUSES[firstOption] || this.$options.ALL.value; return this.$options.i18n.STATUSES[firstOption] || this.$options.ALL.value;
}, },
extraOptionText() {
return sprintf(__('+%{extra} more'), { extra: this.extraOptionCount });
},
}, },
methods: { methods: {
handleFilterChange(newFilters) { handleFilterChange(newFilters) {
...@@ -109,14 +110,9 @@ export default { ...@@ -109,14 +110,9 @@ export default {
<gl-dropdown toggle-class="gl-inset-border-1-gray-400!" class="gl-w-full"> <gl-dropdown toggle-class="gl-inset-border-1-gray-400!" class="gl-w-full">
<template #button-content> <template #button-content>
<gl-truncate :text="firstSelectedOption" class="gl-min-w-0 gl-mr-2" /> <gl-truncate :text="firstSelectedOption" class="gl-min-w-0 gl-mr-2" />
<gl-sprintf <span v-if="extraOptionCount > 0" class="gl-mr-2">
v-if="extraOptionCount > 0" {{ extraOptionText }}
class="gl-mr-2" </span>
:message="__('+%{extra} more')"
data-testid="dropdown-message"
>
<template #extra>{{ extraOptionCount }}</template>
</gl-sprintf>
<gl-icon name="chevron-down" class="gl-flex-shrink-0 gl-ml-auto" /> <gl-icon name="chevron-down" class="gl-flex-shrink-0 gl-ml-auto" />
</template> </template>
......
...@@ -2,6 +2,7 @@ import { GlDropdownItem, GlSearchBoxByType } from '@gitlab/ui'; ...@@ -2,6 +2,7 @@ import { GlDropdownItem, GlSearchBoxByType } from '@gitlab/ui';
import { mount, shallowMount } from '@vue/test-utils'; import { mount, shallowMount } from '@vue/test-utils';
import AlertFilters from 'ee/threat_monitoring/components/alerts/alert_filters.vue'; import AlertFilters from 'ee/threat_monitoring/components/alerts/alert_filters.vue';
import { ALL, DEFAULT_FILTERS, STATUSES } from 'ee/threat_monitoring/components/alerts/constants'; import { ALL, DEFAULT_FILTERS, STATUSES } from 'ee/threat_monitoring/components/alerts/constants';
import { trimText } from 'helpers/text_helper';
describe('AlertFilters component', () => { describe('AlertFilters component', () => {
let wrapper; let wrapper;
...@@ -62,7 +63,7 @@ describe('AlertFilters component', () => { ...@@ -62,7 +63,7 @@ describe('AlertFilters component', () => {
const status = 'TRIGGERED'; const status = 'TRIGGERED';
const translated = STATUSES[status]; const translated = STATUSES[status];
createWrapper({ method: mount }); createWrapper({ method: mount });
expect(findDropdownMessage()).toBe(`${translated} +1 more`); expect(trimText(findDropdownMessage())).toBe(`${translated} +1 more`);
}); });
it('Emits an event with the new filters on deselect', async () => { it('Emits an event with the new filters on deselect', async () => {
......
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