summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/badges/components/badge_list_row.vue
blob: 3343634ecad5e03db32329bc117cdad74c73827a (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
<script>
import { mapActions, mapState } from 'vuex';
import { GlLoadingIcon, GlIcon } from '@gitlab/ui';
import { s__ } from '~/locale';
import { PROJECT_BADGE } from '../constants';
import Badge from './badge.vue';

export default {
  name: 'BadgeListRow',
  components: {
    Badge,
    GlIcon,
    GlLoadingIcon,
  },
  props: {
    badge: {
      type: Object,
      required: true,
    },
  },
  computed: {
    ...mapState(['kind']),
    badgeKindText() {
      if (this.badge.kind === PROJECT_BADGE) {
        return s__('Badges|Project Badge');
      }

      return s__('Badges|Group Badge');
    },
    canEditBadge() {
      return this.badge.kind === this.kind;
    },
  },
  methods: {
    ...mapActions(['editBadge', 'updateBadgeInModal']),
  },
};
</script>

<template>
  <div class="gl-responsive-table-row-layout gl-responsive-table-row">
    <badge
      :image-url="badge.renderedImageUrl"
      :link-url="badge.renderedLinkUrl"
      class="table-section section-30"
    />
    <div class="table-section section-30">
      <label class="label-bold str-truncated mb-0">{{ badge.name }}</label>
      <span class="badge badge-pill">{{ badgeKindText }}</span>
    </div>
    <span class="table-section section-30 str-truncated">{{ badge.linkUrl }}</span>
    <div class="table-section section-10 table-button-footer">
      <div v-if="canEditBadge" class="table-action-buttons">
        <button
          :disabled="badge.isDeleting"
          class="btn btn-default gl-mr-3"
          type="button"
          @click="editBadge(badge)"
        >
          <gl-icon :size="16" :aria-label="__('Edit')" name="pencil" />
        </button>
        <button
          :disabled="badge.isDeleting"
          class="btn btn-danger"
          type="button"
          data-toggle="modal"
          data-target="#delete-badge-modal"
          @click="updateBadgeInModal(badge)"
        >
          <gl-icon :size="16" :aria-label="__('Delete')" name="remove" />
        </button>
        <gl-loading-icon v-show="badge.isDeleting" :inline="true" />
      </div>
    </div>
  </div>
</template>