debian-mirror-gitlab/app/assets/javascripts/diffs/components/diff_gutter_avatars.vue

95 lines
2.4 KiB
Vue
Raw Normal View History

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 { n__ } from '~/locale';
import { truncate } from '~/lib/utils/text_utility';
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';
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}`;
},
},
};
</script>
<template>
<div class="diff-comment-avatar-holders">
<button
v-if="discussionsExpanded"
type="button"
2019-09-30 21:07:59 +05:30
:aria-label="__('Show 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"
:tooltip-text="getTooltipText(note)"
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>