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

badge_list.vue « components « badges « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 12c9662b30d98115c4157e7727335d0c0d2268fa (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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<script>
import {
  GlBadge,
  GlLoadingIcon,
  GlTable,
  GlPagination,
  GlButton,
  GlModalDirective,
} from '@gitlab/ui';
// eslint-disable-next-line no-restricted-imports
import { mapActions, mapState } from 'vuex';
import { __, s__ } from '~/locale';
import { GROUP_BADGE, PROJECT_BADGE, INITIAL_PAGE, PAGE_SIZE } from '../constants';
import Badge from './badge.vue';

export default {
  PAGE_SIZE,
  INITIAL_PAGE,
  name: 'BadgeList',
  components: {
    Badge,
    GlBadge,
    GlLoadingIcon,
    GlTable,
    GlPagination,
    GlButton,
  },
  directives: {
    GlModal: GlModalDirective,
  },
  i18n: {
    emptyGroupMessage: s__('Badges|This group has no badges, start by creating a new one above.'),
    emptyProjectMessage: s__(
      'Badges|This project has no badges, start by creating a new one above.',
    ),
  },
  data() {
    return {
      currentPage: INITIAL_PAGE,
    };
  },
  computed: {
    ...mapState(['badges', 'isLoading', 'kind']),
    hasNoBadges() {
      return !this.isLoading && (!this.badges || !this.badges.length);
    },
    isGroupBadge() {
      return this.kind === GROUP_BADGE;
    },
    showPagination() {
      return this.badges.length > PAGE_SIZE;
    },
    emptyMessage() {
      return this.isGroupBadge
        ? this.$options.i18n.emptyGroupMessage
        : this.$options.i18n.emptyProjectMessage;
    },
    fields() {
      return [
        {
          key: 'name',
          label: __('Name'),
          tdClass: 'gl-vertical-align-middle!',
        },
        {
          key: 'badge',
          label: __('Badge'),
          tdClass: 'gl-vertical-align-middle!',
        },
        {
          key: 'url',
          label: __('URL'),
          tdClass: 'gl-vertical-align-middle!',
        },
        {
          key: 'actions',
          label: __('Actions'),
          thClass: 'gl-text-right',
          tdClass: 'gl-text-right',
        },
      ];
    },
  },
  methods: {
    ...mapActions(['editBadge', 'updateBadgeInModal']),
    badgeKindText(item) {
      if (item.kind === PROJECT_BADGE) {
        return s__('Badges|Project Badge');
      }

      return s__('Badges|Group Badge');
    },
    canEditBadge(item) {
      return item.kind === this.kind;
    },
  },
};
</script>

<template>
  <div>
    <gl-loading-icon v-show="isLoading" size="md" />
    <div data-testid="badge-list-content">
      <gl-table
        :empty-text="emptyMessage"
        :fields="fields"
        :items="badges"
        :per-page="$options.PAGE_SIZE"
        :current-page="currentPage"
        stacked="md"
        show-empty
        data-testid="badge-list"
      >
        <template #cell(name)="{ item }">
          <label class="label-bold str-truncated mb-0">{{ item.name }}</label>
          <gl-badge size="sm">{{ badgeKindText(item) }}</gl-badge>
        </template>

        <template #cell(badge)="{ item }">
          <badge :image-url="item.renderedImageUrl" :link-url="item.renderedLinkUrl" />
        </template>

        <template #cell(url)="{ item }">
          {{ item.linkUrl }}
        </template>

        <template #cell(actions)="{ item }">
          <div v-if="canEditBadge(item)" class="table-action-buttons" data-testid="badge-actions">
            <gl-button
              v-gl-modal.edit-badge-modal
              :disabled="item.isDeleting"
              class="gl-mr-3"
              variant="default"
              icon="pencil"
              size="medium"
              :aria-label="__('Edit')"
              data-testid="edit-badge-button"
              @click="editBadge(item)"
            />
            <gl-button
              v-gl-modal.delete-badge-modal
              :disabled="item.isDeleting"
              category="secondary"
              variant="danger"
              icon="remove"
              size="medium"
              :aria-label="__('Delete')"
              data-testid="delete-badge"
              @click="updateBadgeInModal(item)"
            />
            <gl-loading-icon v-show="item.isDeleting" size="sm" :inline="true" />
          </div>
        </template>
      </gl-table>

      <gl-pagination
        v-if="showPagination"
        v-model="currentPage"
        :per-page="$options.PAGE_SIZE"
        :total-items="badges.length"
        :prev-text="__('Prev')"
        :next-text="__('Next')"
        :label-next-page="__('Go to next page')"
        :label-prev-page="__('Go to previous page')"
        align="center"
        class="gl-mt-5"
      />
    </div>
  </div>
</template>