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