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

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

250 lines
6.7 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2023-03-04 22:38:38 +05:30
import { GlIcon, GlBadge, GlLoadingIcon, GlTooltipDirective } from '@gitlab/ui';
2018-05-09 12:01:36 +05:30
import { mapActions } from 'vuex';
2023-03-17 16:20:25 +05:30
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
2022-06-21 17:19:12 +05:30
import { __, s__ } from '~/locale';
2022-10-11 01:57:18 +05:30
import TimeAgoTooltip from '~/vue_shared/components/time_ago_tooltip.vue';
2022-06-21 17:19:12 +05:30
2018-05-09 12:01:36 +05:30
export default {
components: {
2022-10-11 01:57:18 +05:30
TimeAgoTooltip,
2020-05-24 23:13:21 +05:30
GitlabTeamMemberBadge: () =>
import('ee_component/vue_shared/components/user_avatar/badges/gitlab_team_member_badge.vue'),
GlIcon,
2022-07-16 23:28:13 +05:30
GlBadge,
2020-11-24 15:15:51 +05:30
GlLoadingIcon,
2020-05-24 23:13:21 +05:30
},
directives: {
GlTooltip: GlTooltipDirective,
2018-05-09 12:01:36 +05:30
},
props: {
author: {
type: Object,
2018-11-20 20:47:30 +05:30
required: false,
default: () => ({}),
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
createdAt: {
type: String,
2018-12-05 23:21:45 +05:30
required: false,
default: null,
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
actionText: {
type: String,
required: false,
default: '',
2018-03-17 18:26:18 +05:30
},
2018-05-09 12:01:36 +05:30
noteId: {
2018-12-05 23:21:45 +05:30
type: [String, Number],
required: false,
default: null,
2018-05-09 12:01:36 +05:30
},
2022-06-21 17:19:12 +05:30
noteableType: {
type: String,
required: false,
default: '',
},
2018-05-09 12:01:36 +05:30
includeToggle: {
type: Boolean,
required: false,
default: false,
},
expanded: {
type: Boolean,
required: false,
default: true,
},
2020-04-22 19:07:51 +05:30
showSpinner: {
type: Boolean,
required: false,
default: true,
},
2022-07-23 23:45:48 +05:30
isInternalNote: {
2020-05-24 23:13:21 +05:30
type: Boolean,
required: false,
default: false,
},
2022-11-25 23:54:43 +05:30
isSystemNote: {
type: Boolean,
required: false,
default: false,
},
2023-05-27 22:25:52 +05:30
noteUrl: {
type: String,
required: false,
default: '',
},
2023-07-09 08:55:56 +05:30
emailParticipant: {
type: String,
required: false,
default: '',
},
2020-05-24 23:13:21 +05:30
},
data() {
return {
isUsernameLinkHovered: false,
};
2018-05-09 12:01:36 +05:30
},
computed: {
2023-03-17 16:20:25 +05:30
authorId() {
return getIdFromGraphQLId(this.author.id);
},
authorHref() {
return this.author.path || this.author.webUrl;
},
2021-01-29 00:20:46 +05:30
toggleChevronIconName() {
return this.expanded ? 'chevron-up' : 'chevron-down';
2018-05-09 12:01:36 +05:30
},
noteTimestampLink() {
2023-05-27 22:25:52 +05:30
if (this.noteUrl) return this.noteUrl;
return this.noteId ? `#note_${getIdFromGraphQLId(this.noteId)}` : undefined;
2018-05-09 12:01:36 +05:30
},
2018-12-13 13:39:08 +05:30
hasAuthor() {
return this.author && Object.keys(this.author).length;
},
2023-07-09 08:55:56 +05:30
isServiceDeskEmailParticipant() {
return (
!this.isInternalNote && this.author.username === 'support-bot' && this.emailParticipant
);
},
2020-05-24 23:13:21 +05:30
authorLinkClasses() {
return {
hover: this.isUsernameLinkHovered,
'text-underline': this.isUsernameLinkHovered,
'author-name-link': true,
'js-user-link': true,
2023-04-23 21:23:45 +05:30
'gl-overflow-hidden': true,
'gl-overflow-wrap-break': true,
2020-05-24 23:13:21 +05:30
};
},
2021-01-29 00:20:46 +05:30
authorName() {
2023-07-09 08:55:56 +05:30
return this.isServiceDeskEmailParticipant ? this.emailParticipant : this.author.name;
2021-01-29 00:20:46 +05:30
},
2022-07-23 23:45:48 +05:30
internalNoteTooltip() {
2022-07-16 23:28:13 +05:30
return s__('Notes|This internal note will always remain confidential');
2022-06-21 17:19:12 +05:30
},
2018-05-09 12:01:36 +05:30
},
methods: {
...mapActions(['setTargetNoteHash']),
handleToggle() {
this.$emit('toggleHandler');
},
updateTargetNoteHash() {
2020-04-22 19:07:51 +05:30
if (this.$store) {
this.setTargetNoteHash(this.noteTimestampLink);
}
2018-05-09 12:01:36 +05:30
},
2020-05-24 23:13:21 +05:30
handleUsernameMouseEnter() {
this.$refs.authorNameLink.dispatchEvent(new Event('mouseenter'));
this.isUsernameLinkHovered = true;
},
handleUsernameMouseLeave() {
this.$refs.authorNameLink.dispatchEvent(new Event('mouseleave'));
this.isUsernameLinkHovered = false;
},
2018-05-09 12:01:36 +05:30
},
2022-05-07 20:08:51 +05:30
i18n: {
showThread: __('Show thread'),
hideThread: __('Hide thread'),
},
2018-05-09 12:01:36 +05:30
};
2018-03-17 18:26:18 +05:30
</script>
<template>
<div class="note-header-info">
2020-03-13 15:44:24 +05:30
<div v-if="includeToggle" ref="discussionActions" class="discussion-actions">
2018-11-08 19:23:39 +05:30
<button
class="note-action-button discussion-toggle-button js-vue-toggle-button"
type="button"
2022-05-07 20:08:51 +05:30
data-testid="thread-toggle"
2019-02-15 15:39:39 +05:30
@click="handleToggle"
>
2021-02-22 17:27:13 +05:30
<gl-icon ref="chevronIcon" :name="toggleChevronIconName" />
2022-05-07 20:08:51 +05:30
<template v-if="expanded">
{{ $options.i18n.hideThread }}
</template>
<template v-else>
{{ $options.i18n.showThread }}
</template>
2018-11-08 19:23:39 +05:30
</button>
</div>
2020-04-22 19:07:51 +05:30
<template v-if="hasAuthor">
2023-07-09 08:55:56 +05:30
<span
v-if="emailParticipant"
class="note-header-author-name gl-font-weight-bold"
data-testid="author-name"
v-text="authorName"
></span>
2020-04-22 19:07:51 +05:30
<a
2023-07-09 08:55:56 +05:30
v-else
2020-05-24 23:13:21 +05:30
ref="authorNameLink"
2023-03-17 16:20:25 +05:30
:href="authorHref"
2020-05-24 23:13:21 +05:30
:class="authorLinkClasses"
2023-03-17 16:20:25 +05:30
:data-user-id="authorId"
2020-04-22 19:07:51 +05:30
:data-username="author.username"
>
2023-07-09 08:55:56 +05:30
<span
class="note-header-author-name gl-font-weight-bold"
data-testid="author-name"
v-text="authorName"
></span>
2020-04-22 19:07:51 +05:30
</a>
2023-07-09 08:55:56 +05:30
<span v-if="!isSystemNote && !emailParticipant" class="text-nowrap author-username">
2020-05-24 23:13:21 +05:30
<a
ref="authorUsernameLink"
class="author-username-link"
2023-05-27 22:25:52 +05:30
:href="authorHref"
2020-05-24 23:13:21 +05:30
@mouseenter="handleUsernameMouseEnter"
@mouseleave="handleUsernameMouseLeave"
><span class="note-headline-light">@{{ author.username }}</span>
</a>
2022-10-11 01:57:18 +05:30
<slot name="note-header-info"></slot>
2020-05-24 23:13:21 +05:30
<gitlab-team-member-badge v-if="author && author.is_gitlab_employee" />
</span>
2023-07-09 08:55:56 +05:30
<span v-if="emailParticipant" class="note-headline-light">{{
__('(external participant)')
}}</span>
2020-04-22 19:07:51 +05:30
</template>
2019-07-07 11:18:12 +05:30
<span v-else>{{ __('A deleted user') }}</span>
<span class="note-headline-light note-headline-meta">
2021-01-29 00:20:46 +05:30
<span class="system-note-message" data-qa-selector="system_note_content">
<slot></slot>
</span>
2019-07-07 11:18:12 +05:30
<template v-if="createdAt">
2020-03-13 15:44:24 +05:30
<span ref="actionText" class="system-note-separator">
2019-07-07 11:18:12 +05:30
<template v-if="actionText">{{ actionText }}</template>
</span>
<a
2020-04-22 19:07:51 +05:30
v-if="noteTimestampLink"
ref="noteTimestampLink"
2019-07-07 11:18:12 +05:30
:href="noteTimestampLink"
class="note-timestamp system-note-separator"
@click="updateTargetNoteHash"
2018-03-17 18:26:18 +05:30
>
2019-07-07 11:18:12 +05:30
<time-ago-tooltip :time="createdAt" tooltip-placement="bottom" />
</a>
2020-04-22 19:07:51 +05:30
<time-ago-tooltip v-else ref="noteTimestamp" :time="createdAt" tooltip-placement="bottom" />
2019-07-07 11:18:12 +05:30
</template>
2022-07-16 23:28:13 +05:30
<gl-badge
2022-07-23 23:45:48 +05:30
v-if="isInternalNote"
2020-05-24 23:13:21 +05:30
v-gl-tooltip:tooltipcontainer.bottom
2023-01-13 00:05:48 +05:30
data-testid="internal-note-indicator"
2022-07-16 23:28:13 +05:30
variant="warning"
size="sm"
2022-11-25 23:54:43 +05:30
class="gl-ml-2"
2022-07-23 23:45:48 +05:30
:title="internalNoteTooltip"
2022-07-16 23:28:13 +05:30
>
{{ __('Internal note') }}
</gl-badge>
2019-12-26 22:10:19 +05:30
<slot name="extra-controls"></slot>
2020-11-24 15:15:51 +05:30
<gl-loading-icon
2020-04-22 19:07:51 +05:30
v-if="showSpinner"
ref="spinner"
2021-09-30 23:02:18 +05:30
size="sm"
2020-11-24 15:15:51 +05:30
class="editing-spinner"
:label="__('Comment is being updated')"
/>
2018-03-17 18:26:18 +05:30
</span>
</div>
</template>