summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/registry/explorer/components/details_page/tags_list.vue
blob: 2844b4ffde321de090019b0992b74fc8b6b8c735 (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 { GlButton } from '@gitlab/ui';
import TagsListRow from './tags_list_row.vue';
import { REMOVE_TAGS_BUTTON_TITLE, TAGS_LIST_TITLE } from '../../constants/index';

export default {
  components: {
    GlButton,
    TagsListRow,
  },
  props: {
    tags: {
      type: Array,
      required: false,
      default: () => [],
    },
    isMobile: {
      type: Boolean,
      default: true,
      required: false,
    },
  },
  i18n: {
    REMOVE_TAGS_BUTTON_TITLE,
    TAGS_LIST_TITLE,
  },
  data() {
    return {
      selectedItems: {},
    };
  },
  computed: {
    hasSelectedItems() {
      return this.tags.some(tag => this.selectedItems[tag.name]);
    },
    showMultiDeleteButton() {
      return this.tags.some(tag => tag.destroy_path) && !this.isMobile;
    },
  },
  methods: {
    updateSelectedItems(name) {
      this.$set(this.selectedItems, name, !this.selectedItems[name]);
    },
  },
};
</script>

<template>
  <div>
    <div class="gl-display-flex gl-justify-content-space-between gl-mb-3">
      <h5 data-testid="list-title">
        {{ $options.i18n.TAGS_LIST_TITLE }}
      </h5>

      <gl-button
        v-if="showMultiDeleteButton"
        :disabled="!hasSelectedItems"
        category="secondary"
        variant="danger"
        @click="$emit('delete', selectedItems)"
      >
        {{ $options.i18n.REMOVE_TAGS_BUTTON_TITLE }}
      </gl-button>
    </div>
    <tags-list-row
      v-for="(tag, index) in tags"
      :key="tag.path"
      :tag="tag"
      :first="index === 0"
      :selected="selectedItems[tag.name]"
      :is-mobile="isMobile"
      @select="updateSelectedItems(tag.name)"
      @delete="$emit('delete', { [tag.name]: true })"
    />
  </div>
</template>