Welcome to mirror list, hosted at ThFree Co, Russian Federation.

work_item_note_awards_list.vue « notes « components « work_items « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3c30c204ab64cf39b36b208ead75c55af9825d43 (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
89
90
91
92
93
94
95
<script>
import * as Sentry from '@sentry/browser';
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import AwardsList from '~/vue_shared/components/awards_list.vue';
import { getMutation, optimisticAwardUpdate } from '../../notes/award_utils';

export default {
  components: {
    AwardsList,
  },
  inject: ['fullPath'],
  props: {
    workItemIid: {
      type: String,
      required: true,
    },
    note: {
      type: Object,
      required: true,
    },
    isModal: {
      type: Boolean,
      required: false,
      default: false,
    },
  },
  computed: {
    awardsListBoundary() {
      return this.isModal ? '.modal-body' : '';
    },
    awards() {
      return this.note.awardEmoji.nodes.map((award) => {
        return {
          ...award,
          user: {
            ...award.user,
            id: getIdFromGraphQLId(award.user.id),
          },
        };
      });
    },
    hasAwardEmojiPermission() {
      return this.note.userPermissions.awardEmoji;
    },
    currentUserId() {
      return window.gon.current_user_id;
    },
  },
  methods: {
    async handleAward(name) {
      if (!this.hasAwardEmojiPermission) {
        return;
      }

      const { mutation, mutationName, errorMessage } = getMutation({ note: this.note, name });

      try {
        await this.$apollo.mutate({
          mutation,
          variables: {
            awardableId: this.note.id,
            name,
          },
          optimisticResponse: {
            [mutationName]: {
              errors: [],
            },
          },
          update: optimisticAwardUpdate({
            note: this.note,
            name,
            fullPath: this.fullPath,
            workItemIid: this.workItemIid,
          }),
        });
      } catch (error) {
        this.$emit('error', errorMessage);
        Sentry.captureException(error);
      }
    },
  },
};
</script>

<template>
  <awards-list
    v-if="awards.length"
    :awards="awards"
    :can-award-emoji="hasAwardEmojiPermission"
    :current-user-id="currentUserId"
    :boundary="awardsListBoundary"
    class="gl-px-2"
    @award="handleAward($event)"
  />
</template>