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

delete_item.vue « components « custom_emoji « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9d13d40dc470fc4d8652b69371c8080c427d8230 (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
<script>
import * as Sentry from '@sentry/browser';
import { uniqueId } from 'lodash';
import { GlButton, GlTooltipDirective, GlModal, GlModalDirective, GlSprintf } from '@gitlab/ui';
import { createAlert } from '~/alert';
import { __ } from '~/locale';
import deleteCustomEmojiMutation from '../queries/delete_custom_emoji.mutation.graphql';

export default {
  name: 'DeleteItem',
  components: {
    GlButton,
    GlModal,
    GlSprintf,
  },
  directives: {
    GlTooltip: GlTooltipDirective,
    GlModal: GlModalDirective,
  },
  props: {
    emoji: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      isDeleting: false,
      modalId: uniqueId('delete-custom-emoji-'),
    };
  },
  methods: {
    showModal() {
      this.$refs['delete-modal'].show();
    },
    async onDelete() {
      this.isDeleting = true;

      try {
        await this.$apollo.mutate({
          mutation: deleteCustomEmojiMutation,
          variables: {
            id: this.emoji.id,
          },
          update: (cache) => {
            const cacheId = cache.identify(this.emoji);
            cache.evict({ id: cacheId });
          },
        });
      } catch (e) {
        createAlert(__('Failed to delete custom emoji. Please try again.'));
        Sentry.captureException(e);
      }
    },
  },
  actionPrimary: { text: __('Delete'), attributes: { variant: 'danger' } },
  actionSecondary: { text: __('Cancel'), attributes: { variant: 'default' } },
};
</script>

<template>
  <div>
    <gl-button
      v-gl-tooltip
      icon="remove"
      :aria-label="__('Delete custom emoji')"
      :title="__('Delete custom emoji')"
      :loading="isDeleting"
      data-testid="delete-button"
      @click="showModal"
    />
    <gl-modal
      ref="delete-modal"
      :title="__('Delete custom emoji')"
      :action-primary="$options.actionPrimary"
      :action-secondary="$options.actionSecondary"
      :modal-id="modalId"
      size="sm"
      @primary="onDelete"
    >
      <gl-sprintf
        :message="__('Are you sure you want to delete %{name}? This action cannot be undone.')"
      >
        <template #name
          ><strong>{{ emoji.name }}</strong></template
        >
      </gl-sprintf>
    </gl-modal>
  </div>
</template>