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
|
<script>
import { GlCollapsibleListbox, GlButton, GlIcon, GlSprintf, GlButtonGroup } from '@gitlab/ui';
import { mapActions, mapState } from 'vuex';
import LocalStorageSync from '~/vue_shared/components/local_storage_sync.vue';
import { __ } from '~/locale';
import { MR_FILTER_OPTIONS } from '~/notes/constants';
export default {
components: {
GlCollapsibleListbox,
GlButton,
GlButtonGroup,
GlIcon,
GlSprintf,
LocalStorageSync,
},
data() {
return {
selectedFilters: MR_FILTER_OPTIONS.map((f) => f.value),
};
},
computed: {
...mapState({
mergeRequestFilters: (state) => state.notes.mergeRequestFilters,
discussionSortOrder: (state) => state.notes.discussionSortOrder,
}),
selectedFilterText() {
const { length } = this.mergeRequestFilters;
if (length === 0) return __('None');
const firstSelected = MR_FILTER_OPTIONS.find(
({ value }) => this.mergeRequestFilters[0] === value,
);
if (length === MR_FILTER_OPTIONS.length) {
return __('All activity');
} else if (length > 1) {
return `%{strongStart}${firstSelected.text}%{strongEnd} +${length - 1} more`;
}
return firstSelected.text;
},
isSortAsc() {
return this.discussionSortOrder === 'asc';
},
sortIcon() {
return this.isSortAsc ? 'sort-lowest' : 'sort-highest';
},
},
methods: {
...mapActions(['updateMergeRequestFilters', 'setDiscussionSortDirection']),
updateSortDirection() {
this.setDiscussionSortDirection({
direction: this.isSortAsc ? 'desc' : 'asc',
});
},
applyFilters() {
this.updateMergeRequestFilters(this.selectedFilters);
},
localSyncFilters(filters) {
this.updateMergeRequestFilters(filters);
this.selectedFilters = filters;
},
deselectAll() {
this.selectedFilters = [];
},
selectAll() {
this.selectedFilters = MR_FILTER_OPTIONS.map((f) => f.value);
},
},
MR_FILTER_OPTIONS,
};
</script>
<template>
<div>
<local-storage-sync
:value="discussionSortOrder"
storage-key="sort_direction_merge_request"
as-string
@input="setDiscussionSortDirection({ direction: $event })"
/>
<local-storage-sync
:value="mergeRequestFilters"
storage-key="mr_activity_filters"
@input="localSyncFilters"
/>
<gl-button-group>
<gl-collapsible-listbox
v-model="selectedFilters"
:items="$options.MR_FILTER_OPTIONS"
:header-text="__('Filter activity')"
:show-select-all-button-label="__('Select all')"
:reset-button-label="__('Deselect all')"
multiple
placement="right"
@hidden="applyFilters"
@reset="deselectAll"
@select-all="selectAll"
>
<template #toggle>
<gl-button class="gl-rounded-top-right-none! gl-rounded-bottom-right-none!">
<gl-sprintf :message="selectedFilterText">
<template #strong="{ content }">
<strong>{{ content }}</strong>
</template>
</gl-sprintf>
<gl-icon name="chevron-down" />
</gl-button>
</template>
<template #list-item="{ item }">
<strong v-if="item.value === '*'">{{ item.text }}</strong>
<span v-else>{{ item.text }}</span>
</template>
</gl-collapsible-listbox>
<gl-button :icon="sortIcon" @click="updateSortDirection" />
</gl-button-group>
</div>
</template>
|