summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/sidebar/components/attention_requested_toggle.vue
blob: 6ba88939373be1d6c935a776152f461fb7db1504 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<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'),
    attentionRequestedNoPermission: __('Attention requested'),
    noAttentionRequestedNoPermission: __('No attention request'),
  },
  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) {
        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;
      }

      return this.$options.i18n.noAttentionRequestedNoPermission;
    },
  },
  methods: {
    toggleAttentionRequired() {
      if (this.loading || !this.user.can_update_merge_request) return;

      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>
  <span
    v-gl-tooltip.left.viewport="tooltipTitle"
    class="gl-display-inline-block js-attention-request-toggle"
  >
    <gl-button
      :loading="loading"
      :variant="user.attention_requested ? 'warning' : 'default'"
      :icon="user.attention_requested ? 'attention-solid' : 'attention'"
      :aria-label="tooltipTitle"
      :class="{ 'gl-pointer-events-none': !user.can_update_merge_request }"
      size="small"
      category="tertiary"
      @click="toggleAttentionRequired"
    />
  </span>
</template>