debian-mirror-gitlab/app/assets/javascripts/sidebar/components/attention_requested_toggle.vue

89 lines
2.3 KiB
Vue
Raw Normal View History

2021-12-11 22:18:48 +05:30
<script>
import { GlButton, GlTooltipDirective } from '@gitlab/ui';
import { __ } from '~/locale';
import { BV_HIDE_TOOLTIP } from '~/lib/utils/constants';
export default {
i18n: {
attentionRequestedReviewer: __('Request attention to review'),
attentionRequestedAssignee: __('Request attention'),
removeAttentionRequested: __('Remove attention request'),
2022-05-07 20:08:51 +05:30
attentionRequestedNoPermission: __('Attention requested'),
noAttentionRequestedNoPermission: __('No attention request'),
2021-12-11 22:18:48 +05:30
},
components: {
GlButton,
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
type: {
type: String,
required: true,
},
user: {
type: Object,
required: true,
},
},
data() {
return {
loading: false,
};
},
computed: {
tooltipTitle() {
if (this.user.attention_requested) {
2022-05-07 20:08:51 +05:30
if (this.user.can_update_merge_request) {
return this.$options.i18n.removeAttentionRequested;
}
return this.$options.i18n.attentionRequestedNoPermission;
}
if (this.user.can_update_merge_request) {
return this.type === 'reviewer'
? this.$options.i18n.attentionRequestedReviewer
: this.$options.i18n.attentionRequestedAssignee;
2021-12-11 22:18:48 +05:30
}
2022-05-07 20:08:51 +05:30
return this.$options.i18n.noAttentionRequestedNoPermission;
2021-12-11 22:18:48 +05:30
},
},
methods: {
toggleAttentionRequired() {
2022-05-07 20:08:51 +05:30
if (this.loading || !this.user.can_update_merge_request) return;
2021-12-11 22:18:48 +05:30
this.$root.$emit(BV_HIDE_TOOLTIP);
this.loading = true;
this.$emit('toggle-attention-requested', {
user: this.user,
callback: this.toggleAttentionRequiredComplete,
});
},
toggleAttentionRequiredComplete() {
this.loading = false;
},
},
};
</script>
<template>
2022-05-07 20:08:51 +05:30
<span
v-gl-tooltip.left.viewport="tooltipTitle"
class="gl-display-inline-block js-attention-request-toggle"
>
2021-12-11 22:18:48 +05:30
<gl-button
:loading="loading"
:variant="user.attention_requested ? 'warning' : 'default'"
2022-01-26 12:08:38 +05:30
:icon="user.attention_requested ? 'attention-solid' : 'attention'"
2021-12-11 22:18:48 +05:30
:aria-label="tooltipTitle"
2022-05-07 20:08:51 +05:30
:class="{ 'gl-pointer-events-none': !user.can_update_merge_request }"
2021-12-11 22:18:48 +05:30
size="small"
category="tertiary"
@click="toggleAttentionRequired"
/>
</span>
</template>