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
|
<script>
import { mapState, mapActions } from 'vuex';
import { GlFormRadioGroup, GlFormRadio } from '@gitlab/ui';
import { sprintf, s__ } from '~/locale';
export default {
name: 'RadioFilter',
components: {
GlFormRadioGroup,
GlFormRadio,
},
props: {
filterData: {
type: Object,
required: true,
},
},
computed: {
...mapState(['query']),
ANY() {
return this.filterData.filters.ANY;
},
scope() {
return this.query.scope;
},
initialFilter() {
return this.query[this.filterData.filterParam];
},
filter() {
return this.initialFilter || this.ANY.value;
},
filtersArray() {
return this.filterData.filterByScope[this.scope];
},
selectedFilter: {
get() {
if (this.filtersArray.some(({ value }) => value === this.filter)) {
return this.filter;
}
return this.ANY.value;
},
set(value) {
this.setQuery({ key: this.filterData.filterParam, value });
},
},
},
methods: {
...mapActions(['setQuery']),
radioLabel(filter) {
return filter.value === this.ANY.value
? sprintf(s__('Any %{header}'), { header: this.filterData.header.toLowerCase() })
: filter.label;
},
},
};
</script>
<template>
<div>
<h5 class="gl-mt-0">{{ filterData.header }}</h5>
<gl-form-radio-group v-model="selectedFilter">
<gl-form-radio v-for="f in filtersArray" :key="f.value" :value="f.value">
{{ radioLabel(f) }}
</gl-form-radio>
</gl-form-radio-group>
</div>
</template>
|