summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/saved_replies/components/list_item.vue
blob: 774ac745925adfe6ac6ac75a3953c510c3e00e52 (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
<script>
import { uniqueId } from 'lodash';
import { GlButton, GlModal, GlModalDirective, GlSprintf, GlTooltipDirective } from '@gitlab/ui';
import { __ } from '~/locale';
import deleteSavedReplyMutation from '../queries/delete_saved_reply.mutation.graphql';

export default {
  components: {
    GlButton,
    GlModal,
    GlSprintf,
  },
  directives: {
    GlModal: GlModalDirective,
    GlTooltip: GlTooltipDirective,
  },
  props: {
    reply: {
      type: Object,
      required: true,
    },
  },
  data() {
    return {
      isDeleting: false,
      modalId: uniqueId('delete-saved-reply-'),
    };
  },
  methods: {
    onDelete() {
      this.isDeleting = true;

      this.$apollo.mutate({
        mutation: deleteSavedReplyMutation,
        variables: {
          id: this.reply.id,
        },
        update: (cache) => {
          const cacheId = cache.identify(this.reply);
          cache.evict({ id: cacheId });
        },
      });
    },
  },
  actionPrimary: { text: __('Delete'), attributes: { variant: 'danger' } },
  actionSecondary: { text: __('Cancel'), attributes: { variant: 'default' } },
};
</script>

<template>
  <li class="gl-mb-5">
    <div class="gl-display-flex gl-align-items-center">
      <strong>{{ reply.name }}</strong>
      <div class="gl-ml-auto">
        <gl-button
          v-gl-modal="modalId"
          v-gl-tooltip
          icon="remove"
          :aria-label="__('Delete')"
          :title="__('Delete')"
          variant="danger"
          category="secondary"
          data-testid="saved-reply-delete-btn"
          :loading="isDeleting"
        />
      </div>
    </div>
    <div class="gl-mt-3 gl-font-monospace">{{ reply.content }}</div>
    <gl-modal
      :title="__('Delete saved reply')"
      :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>{{ reply.name }}</strong></template
        >
      </gl-sprintf>
    </gl-modal>
  </li>
</template>