Commit 5ceabb04 authored by Eulyeon Ko's avatar Eulyeon Ko

Apply reviewer suggestions

- Gather the de-duplication logic together

- DRY mock user data
parent 62391b52
......@@ -88,6 +88,8 @@ export default {
},
},
searchUsers: {
// TODO Remove error policy
// https://gitlab.com/gitlab-org/gitlab/-/issues/329750
errorPolicy: 'all',
query: searchUsers,
variables() {
......@@ -98,15 +100,9 @@ export default {
};
},
update(data) {
if (!data.workspace?.users?.nodes) return [];
// TODO this de-duplication is temporary (BE fix required)
// Also remove the error policy and related test (mockdata)
// https://gitlab.com/gitlab-org/gitlab/-/issues/327822
const users = data.workspace?.users?.nodes.filter((x) => x).map(({ user }) => user);
return users.reduce((acc, cur) => {
return acc.find((u) => u.id === cur.id) ? acc : [...acc, cur];
}, []);
// TODO Remove null filter (BE fix required)
// https://gitlab.com/gitlab-org/gitlab/-/issues/329750
return data.workspace?.users?.nodes.filter((x) => x).map(({ user }) => user) || [];
},
debounce: ASSIGNEES_DEBOUNCE_DELAY,
error({ graphQLErrors }) {
......@@ -140,15 +136,20 @@ export default {
if (!this.participants) {
return [];
}
const mergedSearchResults = this.participants.reduce((acc, current) => {
if (
!acc.some((user) => current.username === user.username) &&
(current.name.includes(this.search) || current.username.includes(this.search))
) {
acc.push(current);
}
return acc;
}, this.searchUsers);
const filteredParticipants = this.participants.filter(
(user) => user.name.includes(this.search) || user.username.includes(this.search),
);
// TODO this de-duplication is temporary (BE fix required)
// https://gitlab.com/gitlab-org/gitlab/-/issues/327822
const mergedSearchResults = filteredParticipants
.concat(this.searchUsers)
.reduce(
(acc, current) => (acc.some((user) => current.id === user.id) ? acc : [...acc, current]),
[],
);
return this.moveCurrentUserToStart(mergedSearchResults);
},
isSearchEmpty() {
......
......@@ -366,6 +366,25 @@ export const subscriptionNullResponse = {
},
};
const mockUser1 = {
id: 'gid://gitlab/User/1',
avatarUrl:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
name: 'Administrator',
username: 'root',
webUrl: '/root',
status: null,
};
const mockUser2 = {
id: 'gid://gitlab/User/4',
avatarUrl: '/avatar2',
name: 'rookie',
username: 'rookie',
webUrl: 'rookie',
status: null,
};
export const searchResponse = {
data: {
workspace: {
......@@ -373,24 +392,10 @@ export const searchResponse = {
users: {
nodes: [
{
user: {
id: '1',
avatarUrl: '/avatar',
name: 'root',
username: 'root',
webUrl: 'root',
status: null,
},
user: mockUser1,
},
{
user: {
id: '2',
avatarUrl: '/avatar2',
name: 'rookie',
username: 'rookie',
webUrl: 'rookie',
status: null,
},
user: mockUser2,
},
],
},
......@@ -407,39 +412,10 @@ export const projectMembersResponse = {
// Remove nulls https://gitlab.com/gitlab-org/gitlab/-/issues/329750
null,
null,
{
user: {
id: 'gid://gitlab/User/1',
avatarUrl:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
name: 'Administrator',
username: 'root',
webUrl: '/root',
status: null,
},
},
// This is a duplicated entry https://gitlab.com/gitlab-org/gitlab/-/issues/327822
{
user: {
id: 'gid://gitlab/User/1',
avatarUrl:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
name: 'Administrator',
username: 'root',
webUrl: '/root',
status: null,
},
},
{
user: {
id: '2',
avatarUrl: '/avatar2',
name: 'rookie',
username: 'rookie',
webUrl: 'rookie',
status: null,
},
},
// Remove duplicated entry https://gitlab.com/gitlab-org/gitlab/-/issues/327822
mockUser1,
mockUser1,
mockUser2,
{
user: {
id: 'gid://gitlab/User/2',
......@@ -469,25 +445,9 @@ export const participantsQueryResponse = {
iid: '1',
participants: {
nodes: [
{
id: 'gid://gitlab/User/1',
avatarUrl:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
name: 'Administrator',
username: 'root',
webUrl: '/root',
status: null,
},
// this is a duplicated entry https://gitlab.com/gitlab-org/gitlab/-/issues/327822
{
id: 'gid://gitlab/User/1',
avatarUrl:
'https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon',
name: 'Administrator',
username: 'root',
webUrl: '/root',
status: null,
},
// Remove duplicated entry https://gitlab.com/gitlab-org/gitlab/-/issues/327822
mockUser1,
mockUser1,
{
id: 'gid://gitlab/User/2',
avatarUrl:
......
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