Commit 320ae7ee authored by Kushal Pandya's avatar Kushal Pandya

Add fuzzy search support to labels dropdown

Use `fuzzaldrinPlus` to filter labels within Vue
Labels Dropdown.
parent af144667
<script> <script>
import { mapState, mapGetters, mapActions } from 'vuex'; import { mapState, mapGetters, mapActions } from 'vuex';
import { GlLoadingIcon, GlButton, GlSearchBoxByType, GlLink } from '@gitlab/ui'; import { GlLoadingIcon, GlButton, GlSearchBoxByType, GlLink } from '@gitlab/ui';
import fuzzaldrinPlus from 'fuzzaldrin-plus';
import { UP_KEY_CODE, DOWN_KEY_CODE, ENTER_KEY_CODE, ESC_KEY_CODE } from '~/lib/utils/keycodes'; import { UP_KEY_CODE, DOWN_KEY_CODE, ENTER_KEY_CODE, ESC_KEY_CODE } from '~/lib/utils/keycodes';
import SmartVirtualList from '~/vue_shared/components/smart_virtual_list.vue'; import SmartVirtualList from '~/vue_shared/components/smart_virtual_list.vue';
...@@ -39,9 +40,9 @@ export default { ...@@ -39,9 +40,9 @@ export default {
...mapGetters(['selectedLabelsList', 'isDropdownVariantSidebar', 'isDropdownVariantEmbedded']), ...mapGetters(['selectedLabelsList', 'isDropdownVariantSidebar', 'isDropdownVariantEmbedded']),
visibleLabels() { visibleLabels() {
if (this.searchKey) { if (this.searchKey) {
return this.labels.filter(label => return fuzzaldrinPlus.filter(this.labels, this.searchKey, {
label.title.toLowerCase().includes(this.searchKey.toLowerCase()), key: ['title'],
); });
} }
return this.labels; return this.labels;
}, },
......
---
title: Add fuzzy search support to labels dropdown
merge_request: 43969
author:
type: fixed
...@@ -114,7 +114,7 @@ describe('sidebar labels', () => { ...@@ -114,7 +114,7 @@ describe('sidebar labels', () => {
const expected = { const expected = {
[defaultProps.issuableType]: { [defaultProps.issuableType]: {
label_ids: [27, 28, 40], label_ids: [27, 28, 29, 40],
}, },
}; };
......
...@@ -69,6 +69,16 @@ describe('DropdownContentsLabelsView', () => { ...@@ -69,6 +69,16 @@ describe('DropdownContentsLabelsView', () => {
expect(wrapper.vm.visibleLabels[0].title).toBe('Bug'); expect(wrapper.vm.visibleLabels[0].title).toBe('Bug');
}); });
it('returns matching labels with fuzzy filtering', () => {
wrapper.setData({
searchKey: 'bg',
});
expect(wrapper.vm.visibleLabels.length).toBe(2);
expect(wrapper.vm.visibleLabels[0].title).toBe('Bug');
expect(wrapper.vm.visibleLabels[1].title).toBe('Boog');
});
it('returns all labels when `searchKey` is empty', () => { it('returns all labels when `searchKey` is empty', () => {
wrapper.setData({ wrapper.setData({
searchKey: '', searchKey: '',
......
...@@ -24,6 +24,13 @@ export const mockLabels = [ ...@@ -24,6 +24,13 @@ export const mockLabels = [
color: '#FF0000', color: '#FF0000',
textColor: '#FFFFFF', textColor: '#FFFFFF',
}, },
{
id: 29,
title: 'Boog',
description: 'Label for bugs',
color: '#FF0000',
textColor: '#FFFFFF',
},
]; ];
export const mockConfig = { export const mockConfig = {
......
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