2018-06-21 12:22:40 +00:00
|
|
|
<script>
|
2020-08-24 15:10:11 +00:00
|
|
|
import { GlTooltipDirective, GlIcon } from '@gitlab/ui';
|
2019-07-24 17:39:18 +00:00
|
|
|
import { n__ } from '~/locale';
|
|
|
|
import { truncate } from '~/lib/utils/text_utility';
|
2018-06-21 12:22:40 +00:00
|
|
|
import UserAvatarImage from '~/vue_shared/components/user_avatar/user_avatar_image.vue';
|
|
|
|
import { COUNT_OF_AVATARS_IN_GUTTER, LENGTH_OF_AVATAR_TOOLTIP } from '../constants';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2020-08-24 15:10:11 +00:00
|
|
|
GlIcon,
|
2018-06-21 12:22:40 +00:00
|
|
|
UserAvatarImage,
|
|
|
|
},
|
2018-11-05 16:48:55 +00:00
|
|
|
directives: {
|
|
|
|
GlTooltip: GlTooltipDirective,
|
|
|
|
},
|
2018-06-21 12:22:40 +00:00
|
|
|
props: {
|
|
|
|
discussions: {
|
|
|
|
type: Array,
|
|
|
|
required: true,
|
|
|
|
},
|
2019-07-03 08:26:57 +00:00
|
|
|
discussionsExpanded: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
allDiscussions() {
|
|
|
|
return this.discussions.reduce((acc, note) => acc.concat(note.notes), []);
|
|
|
|
},
|
|
|
|
notesInGutter() {
|
2020-12-23 21:10:24 +00:00
|
|
|
return this.allDiscussions.slice(0, COUNT_OF_AVATARS_IN_GUTTER).map((n) => ({
|
2018-06-21 12:22:40 +00:00
|
|
|
note: n.note,
|
|
|
|
author: n.author,
|
|
|
|
}));
|
|
|
|
},
|
|
|
|
moreCount() {
|
|
|
|
return this.allDiscussions.length - this.notesInGutter.length;
|
|
|
|
},
|
|
|
|
moreText() {
|
|
|
|
if (this.moreCount === 0) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
2019-07-24 17:39:18 +00:00
|
|
|
return n__('%d more comment', '%d more comments', this.moreCount);
|
2018-06-21 12:22:40 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
getTooltipText(noteData) {
|
2018-06-16 21:50:13 +00:00
|
|
|
let { note } = noteData;
|
2018-06-21 12:22:40 +00:00
|
|
|
if (note.length > LENGTH_OF_AVATAR_TOOLTIP) {
|
|
|
|
note = truncate(note, LENGTH_OF_AVATAR_TOOLTIP);
|
|
|
|
}
|
|
|
|
|
|
|
|
return `${noteData.author.name}: ${note}`;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="diff-comment-avatar-holders">
|
|
|
|
<button
|
|
|
|
v-if="discussionsExpanded"
|
|
|
|
type="button"
|
2019-06-26 07:33:14 +00:00
|
|
|
:aria-label="__('Show comments')"
|
2018-06-21 12:22:40 +00:00
|
|
|
class="diff-notes-collapse js-diff-comment-avatar js-diff-comment-button"
|
2019-07-03 08:26:57 +00:00
|
|
|
@click="$emit('toggleLineDiscussions')"
|
2018-06-21 12:22:40 +00:00
|
|
|
>
|
2020-08-24 15:10:11 +00:00
|
|
|
<gl-icon :size="12" name="collapse" />
|
2018-06-21 12:22:40 +00:00
|
|
|
</button>
|
|
|
|
<template v-else>
|
|
|
|
<user-avatar-image
|
|
|
|
v-for="note in notesInGutter"
|
|
|
|
:key="note.id"
|
|
|
|
:img-src="note.author.avatar_url"
|
|
|
|
:tooltip-text="getTooltipText(note)"
|
|
|
|
class="diff-comment-avatar js-diff-comment-avatar"
|
2019-07-03 08:26:57 +00:00
|
|
|
@click.native="$emit('toggleLineDiscussions')"
|
2018-06-21 12:22:40 +00:00
|
|
|
/>
|
|
|
|
<span
|
|
|
|
v-if="moreText"
|
2018-09-20 06:13:50 +00:00
|
|
|
v-gl-tooltip
|
2018-06-21 12:22:40 +00:00
|
|
|
:title="moreText"
|
2018-09-10 21:44:44 +00:00
|
|
|
class="diff-comments-more-count js-diff-comment-avatar js-diff-comment-plus"
|
2018-06-21 12:22:40 +00:00
|
|
|
data-container="body"
|
|
|
|
data-placement="top"
|
|
|
|
role="button"
|
2019-07-03 08:26:57 +00:00
|
|
|
@click="$emit('toggleLineDiscussions')"
|
2018-11-16 20:07:38 +00:00
|
|
|
>+{{ moreCount }}</span
|
|
|
|
>
|
2018-06-21 12:22:40 +00:00
|
|
|
</template>
|
|
|
|
</div>
|
|
|
|
</template>
|