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

286 lines
7.6 KiB
Vue
Raw Normal View History

2018-03-17 18:26:18 +05:30
<script>
2020-06-23 00:09:42 +05:30
import { __ } from '~/locale';
2018-05-09 12:01:36 +05:30
import { mapGetters } from 'vuex';
2019-02-15 15:39:39 +05:30
import { GlLoadingIcon, GlTooltipDirective } from '@gitlab/ui';
2020-06-23 00:09:42 +05:30
import resolvedStatusMixin from '~/batch_comments/mixins/resolved_status';
2020-01-01 13:55:28 +05:30
import Icon from '~/vue_shared/components/icon.vue';
2019-03-02 22:35:43 +05:30
import ReplyButton from './note_actions/reply_button.vue';
2020-06-23 00:09:42 +05:30
import eventHub from '~/sidebar/event_hub';
import Api from '~/api';
import flash from '~/flash';
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
export default {
name: 'NoteActions',
2018-12-05 23:21:45 +05:30
components: {
Icon,
2019-03-02 22:35:43 +05:30
ReplyButton,
2018-12-13 13:39:08 +05:30
GlLoadingIcon,
2018-12-05 23:21:45 +05:30
},
2018-05-09 12:01:36 +05:30
directives: {
2019-02-15 15:39:39 +05:30
GlTooltip: GlTooltipDirective,
2018-05-09 12:01:36 +05:30
},
2019-07-31 22:56:46 +05:30
mixins: [resolvedStatusMixin],
2018-05-09 12:01:36 +05:30
props: {
2020-06-23 00:09:42 +05:30
author: {
type: Object,
required: true,
},
2018-05-09 12:01:36 +05:30
authorId: {
type: Number,
required: true,
},
noteId: {
2018-12-05 23:21:45 +05:30
type: [String, Number],
2018-05-09 12:01:36 +05:30
required: true,
},
2018-11-08 19:23:39 +05:30
noteUrl: {
type: String,
2018-11-20 20:47:30 +05:30
required: false,
default: '',
2018-11-08 19:23:39 +05:30
},
2018-05-09 12:01:36 +05:30
accessLevel: {
type: String,
required: false,
default: '',
},
reportAbusePath: {
type: String,
2018-12-05 23:21:45 +05:30
required: false,
default: null,
2018-05-09 12:01:36 +05:30
},
2019-03-02 22:35:43 +05:30
showReply: {
type: Boolean,
required: true,
},
2018-05-09 12:01:36 +05:30
canEdit: {
type: Boolean,
required: true,
},
canAwardEmoji: {
type: Boolean,
required: true,
},
canDelete: {
type: Boolean,
required: true,
},
2018-11-08 19:23:39 +05:30
canResolve: {
type: Boolean,
required: false,
default: false,
},
2018-05-09 12:01:36 +05:30
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,
},
},
computed: {
2020-06-23 00:09:42 +05:30
...mapGetters(['getUserDataByProp', 'getNoteableData']),
2018-05-09 12:01:36 +05:30
shouldShowActionsDropdown() {
return this.currentUserId && (this.canEdit || this.canReportAsAbuse);
},
2018-12-05 23:21:45 +05:30
showDeleteAction() {
return this.canDelete && !this.canReportAsAbuse && !this.noteUrl;
},
2018-05-09 12:01:36 +05:30
isAuthoredByCurrentUser() {
return this.authorId === this.currentUserId;
},
currentUserId() {
return this.getUserDataByProp('id');
},
2020-06-23 00:09:42 +05:30
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;
},
assignees() {
return this.getNoteableData.assignees || [];
},
isIssue() {
return this.targetType === 'issue';
},
2020-07-28 23:09:34 +05:30
canAssign() {
return this.getNoteableData.current_user?.can_update && this.isIssue;
},
2018-05-09 12:01:36 +05:30
},
methods: {
onEdit() {
this.$emit('handleEdit');
},
onDelete() {
this.$emit('handleDelete');
},
onResolve() {
this.$emit('handleResolve');
},
2019-07-07 11:18:12 +05:30
closeTooltip() {
this.$nextTick(() => {
this.$root.$emit('bv::hide::tooltip');
});
},
2020-06-23 00:09:42 +05:30
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) {
assignees = assignees.filter(assignee => assignee.id !== this.author.id);
} else {
assignees.push({ id: this.author.id });
}
if (this.targetType === 'issue') {
Api.updateIssue(project_id, iid, {
assignee_ids: assignees.map(assignee => assignee.id),
})
.then(() => this.handleAssigneeUpdate(assignees))
.catch(() => flash(__('Something went wrong while updating assignees')));
}
},
2018-05-09 12:01:36 +05:30
},
};
2018-03-17 18:26:18 +05:30
</script>
<template>
<div class="note-actions">
2019-02-15 15:39:39 +05:30
<span v-if="accessLevel" class="note-role user-access-role">{{ accessLevel }}</span>
<div v-if="canResolve" class="note-actions-item">
2018-03-27 19:54:05 +05:30
<button
2019-07-07 11:18:12 +05:30
ref="resolveButton"
2019-02-15 15:39:39 +05:30
v-gl-tooltip
2018-03-27 19:54:05 +05:30
:class="{ 'is-disabled': !resolvable, 'is-active': isResolved }"
:title="resolveButtonTitle"
:aria-label="resolveButtonTitle"
type="button"
2018-11-08 19:23:39 +05:30
class="line-resolve-btn note-action-button"
2019-02-15 15:39:39 +05:30
@click="onResolve"
>
2018-03-27 19:54:05 +05:30
<template v-if="!isResolving">
2019-09-04 21:01:54 +05:30
<icon :name="isResolved ? 'check-circle-filled' : 'check-circle'" />
2018-03-27 19:54:05 +05:30
</template>
2019-02-15 15:39:39 +05:30
<gl-loading-icon v-else inline />
2018-03-27 19:54:05 +05:30
</button>
</div>
2019-02-15 15:39:39 +05:30
<div v-if="canAwardEmoji" class="note-actions-item">
2018-03-17 18:26:18 +05:30
<a
2019-03-02 22:35:43 +05:30
v-gl-tooltip
2018-03-17 18:26:18 +05:30
:class="{ 'js-user-authored': isAuthoredByCurrentUser }"
class="note-action-button note-emoji-button js-add-award js-note-emoji"
href="#"
title="Add reaction"
2019-09-04 21:01:54 +05:30
data-position="right"
2018-03-17 18:26:18 +05:30
>
2019-12-21 20:55:43 +05:30
<icon class="link-highlight award-control-icon-neutral" name="slight-smile" />
<icon class="link-highlight award-control-icon-positive" name="smiley" />
<icon class="link-highlight award-control-icon-super-positive" name="smiley" />
2018-03-17 18:26:18 +05:30
</a>
</div>
2019-03-02 22:35:43 +05:30
<reply-button
2019-07-07 11:18:12 +05:30
v-if="showReply"
2019-03-02 22:35:43 +05:30
ref="replyButton"
class="js-reply-button"
2019-07-07 11:18:12 +05:30
@startReplying="$emit('startReplying')"
2019-03-02 22:35:43 +05:30
/>
2019-02-15 15:39:39 +05:30
<div v-if="canEdit" class="note-actions-item">
2018-03-17 18:26:18 +05:30
<button
2019-03-02 22:35:43 +05:30
v-gl-tooltip
2018-03-17 18:26:18 +05:30
type="button"
title="Edit comment"
2019-09-30 21:07:59 +05:30
class="note-action-button js-note-edit btn btn-transparent qa-note-edit-button"
2019-02-15 15:39:39 +05:30
@click="onEdit"
>
2019-12-21 20:55:43 +05:30
<icon name="pencil" class="link-highlight" />
2018-03-17 18:26:18 +05:30
</button>
</div>
2019-02-15 15:39:39 +05:30
<div v-if="showDeleteAction" class="note-actions-item">
2018-12-05 23:21:45 +05:30
<button
2019-03-02 22:35:43 +05:30
v-gl-tooltip
2018-12-05 23:21:45 +05:30
type="button"
title="Delete comment"
class="note-action-button js-note-delete btn btn-transparent"
@click="onDelete"
>
2019-02-15 15:39:39 +05:30
<icon name="remove" class="link-highlight" />
2018-12-05 23:21:45 +05:30
</button>
</div>
2019-02-15 15:39:39 +05:30
<div v-else-if="shouldShowActionsDropdown" class="dropdown more-actions note-actions-item">
2018-03-17 18:26:18 +05:30
<button
2019-03-02 22:35:43 +05:30
v-gl-tooltip
2018-03-17 18:26:18 +05:30
type="button"
title="More actions"
class="note-action-button more-actions-toggle btn btn-transparent"
data-toggle="dropdown"
2019-07-07 11:18:12 +05:30
@click="closeTooltip"
2019-02-15 15:39:39 +05:30
>
2019-12-21 20:55:43 +05:30
<icon class="icon" name="ellipsis_v" />
2018-03-17 18:26:18 +05:30
</button>
<ul class="dropdown-menu more-actions-dropdown dropdown-open-left">
<li v-if="canReportAsAbuse">
2019-09-04 21:01:54 +05:30
<a :href="reportAbusePath">{{ __('Report abuse to admin') }}</a>
2018-03-17 18:26:18 +05:30
</li>
2018-11-20 20:47:30 +05:30
<li v-if="noteUrl">
2018-11-08 19:23:39 +05:30
<button
:data-clipboard-text="noteUrl"
type="button"
2018-11-20 20:47:30 +05:30
class="btn-default btn-transparent js-btn-copy-note-link"
2018-11-08 19:23:39 +05:30
>
2018-12-13 13:39:08 +05:30
{{ __('Copy link') }}
2018-11-08 19:23:39 +05:30
</button>
</li>
2020-07-28 23:09:34 +05:30
<li v-if="canAssign">
2018-03-17 18:26:18 +05:30
<button
2020-07-28 23:09:34 +05:30
class="btn-default btn-transparent"
data-testid="assign-user"
2018-11-08 19:23:39 +05:30
type="button"
2020-07-28 23:09:34 +05:30
@click="assignUser"
2019-02-15 15:39:39 +05:30
>
2020-07-28 23:09:34 +05:30
{{ displayAssignUserText }}
2018-03-17 18:26:18 +05:30
</button>
</li>
2020-07-28 23:09:34 +05:30
<li v-if="canEdit">
2020-06-23 00:09:42 +05:30
<button
2020-07-28 23:09:34 +05:30
class="btn btn-transparent js-note-delete js-note-delete"
2020-06-23 00:09:42 +05:30
type="button"
2020-07-28 23:09:34 +05:30
@click.prevent="onDelete"
2020-06-23 00:09:42 +05:30
>
2020-07-28 23:09:34 +05:30
<span class="text-danger">{{ __('Delete comment') }}</span>
2020-06-23 00:09:42 +05:30
</button>
</li>
2018-03-17 18:26:18 +05:30
</ul>
</div>
</div>
</template>