From 3b060a68f3ca685d0676c2a70e3471dc7ee19d6e Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Wed, 27 Jul 2022 18:12:02 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- .../components/user_select/user_select.vue | 54 ++++++++++++++++------ 1 file changed, 39 insertions(+), 15 deletions(-) (limited to 'app/assets/javascripts/vue_shared/components/user_select/user_select.vue') diff --git a/app/assets/javascripts/vue_shared/components/user_select/user_select.vue b/app/assets/javascripts/vue_shared/components/user_select/user_select.vue index 91f20863089..43a590c2367 100644 --- a/app/assets/javascripts/vue_shared/components/user_select/user_select.vue +++ b/app/assets/javascripts/vue_shared/components/user_select/user_select.vue @@ -77,6 +77,11 @@ export default { required: false, default: null, }, + issuableAuthor: { + type: Object, + required: false, + default: null, + }, }, data() { return { @@ -178,7 +183,7 @@ export default { [], ); - return this.moveCurrentUserToStart(mergedSearchResults); + return this.moveCurrentUserAndAuthorToStart(mergedSearchResults); }, isSearchEmpty() { return this.search === ''; @@ -196,14 +201,21 @@ export default { showCurrentUser() { return this.currentUser.username && !this.isCurrentUserInList && this.isSearchEmpty; }, + showAuthor() { + return ( + this.issuableAuthor && + !this.users.some((user) => user.id === this.issuableAuthor.id) && + this.isSearchEmpty + ); + }, selectedFiltered() { if (this.shouldShowParticipants) { - return this.moveCurrentUserToStart(this.value); + return this.moveCurrentUserAndAuthorToStart(this.value); } const foundUsernames = this.users.map(({ username }) => username); const filtered = this.value.filter(({ username }) => foundUsernames.includes(username)); - return this.moveCurrentUserToStart(filtered); + return this.moveCurrentUserAndAuthorToStart(filtered); }, selectedUserNames() { return this.value.map(({ username }) => username); @@ -254,20 +266,22 @@ export default { showDivider(list) { return list.length > 0 && this.isSearchEmpty; }, - moveCurrentUserToStart(users) { - if (!users) { - return []; + moveCurrentUserAndAuthorToStart(users = []) { + let sortedUsers = [...users]; + + const author = sortedUsers.find((user) => user.id === this.issuableAuthor?.id); + if (author) { + sortedUsers = [author, ...sortedUsers.filter((user) => user.id !== author.id)]; } - const usersCopy = [...users]; - const currentUser = usersCopy.find((user) => user.username === this.currentUser.username); + + const currentUser = sortedUsers.find((user) => user.username === this.currentUser.username); if (currentUser) { currentUser.canMerge = this.currentUser.canMerge; - const index = usersCopy.indexOf(currentUser); - usersCopy.splice(0, 0, usersCopy.splice(index, 1)[0]); + sortedUsers = [currentUser, ...sortedUsers.filter((user) => user.id !== currentUser.id)]; } - return usersCopy; + return sortedUsers; }, setSearchKey(value) { this.search = value.trim(); @@ -298,7 +312,7 @@ export default { - + + +