summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/components/table/jobs_table_tabs.vue
blob: 27e3b8028b731d5d1bb19fe7e0c07e2908c8d457 (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
<script>
import { GlBadge, GlTab, GlTabs, GlLoadingIcon } from '@gitlab/ui';
import { s__ } from '~/locale';

export default {
  components: {
    GlBadge,
    GlTab,
    GlTabs,
    GlLoadingIcon,
  },
  inject: {
    jobStatuses: {
      default: {},
    },
  },
  props: {
    allJobsCount: {
      type: Number,
      required: true,
    },
    loading: {
      type: Boolean,
      required: true,
    },
  },
  computed: {
    tabs() {
      return [
        {
          text: s__('Jobs|All'),
          count: this.allJobsCount,
          scope: null,
          testId: 'jobs-all-tab',
          showBadge: true,
        },
        {
          text: s__('Jobs|Finished'),
          scope: [this.jobStatuses.success, this.jobStatuses.failed, this.jobStatuses.canceled],
          testId: 'jobs-finished-tab',
          showBadge: false,
        },
      ];
    },
    showLoadingIcon() {
      return this.loading && !this.allJobsCount;
    },
  },
};
</script>

<template>
  <gl-tabs content-class="gl-py-0">
    <gl-tab
      v-for="tab in tabs"
      :key="tab.text"
      :title-link-attributes="/* eslint-disable @gitlab/vue-no-new-non-primitive-in-template */ {
        'data-testid': tab.testId,
      } /* eslint-enable @gitlab/vue-no-new-non-primitive-in-template */"
      @click="$emit('fetchJobsByStatus', tab.scope)"
    >
      <template #title>
        <span>{{ tab.text }}</span>
        <gl-loading-icon v-if="showLoadingIcon && tab.showBadge" class="gl-ml-2" />

        <gl-badge v-else-if="tab.showBadge" size="sm" class="gl-tab-counter-badge">
          {{ tab.count }}
        </gl-badge>
      </template>
    </gl-tab>
  </gl-tabs>
</template>