2018-12-13 13:39:08 +05:30
|
|
|
<script>
|
2022-08-13 15:12:31 +05:30
|
|
|
import { GlButton, GlLink, GlSprintf } from '@gitlab/ui';
|
2021-03-11 19:13:27 +05:30
|
|
|
import { uniqBy } from 'lodash';
|
2022-08-13 15:12:31 +05:30
|
|
|
import { s__ } from '~/locale';
|
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 {
|
2022-08-13 15:12:31 +05:30
|
|
|
i18n: {
|
|
|
|
collapseReplies: s__('Notes|Collapse replies'),
|
|
|
|
expandReplies: s__('Notes|Expand replies'),
|
|
|
|
lastReplyBy: s__('Notes|Last reply by %{name}'),
|
|
|
|
},
|
2018-12-13 13:39:08 +05:30
|
|
|
components: {
|
2021-01-29 00:20:46 +05:30
|
|
|
GlButton,
|
2022-08-13 15:12:31 +05:30
|
|
|
GlLink,
|
|
|
|
GlSprintf,
|
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
|
|
|
|
2022-08-13 15:12:31 +05:30
|
|
|
return uniqBy(authors, 'username');
|
|
|
|
},
|
|
|
|
liClasses() {
|
|
|
|
return this.collapsed
|
2023-05-27 22:25:52 +05:30
|
|
|
? 'gl-text-gray-500 gl-rounded-bottom-left-base! gl-rounded-bottom-right-base! replies-widget-collapsed'
|
2022-08-13 15:12:31 +05:30
|
|
|
: 'gl-border-b';
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
2022-08-13 15:12:31 +05:30
|
|
|
buttonIcon() {
|
|
|
|
return this.collapsed ? 'chevron-right' : 'chevron-down';
|
|
|
|
},
|
|
|
|
buttonLabel() {
|
|
|
|
return this.collapsed ? this.$options.i18n.expandReplies : this.$options.i18n.collapseReplies;
|
2018-12-13 13:39:08 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
toggle() {
|
2022-08-13 15:12:31 +05:30
|
|
|
this.$refs.toggle.$el.focus();
|
2018-12-13 13:39:08 +05:30
|
|
|
this.$emit('toggle');
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2021-03-11 19:13:27 +05:30
|
|
|
<li
|
2022-08-13 15:12:31 +05:30
|
|
|
:class="liClasses"
|
2022-11-25 23:54:43 +05:30
|
|
|
class="toggle-replies-widget gl-display-flex! gl-align-items-center gl-flex-wrap gl-bg-gray-10 gl-py-3 gl-px-5 gl-border"
|
2021-03-11 19:13:27 +05:30
|
|
|
>
|
2022-08-13 15:12:31 +05:30
|
|
|
<gl-button
|
|
|
|
ref="toggle"
|
|
|
|
class="gl-my-2 gl-mr-3 gl-p-0!"
|
|
|
|
category="tertiary"
|
|
|
|
:icon="buttonIcon"
|
|
|
|
:aria-label="buttonLabel"
|
|
|
|
@click="toggle"
|
|
|
|
/>
|
2018-12-13 13:39:08 +05:30
|
|
|
<template v-if="collapsed">
|
2022-08-13 15:12:31 +05:30
|
|
|
<user-avatar-link
|
|
|
|
v-for="author in uniqueAuthors"
|
|
|
|
:key="author.username"
|
2022-11-25 23:54:43 +05:30
|
|
|
class="gl-mr-3 reply-author-avatar"
|
2023-05-27 22:25:52 +05:30
|
|
|
:link-href="author.path || author.webUrl"
|
2022-08-13 15:12:31 +05:30
|
|
|
:img-alt="author.name"
|
|
|
|
img-css-classes="gl-mr-0!"
|
2023-04-23 21:23:45 +05:30
|
|
|
:img-src="author.avatar_url || author.avatarUrl"
|
2022-08-13 15:12:31 +05:30
|
|
|
:img-size="24"
|
|
|
|
:tooltip-text="author.name"
|
|
|
|
tooltip-placement="bottom"
|
|
|
|
/>
|
2021-01-29 00:20:46 +05:30
|
|
|
<gl-button
|
2022-08-13 15:12:31 +05:30
|
|
|
class="gl-mr-2"
|
2021-01-29 00:20:46 +05:30
|
|
|
variant="link"
|
2021-01-03 14:25:43 +05:30
|
|
|
data-qa-selector="expand_replies_button"
|
|
|
|
@click="toggle"
|
|
|
|
>
|
2022-08-13 15:12:31 +05:30
|
|
|
{{ n__('%d reply', '%d replies', replies.length) }}
|
2021-01-29 00:20:46 +05:30
|
|
|
</gl-button>
|
2022-08-13 15:12:31 +05:30
|
|
|
<gl-sprintf :message="$options.i18n.lastReplyBy">
|
|
|
|
<template #name>
|
|
|
|
<gl-link
|
2023-05-27 22:25:52 +05:30
|
|
|
:href="lastReply.author.path || lastReply.author.webUrl"
|
2022-08-13 15:12:31 +05:30
|
|
|
class="gl-text-body! gl-text-decoration-none! gl-mx-2"
|
|
|
|
>
|
|
|
|
{{ lastReply.author.name }}
|
|
|
|
</gl-link>
|
|
|
|
</template>
|
|
|
|
</gl-sprintf>
|
2023-04-23 21:23:45 +05:30
|
|
|
<time-ago-tooltip
|
|
|
|
:time="lastReply.created_at || lastReply.createdAt"
|
|
|
|
tooltip-placement="bottom"
|
|
|
|
/>
|
2018-12-13 13:39:08 +05:30
|
|
|
</template>
|
2022-08-13 15:12:31 +05:30
|
|
|
<gl-button
|
2019-01-03 12:48:30 +05:30
|
|
|
v-else
|
2022-08-13 15:12:31 +05:30
|
|
|
class="gl-text-body! gl-text-decoration-none!"
|
|
|
|
variant="link"
|
2021-01-03 14:25:43 +05:30
|
|
|
data-qa-selector="collapse_replies_button"
|
2019-01-03 12:48:30 +05:30
|
|
|
@click="toggle"
|
|
|
|
>
|
2022-08-13 15:12:31 +05:30
|
|
|
{{ $options.i18n.collapseReplies }}
|
|
|
|
</gl-button>
|
2018-12-13 13:39:08 +05:30
|
|
|
</li>
|
|
|
|
</template>
|