1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
<script>
import { GlAvatar, GlBadge, GlPopover, GlSprintf } from '@gitlab/ui';
import { groupBy } from 'lodash';
import { convertToGraphQLId } from '~/graphql_shared/utils';
import { s__ } from '~/locale';
import { TYPENAME_USER } from '~/graphql_shared/constants';
import timeagoMixin from '~/vue_shared/mixins/timeago';
import getUserAchievements from './graphql/get_user_achievements.query.graphql';
export default {
name: 'UserAchievements',
components: { GlAvatar, GlBadge, GlPopover, GlSprintf },
mixins: [timeagoMixin],
inject: ['rootUrl', 'userId'],
apollo: {
userAchievements: {
query: getUserAchievements,
variables() {
return {
id: convertToGraphQLId(TYPENAME_USER, this.userId),
};
},
update(data) {
return this.processNodes(data.user.userAchievements.nodes);
},
error() {
return [];
},
},
},
methods: {
processNodes(nodes) {
return Object.entries(groupBy(nodes, 'achievement.id'))
.slice(0, 3)
.map(([id, values]) => {
const {
achievement: { name, avatarUrl, description, namespace },
createdAt,
} = values[0];
const count = values.length;
return {
id: `user-achievement-${id}`,
name,
timeAgo: this.timeFormatted(createdAt),
avatarUrl: avatarUrl || gon.gitlab_logo,
description,
namespace: namespace && {
fullPath: namespace.fullPath,
webUrl: this.rootUrl + namespace.fullPath,
},
count,
};
});
},
achievementAwardedMessage(userAchievement) {
return userAchievement.namespace
? this.$options.i18n.awardedBy
: this.$options.i18n.awardedByUnknownNamespace;
},
showCountBadge(count) {
return count > 1;
},
getCountBadge(count) {
return `${count}x`;
},
},
i18n: {
awardedBy: s__('Achievements|Awarded %{timeAgo} by %{namespace}'),
awardedByUnknownNamespace: s__('Achievements|Awarded %{timeAgo} by a private namespace'),
},
};
</script>
<template>
<div class="gl-mb-3">
<div
v-for="userAchievement in userAchievements"
:key="userAchievement.id"
class="gl-display-inline-block gl-vertical-align-top"
data-testid="user-achievement"
>
<gl-avatar
:id="userAchievement.id"
:src="userAchievement.avatarUrl"
:size="32"
tabindex="0"
shape="rect"
class="gl-mx-2"
/>
<br />
<gl-badge v-if="showCountBadge(userAchievement.count)" variant="info" size="sm">{{
getCountBadge(userAchievement.count)
}}</gl-badge>
<gl-popover :target="userAchievement.id">
<div>
<span class="gl-font-weight-bold">{{ userAchievement.name }}</span>
<gl-badge v-if="showCountBadge(userAchievement.count)" variant="info" size="sm">{{
getCountBadge(userAchievement.count)
}}</gl-badge>
</div>
<div>
<gl-sprintf :message="achievementAwardedMessage(userAchievement)">
<template #timeAgo>
<span>{{ userAchievement.timeAgo }}</span>
</template>
<template v-if="userAchievement.namespace" #namespace>
<a :href="userAchievement.namespace.webUrl">{{
userAchievement.namespace.fullPath
}}</a>
</template>
</gl-sprintf>
</div>
<div
v-if="userAchievement.description"
class="gl-mt-5"
data-testid="achievement-description"
>
{{ userAchievement.description }}
</div>
</gl-popover>
</div>
</div>
</template>
|