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

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

106 lines
2.4 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: {
2022-07-16 23:28:13 +05:30
addAttentionRequest: __('Add attention request'),
removeAttentionRequest: __('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) {
2022-07-16 23:28:13 +05:30
return this.$options.i18n.removeAttentionRequest;
2022-05-07 20:08:51 +05:30
}
return this.$options.i18n.attentionRequestedNoPermission;
}
if (this.user.can_update_merge_request) {
2022-07-16 23:28:13 +05:30
return this.$options.i18n.addAttentionRequest;
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
},
2022-07-16 23:28:13 +05:30
request() {
const state = {
2022-07-23 23:45:48 +05:30
selected: false,
2022-07-16 23:28:13 +05:30
icon: 'attention',
direction: 'add',
};
if (this.user.attention_requested) {
Object.assign(state, {
2022-07-23 23:45:48 +05:30
selected: true,
2022-07-16 23:28:13 +05:30
icon: 'attention-solid',
direction: 'remove',
});
}
return state;
},
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,
2022-07-16 23:28:13 +05:30
direction: this.request.direction,
2021-12-11 22:18:48 +05:30
});
},
toggleAttentionRequiredComplete() {
this.loading = false;
},
},
};
</script>
<template>
2022-06-21 17:19:12 +05:30
<div>
<span
v-gl-tooltip.left.viewport="tooltipTitle"
class="gl-display-inline-block js-attention-request-toggle"
>
<gl-button
:loading="loading"
2022-07-23 23:45:48 +05:30
:selected="request.selected"
2022-07-16 23:28:13 +05:30
:icon="request.icon"
2022-06-21 17:19:12 +05:30
:aria-label="tooltipTitle"
:class="{ 'gl-pointer-events-none': !user.can_update_merge_request }"
size="small"
category="tertiary"
@click="toggleAttentionRequired"
/>
</span>
</div>
2021-12-11 22:18:48 +05:30
</template>