debian-mirror-gitlab/app/assets/javascripts/notes/components/toggle_replies_widget.vue

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

91 lines
2.4 KiB
Vue
Raw Normal View History

2018-12-13 13:39:08 +05:30
<script>
2021-01-29 00:20:46 +05:30
import { GlButton, GlIcon } from '@gitlab/ui';
2021-03-11 19:13:27 +05:30
import { uniqBy } from 'lodash';
2018-12-13 13:39:08 +05:30
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
2021-03-11 19:13:27 +05:30
import UserAvatarLink from '~/vue_shared/components/user_avatar/user_avatar_link.vue';
2018-12-13 13:39:08 +05:30
export default {
components: {
2021-01-29 00:20:46 +05:30
GlButton,
2020-11-24 15:15:51 +05:30
GlIcon,
2018-12-13 13:39:08 +05:30
UserAvatarLink,
TimeAgoTooltip,
},
props: {
collapsed: {
type: Boolean,
required: true,
},
replies: {
type: Array,
required: true,
},
},
computed: {
lastReply() {
return this.replies[this.replies.length - 1];
},
uniqueAuthors() {
2021-03-08 18:12:59 +05:30
const authors = this.replies.map((reply) => reply.author || {});
2018-12-13 13:39:08 +05:30
2021-03-08 18:12:59 +05:30
return uniqBy(authors, (author) => author.username);
2018-12-13 13:39:08 +05:30
},
className() {
return this.collapsed ? 'collapsed' : 'expanded';
},
},
methods: {
toggle() {
this.$emit('toggle');
},
},
2021-03-11 19:13:27 +05:30
ICON_CLASS: 'gl-mr-3 gl-cursor-pointer',
2018-12-13 13:39:08 +05:30
};
</script>
<template>
2021-03-11 19:13:27 +05:30
<li
:class="className"
class="replies-toggle js-toggle-replies gl-display-flex! gl-align-items-center gl-flex-wrap"
>
2018-12-13 13:39:08 +05:30
<template v-if="collapsed">
2021-03-11 19:13:27 +05:30
<gl-icon :class="$options.ICON_CLASS" name="chevron-right" @click.native="toggle" />
2018-12-13 13:39:08 +05:30
<div>
<user-avatar-link
v-for="author in uniqueAuthors"
:key="author.username"
:link-href="author.path"
:img-alt="author.name"
:img-src="author.avatar_url"
2022-06-21 17:19:12 +05:30
:img-size="24"
2018-12-13 13:39:08 +05:30
:tooltip-text="author.name"
tooltip-placement="bottom"
/>
</div>
2021-01-29 00:20:46 +05:30
<gl-button
2021-03-11 19:13:27 +05:30
class="js-replies-text gl-mr-2"
2021-01-29 00:20:46 +05:30
category="tertiary"
variant="link"
2021-01-03 14:25:43 +05:30
data-qa-selector="expand_replies_button"
@click="toggle"
>
2018-12-13 13:39:08 +05:30
{{ replies.length }} {{ n__('reply', 'replies', replies.length) }}
2021-01-29 00:20:46 +05:30
</gl-button>
2018-12-13 13:39:08 +05:30
{{ __('Last reply by') }}
2021-03-11 19:13:27 +05:30
<a :href="lastReply.author.path" class="btn btn-link author-link gl-mx-2">
2018-12-13 13:39:08 +05:30
{{ lastReply.author.name }}
</a>
2019-02-15 15:39:39 +05:30
<time-ago-tooltip :time="lastReply.created_at" tooltip-placement="bottom" />
2018-12-13 13:39:08 +05:30
</template>
2021-03-11 19:13:27 +05:30
<div
2019-01-03 12:48:30 +05:30
v-else
2021-03-11 19:13:27 +05:30
class="collapse-replies-btn js-collapse-replies gl-display-flex align-items-center"
2021-01-03 14:25:43 +05:30
data-qa-selector="collapse_replies_button"
2019-01-03 12:48:30 +05:30
@click="toggle"
>
2021-03-11 19:13:27 +05:30
<gl-icon :class="$options.ICON_CLASS" name="chevron-down" />
<span class="gl-cursor-pointer">{{ s__('Notes|Collapse replies') }}</span>
</div>
2018-12-13 13:39:08 +05:30
</li>
</template>