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
|
<script>
import { GlBadge, GlTabs, GlTab } from '@gitlab/ui';
import { searchValidator } from '~/ci/runner/runner_search_utils';
import { formatNumber } from '~/locale';
import {
INSTANCE_TYPE,
GROUP_TYPE,
PROJECT_TYPE,
I18N_ALL_TYPES,
I18N_INSTANCE_TYPE,
I18N_GROUP_TYPE,
I18N_PROJECT_TYPE,
} from '../constants';
import RunnerCount from './stat/runner_count.vue';
const I18N_TAB_TITLES = {
[INSTANCE_TYPE]: I18N_INSTANCE_TYPE,
[GROUP_TYPE]: I18N_GROUP_TYPE,
[PROJECT_TYPE]: I18N_PROJECT_TYPE,
};
const TAB_COUNT_REF = 'tab-count';
export default {
components: {
GlBadge,
GlTabs,
GlTab,
RunnerCount,
},
props: {
runnerTypes: {
type: Array,
required: false,
default: () => [INSTANCE_TYPE, GROUP_TYPE, PROJECT_TYPE],
},
value: {
type: Object,
required: true,
validator: searchValidator,
},
countScope: {
type: String,
required: true,
},
countVariables: {
type: Object,
required: true,
},
},
computed: {
tabs() {
const tabs = this.runnerTypes.map((runnerType) => ({
title: I18N_TAB_TITLES[runnerType],
runnerType,
}));
// Always add a "All" tab that resets filters
return [
{
title: I18N_ALL_TYPES,
runnerType: null,
},
...tabs,
];
},
},
methods: {
onTabSelected({ runnerType }) {
this.$emit('input', {
...this.value,
runnerType,
pagination: { page: 1 },
});
},
isTabActive({ runnerType }) {
return runnerType === this.value.runnerType;
},
tabBadgeCountVariables(runnerType) {
return { ...this.countVariables, type: runnerType };
},
tabCount(count) {
if (typeof count === 'number') {
return formatNumber(count);
}
return '';
},
// Component API
refetch() {
// Refresh all of the counts here, can be called by parent component
this.$refs[TAB_COUNT_REF].forEach((countComponent) => {
countComponent.refetch();
});
},
},
TAB_COUNT_REF,
};
</script>
<template>
<gl-tabs v-bind="$attrs" data-testid="runner-type-tabs">
<gl-tab
v-for="tab in tabs"
:key="`${tab.runnerType}`"
:active="isTabActive(tab)"
@click="onTabSelected(tab)"
>
<template #title>
{{ tab.title }}
<runner-count
#default="{ count }"
:ref="$options.TAB_COUNT_REF"
:scope="countScope"
:variables="tabBadgeCountVariables(tab.runnerType)"
>
<gl-badge v-if="tabCount(count)" class="gl-ml-1" size="sm">
{{ tabCount(count) }}
</gl-badge>
</runner-count>
</template>
</gl-tab>
</gl-tabs>
</template>
|