Commit d265d67d authored by Natalia Tepluhina's avatar Natalia Tepluhina Committed by Nicolò Maria Mezzopera

Fix search debounce for Swimlanes board assignees

parent 632b7768
...@@ -39,50 +39,51 @@ export default { ...@@ -39,50 +39,51 @@ export default {
data() { data() {
return { return {
search: '', search: '',
participants: [], issueParticipants: [],
selected: [], selected: [],
}; };
}, },
apollo: { apollo: {
participants: { issueParticipants: {
query() { query: getIssueParticipants,
return this.isSearchEmpty ? getIssueParticipants : searchUsers;
},
variables() { variables() {
if (this.isSearchEmpty) {
return {
id: `gid://gitlab/Issue/${this.activeIssue.iid}`,
};
}
return { return {
search: this.search, id: `gid://gitlab/Issue/${this.activeIssue.iid}`,
}; };
}, },
update(data) { update(data) {
if (this.isSearchEmpty) { return data.issue?.participants?.nodes || [];
return data.issue?.participants?.nodes || [];
}
return data.users?.nodes || [];
}, },
debounce() { },
const { noSearchDelay, searchDelay } = this.$options; searchUsers: {
query: searchUsers,
return this.isSearchEmpty ? noSearchDelay : searchDelay; variables() {
return {
search: this.search,
};
}, },
update: (data) => data.users?.nodes || [],
skip() {
return this.isSearchEmpty;
},
debounce: 250,
}, },
}, },
computed: { computed: {
...mapGetters(['activeIssue']), ...mapGetters(['activeIssue']),
...mapState(['isSettingAssignees']), ...mapState(['isSettingAssignees']),
participants() {
return this.isSearchEmpty ? this.issueParticipants : this.searchUsers;
},
assigneeText() { assigneeText() {
return n__('Assignee', '%d Assignees', this.selected.length); return n__('Assignee', '%d Assignees', this.selected.length);
}, },
unSelectedFiltered() { unSelectedFiltered() {
return this.participants.filter(({ username }) => { return (
return !this.selectedUserNames.includes(username); this.participants?.filter(({ username }) => {
}); return !this.selectedUserNames.includes(username);
}) || []
);
}, },
selectedIsEmpty() { selectedIsEmpty() {
return this.selected.length === 0; return this.selected.length === 0;
...@@ -96,6 +97,11 @@ export default { ...@@ -96,6 +97,11 @@ export default {
currentUser() { currentUser() {
return gon?.current_username; return gon?.current_username;
}, },
isLoading() {
return (
this.$apollo.queries.issueParticipants?.loading || this.$apollo.queries.searchUsers?.loading
);
},
}, },
created() { created() {
this.selected = cloneDeep(this.activeIssue.assignees); this.selected = cloneDeep(this.activeIssue.assignees);
...@@ -147,7 +153,7 @@ export default { ...@@ -147,7 +153,7 @@ export default {
<gl-search-box-by-type v-model.trim="search" /> <gl-search-box-by-type v-model.trim="search" />
</template> </template>
<template #items> <template #items>
<gl-loading-icon v-if="$apollo.queries.participants.loading" size="lg" /> <gl-loading-icon v-if="isLoading" size="lg" />
<template v-else> <template v-else>
<gl-dropdown-item <gl-dropdown-item
:is-checked="selectedIsEmpty" :is-checked="selectedIsEmpty"
......
---
title: Fix search debounce for Swimlanes board assignees
merge_request: 52786
author:
type: fixed
...@@ -38,7 +38,7 @@ describe('BoardCardAssigneeDropdown', () => { ...@@ -38,7 +38,7 @@ describe('BoardCardAssigneeDropdown', () => {
return { return {
search, search,
selected: [], selected: [],
participants, issueParticipants: participants,
}; };
}, },
store, store,
...@@ -49,7 +49,7 @@ describe('BoardCardAssigneeDropdown', () => { ...@@ -49,7 +49,7 @@ describe('BoardCardAssigneeDropdown', () => {
mocks: { mocks: {
$apollo: { $apollo: {
queries: { queries: {
participants: { searchUsers: {
loading, loading,
}, },
}, },
...@@ -70,7 +70,6 @@ describe('BoardCardAssigneeDropdown', () => { ...@@ -70,7 +70,6 @@ describe('BoardCardAssigneeDropdown', () => {
return { return {
search, search,
selected: [], selected: [],
participants,
}; };
}, },
store, store,
...@@ -256,17 +255,15 @@ describe('BoardCardAssigneeDropdown', () => { ...@@ -256,17 +255,15 @@ describe('BoardCardAssigneeDropdown', () => {
}, },
); );
describe('when participants is loading', () => { describe('when searching users is loading', () => {
beforeEach(() => {
createComponent('', true);
});
it('finds a loading icon in the dropdown', () => { it('finds a loading icon in the dropdown', () => {
createComponent('test', true);
expect(findLoadingIcon().exists()).toBe(true); expect(findLoadingIcon().exists()).toBe(true);
}); });
}); });
describe('when participants is loading is false', () => { describe('when participants loading is false', () => {
beforeEach(() => { beforeEach(() => {
createComponent(); createComponent();
}); });
......
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