2017-06-13 13:01:59 -04:00
|
|
|
<script>
|
2020-11-16 13:09:15 -05:00
|
|
|
import { GlTooltipDirective, GlIcon, GlButton, GlDropdownItem } from '@gitlab/ui';
|
2021-03-11 07:09:28 -05:00
|
|
|
import { mapActions, mapGetters } from 'vuex';
|
2020-06-16 17:08:20 -04:00
|
|
|
import Api from '~/api';
|
2021-02-14 13:09:20 -05:00
|
|
|
import resolvedStatusMixin from '~/batch_comments/mixins/resolved_status';
|
2020-08-20 05:09:55 -04:00
|
|
|
import { deprecatedCreateFlash as flash } from '~/flash';
|
2021-02-02 19:09:41 -05:00
|
|
|
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
|
2021-02-14 13:09:20 -05:00
|
|
|
import { __, sprintf } from '~/locale';
|
|
|
|
import eventHub from '~/sidebar/event_hub';
|
2021-03-10 04:09:29 -05:00
|
|
|
import UserAccessRoleBadge from '~/vue_shared/components/user_access_role_badge.vue';
|
2021-03-11 07:09:28 -05:00
|
|
|
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
|
2020-09-16 11:09:32 -04:00
|
|
|
import { splitCamelCase } from '../../lib/utils/text_utility';
|
2021-02-01 10:08:56 -05:00
|
|
|
import ReplyButton from './note_actions/reply_button.vue';
|
2017-06-13 13:01:59 -04:00
|
|
|
|
2018-03-16 16:16:21 -04:00
|
|
|
export default {
|
2021-04-02 11:09:19 -04:00
|
|
|
i18n: {
|
|
|
|
addReactionLabel: __('Add reaction'),
|
|
|
|
editCommentLabel: __('Edit comment'),
|
|
|
|
deleteCommentLabel: __('Delete comment'),
|
|
|
|
moreActionsLabel: __('More actions'),
|
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
name: 'NoteActions',
|
2018-10-06 13:16:40 -04:00
|
|
|
components: {
|
2020-08-24 11:10:11 -04:00
|
|
|
GlIcon,
|
2019-02-06 05:31:46 -05:00
|
|
|
ReplyButton,
|
2020-11-16 13:09:15 -05:00
|
|
|
GlButton,
|
|
|
|
GlDropdownItem,
|
2021-03-10 04:09:29 -05:00
|
|
|
UserAccessRoleBadge,
|
2021-03-11 07:09:28 -05:00
|
|
|
EmojiPicker: () => import('~/emoji/components/picker.vue'),
|
2018-10-06 13:16:40 -04:00
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
directives: {
|
2018-11-09 04:44:07 -05:00
|
|
|
GlTooltip: GlTooltipDirective,
|
2018-03-16 16:16:21 -04:00
|
|
|
},
|
2021-03-11 07:09:28 -05:00
|
|
|
mixins: [resolvedStatusMixin, glFeatureFlagsMixin()],
|
2018-03-16 16:16:21 -04:00
|
|
|
props: {
|
2020-06-16 17:08:20 -04:00
|
|
|
author: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
authorId: {
|
|
|
|
type: Number,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
noteId: {
|
2018-10-06 13:16:40 -04:00
|
|
|
type: [String, Number],
|
2018-03-16 16:16:21 -04:00
|
|
|
required: true,
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
noteUrl: {
|
|
|
|
type: String,
|
2018-09-07 09:39:20 -04:00
|
|
|
required: false,
|
|
|
|
default: '',
|
2018-06-21 08:22:40 -04:00
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
accessLevel: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
reportAbusePath: {
|
|
|
|
type: String,
|
2018-10-06 13:16:40 -04:00
|
|
|
required: false,
|
|
|
|
default: null,
|
2018-03-16 16:16:21 -04:00
|
|
|
},
|
2020-09-16 11:09:32 -04:00
|
|
|
isAuthor: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
isContributor: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
noteableType: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
|
|
|
projectName: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
default: '',
|
|
|
|
},
|
2019-02-06 05:31:46 -05:00
|
|
|
showReply: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
canEdit: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-04-06 14:19:37 -04:00
|
|
|
canAwardEmoji: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
canDelete: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2018-06-21 08:22:40 -04:00
|
|
|
canResolve: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
resolvable: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
isResolved: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
isResolving: {
|
|
|
|
type: Boolean,
|
|
|
|
required: false,
|
|
|
|
default: false,
|
|
|
|
},
|
|
|
|
resolvedBy: {
|
|
|
|
type: Object,
|
|
|
|
required: false,
|
|
|
|
default: () => ({}),
|
|
|
|
},
|
|
|
|
canReportAsAbuse: {
|
|
|
|
type: Boolean,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-04-17 08:09:18 -04:00
|
|
|
// This can be undefined when `canAwardEmoji` is false
|
2021-03-11 07:09:28 -05:00
|
|
|
awardPath: {
|
|
|
|
type: String,
|
2021-04-17 08:09:18 -04:00
|
|
|
required: false,
|
|
|
|
default: '',
|
2021-03-11 07:09:28 -05:00
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
},
|
|
|
|
computed: {
|
2020-06-16 17:08:20 -04:00
|
|
|
...mapGetters(['getUserDataByProp', 'getNoteableData']),
|
2018-03-16 16:16:21 -04:00
|
|
|
shouldShowActionsDropdown() {
|
|
|
|
return this.currentUserId && (this.canEdit || this.canReportAsAbuse);
|
|
|
|
},
|
2018-10-06 13:16:40 -04:00
|
|
|
showDeleteAction() {
|
|
|
|
return this.canDelete && !this.canReportAsAbuse && !this.noteUrl;
|
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
isAuthoredByCurrentUser() {
|
|
|
|
return this.authorId === this.currentUserId;
|
|
|
|
},
|
|
|
|
currentUserId() {
|
|
|
|
return this.getUserDataByProp('id');
|
|
|
|
},
|
2020-06-16 17:08:20 -04:00
|
|
|
isUserAssigned() {
|
|
|
|
return this.assignees && this.assignees.some(({ id }) => id === this.author.id);
|
|
|
|
},
|
|
|
|
displayAssignUserText() {
|
|
|
|
return this.isUserAssigned
|
|
|
|
? __('Unassign from commenting user')
|
|
|
|
: __('Assign to commenting user');
|
|
|
|
},
|
|
|
|
sidebarAction() {
|
|
|
|
return this.isUserAssigned ? 'sidebar.addAssignee' : 'sidebar.removeAssignee';
|
|
|
|
},
|
|
|
|
targetType() {
|
|
|
|
return this.getNoteableData.targetType;
|
|
|
|
},
|
2020-09-16 11:09:32 -04:00
|
|
|
noteableDisplayName() {
|
|
|
|
return splitCamelCase(this.noteableType).toLowerCase();
|
|
|
|
},
|
2020-06-16 17:08:20 -04:00
|
|
|
assignees() {
|
|
|
|
return this.getNoteableData.assignees || [];
|
|
|
|
},
|
|
|
|
isIssue() {
|
|
|
|
return this.targetType === 'issue';
|
|
|
|
},
|
2020-06-30 05:08:37 -04:00
|
|
|
canAssign() {
|
|
|
|
return this.getNoteableData.current_user?.can_update && this.isIssue;
|
|
|
|
},
|
2020-09-16 11:09:32 -04:00
|
|
|
displayAuthorBadgeText() {
|
|
|
|
return sprintf(__('This user is the author of this %{noteable}.'), {
|
|
|
|
noteable: this.noteableDisplayName,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
displayMemberBadgeText() {
|
2020-09-24 08:09:37 -04:00
|
|
|
return sprintf(__('This user has the %{access} role in the %{name} project.'), {
|
2020-09-16 11:09:32 -04:00
|
|
|
access: this.accessLevel.toLowerCase(),
|
|
|
|
name: this.projectName,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
displayContributorBadgeText() {
|
|
|
|
return sprintf(__('This user has previously committed to the %{name} project.'), {
|
|
|
|
name: this.projectName,
|
|
|
|
});
|
|
|
|
},
|
2020-11-16 13:09:15 -05:00
|
|
|
resolveIcon() {
|
|
|
|
if (!this.isResolving) {
|
|
|
|
return this.isResolved ? 'check-circle-filled' : 'check-circle';
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
resolveVariant() {
|
|
|
|
return this.isResolved ? 'success' : 'default';
|
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
},
|
|
|
|
methods: {
|
2021-03-11 07:09:28 -05:00
|
|
|
...mapActions(['toggleAwardRequest']),
|
2018-03-16 16:16:21 -04:00
|
|
|
onEdit() {
|
|
|
|
this.$emit('handleEdit');
|
|
|
|
},
|
|
|
|
onDelete() {
|
|
|
|
this.$emit('handleDelete');
|
|
|
|
},
|
|
|
|
onResolve() {
|
|
|
|
this.$emit('handleResolve');
|
|
|
|
},
|
2019-01-09 18:46:43 -05:00
|
|
|
closeTooltip() {
|
|
|
|
this.$nextTick(() => {
|
2021-02-02 19:09:41 -05:00
|
|
|
this.$root.$emit(BV_HIDE_TOOLTIP);
|
2019-01-09 18:46:43 -05:00
|
|
|
});
|
|
|
|
},
|
2020-06-16 17:08:20 -04:00
|
|
|
handleAssigneeUpdate(assignees) {
|
|
|
|
this.$emit('updateAssignees', assignees);
|
|
|
|
eventHub.$emit(this.sidebarAction, this.author);
|
|
|
|
eventHub.$emit('sidebar.saveAssignees');
|
|
|
|
},
|
|
|
|
assignUser() {
|
|
|
|
let { assignees } = this;
|
|
|
|
const { project_id, iid } = this.getNoteableData;
|
|
|
|
|
|
|
|
if (this.isUserAssigned) {
|
2020-12-23 16:10:24 -05:00
|
|
|
assignees = assignees.filter((assignee) => assignee.id !== this.author.id);
|
2020-06-16 17:08:20 -04:00
|
|
|
} else {
|
|
|
|
assignees.push({ id: this.author.id });
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.targetType === 'issue') {
|
|
|
|
Api.updateIssue(project_id, iid, {
|
2020-12-23 16:10:24 -05:00
|
|
|
assignee_ids: assignees.map((assignee) => assignee.id),
|
2020-06-16 17:08:20 -04:00
|
|
|
})
|
|
|
|
.then(() => this.handleAssigneeUpdate(assignees))
|
|
|
|
.catch(() => flash(__('Something went wrong while updating assignees')));
|
|
|
|
}
|
|
|
|
},
|
2021-03-11 07:09:28 -05:00
|
|
|
setAwardEmoji(awardName) {
|
|
|
|
this.toggleAwardRequest({
|
|
|
|
endpoint: this.awardPath,
|
|
|
|
noteId: this.noteId,
|
|
|
|
awardName,
|
|
|
|
});
|
|
|
|
},
|
2018-03-16 16:16:21 -04:00
|
|
|
},
|
|
|
|
};
|
2017-06-13 13:01:59 -04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div class="note-actions">
|
2021-03-10 04:09:29 -05:00
|
|
|
<user-access-role-badge
|
2020-09-16 11:09:32 -04:00
|
|
|
v-if="isAuthor"
|
2021-03-10 04:09:29 -05:00
|
|
|
v-gl-tooltip
|
|
|
|
class="gl-mx-3 d-none d-md-inline-block"
|
2020-09-16 11:09:32 -04:00
|
|
|
:title="displayAuthorBadgeText"
|
|
|
|
>
|
2021-03-10 04:09:29 -05:00
|
|
|
{{ __('Author') }}
|
|
|
|
</user-access-role-badge>
|
|
|
|
<user-access-role-badge
|
2020-09-16 11:09:32 -04:00
|
|
|
v-if="accessLevel"
|
2021-03-10 04:09:29 -05:00
|
|
|
v-gl-tooltip
|
|
|
|
class="gl-mx-3"
|
2020-09-16 11:09:32 -04:00
|
|
|
:title="displayMemberBadgeText"
|
|
|
|
>
|
2021-03-10 04:09:29 -05:00
|
|
|
{{ accessLevel }}
|
|
|
|
</user-access-role-badge>
|
|
|
|
<user-access-role-badge
|
2020-09-16 11:09:32 -04:00
|
|
|
v-else-if="isContributor"
|
2021-03-10 04:09:29 -05:00
|
|
|
v-gl-tooltip
|
|
|
|
class="gl-mx-3"
|
2020-09-16 11:09:32 -04:00
|
|
|
:title="displayContributorBadgeText"
|
|
|
|
>
|
2021-03-10 04:09:29 -05:00
|
|
|
{{ __('Contributor') }}
|
|
|
|
</user-access-role-badge>
|
2021-02-12 10:08:43 -05:00
|
|
|
<gl-button
|
|
|
|
v-if="canResolve"
|
|
|
|
ref="resolveButton"
|
|
|
|
v-gl-tooltip
|
|
|
|
category="tertiary"
|
|
|
|
:variant="resolveVariant"
|
|
|
|
:class="{ 'is-disabled': !resolvable, 'is-active': isResolved }"
|
|
|
|
:title="resolveButtonTitle"
|
|
|
|
:aria-label="resolveButtonTitle"
|
|
|
|
:icon="resolveIcon"
|
|
|
|
:loading="isResolving"
|
|
|
|
class="line-resolve-btn note-action-button"
|
|
|
|
@click="onResolve"
|
|
|
|
/>
|
2021-03-11 07:09:28 -05:00
|
|
|
<template v-if="canAwardEmoji">
|
|
|
|
<emoji-picker
|
|
|
|
v-if="glFeatures.improvedEmojiPicker"
|
2021-05-11 11:10:20 -04:00
|
|
|
toggle-class="note-action-button note-emoji-button gl-text-gray-600 gl-m-3 gl-p-0! gl-shadow-none! gl-bg-transparent!"
|
2021-03-11 07:09:28 -05:00
|
|
|
@click="setAwardEmoji"
|
|
|
|
>
|
|
|
|
<template #button-content>
|
|
|
|
<gl-icon class="link-highlight award-control-icon-neutral gl-m-0!" name="slight-smile" />
|
|
|
|
<gl-icon class="link-highlight award-control-icon-positive gl-m-0!" name="smiley" />
|
|
|
|
<gl-icon class="link-highlight award-control-icon-super-positive gl-m-0!" name="smile" />
|
|
|
|
</template>
|
|
|
|
</emoji-picker>
|
|
|
|
<gl-button
|
|
|
|
v-else
|
|
|
|
v-gl-tooltip
|
|
|
|
:class="{ 'js-user-authored': isAuthoredByCurrentUser }"
|
2021-06-02 14:10:01 -04:00
|
|
|
class="note-action-button note-emoji-button add-reaction-button js-add-award js-note-emoji"
|
2021-03-11 07:09:28 -05:00
|
|
|
category="tertiary"
|
|
|
|
variant="default"
|
2021-04-02 11:09:19 -04:00
|
|
|
:title="$options.i18n.addReactionLabel"
|
|
|
|
:aria-label="$options.i18n.addReactionLabel"
|
2021-03-11 07:09:28 -05:00
|
|
|
data-position="right"
|
|
|
|
>
|
|
|
|
<span class="reaction-control-icon reaction-control-icon-neutral">
|
|
|
|
<gl-icon name="slight-smile" />
|
|
|
|
</span>
|
|
|
|
<span class="reaction-control-icon reaction-control-icon-positive">
|
|
|
|
<gl-icon name="smiley" />
|
|
|
|
</span>
|
|
|
|
<span class="reaction-control-icon reaction-control-icon-super-positive">
|
|
|
|
<gl-icon name="smile" />
|
|
|
|
</span>
|
|
|
|
</gl-button>
|
|
|
|
</template>
|
2019-02-06 05:31:46 -05:00
|
|
|
<reply-button
|
2019-04-02 22:00:18 -04:00
|
|
|
v-if="showReply"
|
2019-02-06 05:31:46 -05:00
|
|
|
ref="replyButton"
|
|
|
|
class="js-reply-button"
|
2019-02-18 04:43:13 -05:00
|
|
|
@startReplying="$emit('startReplying')"
|
2019-02-06 05:31:46 -05:00
|
|
|
/>
|
2021-02-12 10:08:43 -05:00
|
|
|
<gl-button
|
|
|
|
v-if="canEdit"
|
|
|
|
v-gl-tooltip
|
2021-04-02 11:09:19 -04:00
|
|
|
:title="$options.i18n.editCommentLabel"
|
|
|
|
:aria-label="$options.i18n.editCommentLabel"
|
2021-02-12 10:08:43 -05:00
|
|
|
icon="pencil"
|
|
|
|
category="tertiary"
|
2021-04-09 05:09:10 -04:00
|
|
|
class="note-action-button js-note-edit"
|
2021-02-12 10:08:43 -05:00
|
|
|
data-qa-selector="note_edit_button"
|
|
|
|
@click="onEdit"
|
|
|
|
/>
|
|
|
|
<gl-button
|
|
|
|
v-if="showDeleteAction"
|
|
|
|
v-gl-tooltip
|
2021-04-02 11:09:19 -04:00
|
|
|
:title="$options.i18n.deleteCommentLabel"
|
|
|
|
:aria-label="$options.i18n.deleteCommentLabel"
|
2021-02-12 10:08:43 -05:00
|
|
|
icon="remove"
|
|
|
|
category="tertiary"
|
2021-04-09 05:09:10 -04:00
|
|
|
class="note-action-button js-note-delete"
|
2021-02-12 10:08:43 -05:00
|
|
|
@click="onDelete"
|
|
|
|
/>
|
|
|
|
<div v-else-if="shouldShowActionsDropdown" class="dropdown more-actions">
|
2021-04-29 17:10:03 -04:00
|
|
|
<!-- eslint-disable @gitlab/vue-no-data-toggle -->
|
2020-11-16 13:09:15 -05:00
|
|
|
<gl-button
|
2018-08-15 07:37:24 -04:00
|
|
|
v-gl-tooltip
|
2021-04-02 11:09:19 -04:00
|
|
|
:title="$options.i18n.moreActionsLabel"
|
|
|
|
:aria-label="$options.i18n.moreActionsLabel"
|
2020-11-16 13:09:15 -05:00
|
|
|
icon="ellipsis_v"
|
|
|
|
category="tertiary"
|
2021-04-09 05:09:10 -04:00
|
|
|
class="note-action-button more-actions-toggle"
|
2017-06-13 13:01:59 -04:00
|
|
|
data-toggle="dropdown"
|
2019-01-09 18:46:43 -05:00
|
|
|
@click="closeTooltip"
|
2020-11-16 13:09:15 -05:00
|
|
|
/>
|
2021-04-29 17:10:03 -04:00
|
|
|
<!-- eslint-enable @gitlab/vue-no-data-toggle -->
|
2017-06-13 13:01:59 -04:00
|
|
|
<ul class="dropdown-menu more-actions-dropdown dropdown-open-left">
|
2020-11-16 13:09:15 -05:00
|
|
|
<gl-dropdown-item v-if="canReportAsAbuse" :href="reportAbusePath">
|
|
|
|
{{ __('Report abuse to admin') }}
|
|
|
|
</gl-dropdown-item>
|
|
|
|
<gl-dropdown-item
|
|
|
|
v-if="noteUrl"
|
|
|
|
class="js-btn-copy-note-link"
|
|
|
|
:data-clipboard-text="noteUrl"
|
|
|
|
>
|
|
|
|
{{ __('Copy link') }}
|
|
|
|
</gl-dropdown-item>
|
|
|
|
<gl-dropdown-item v-if="canAssign" data-testid="assign-user" @click="assignUser">
|
|
|
|
{{ displayAssignUserText }}
|
|
|
|
</gl-dropdown-item>
|
|
|
|
<gl-dropdown-item v-if="canEdit" class="js-note-delete" @click.prevent="onDelete">
|
|
|
|
<span class="text-danger">{{ __('Delete comment') }}</span>
|
|
|
|
</gl-dropdown-item>
|
2017-06-13 13:01:59 -04:00
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|