debian-mirror-gitlab/app/assets/javascripts/releases/components/releases_sort.vue

63 lines
1.5 KiB
Vue
Raw Normal View History

2021-01-29 00:20:46 +05:30
<script>
import { GlSorting, GlSortingItem } from '@gitlab/ui';
import { mapState, mapActions } from 'vuex';
2021-09-04 01:27:46 +05:30
import { ASCENDING_ORDER, DESCENDING_ORDER, SORT_OPTIONS } from '../constants';
2021-01-29 00:20:46 +05:30
export default {
name: 'ReleasesSort',
components: {
GlSorting,
GlSortingItem,
},
computed: {
2021-04-29 21:17:54 +05:30
...mapState('index', {
2021-03-08 18:12:59 +05:30
orderBy: (state) => state.sorting.orderBy,
sort: (state) => state.sorting.sort,
2021-01-29 00:20:46 +05:30
}),
sortOptions() {
return SORT_OPTIONS;
},
sortText() {
2021-03-08 18:12:59 +05:30
const option = this.sortOptions.find((s) => s.orderBy === this.orderBy);
2021-01-29 00:20:46 +05:30
return option.label;
},
isSortAscending() {
2021-09-04 01:27:46 +05:30
return this.sort === ASCENDING_ORDER;
2021-01-29 00:20:46 +05:30
},
},
methods: {
2021-04-29 21:17:54 +05:30
...mapActions('index', ['setSorting']),
2021-01-29 00:20:46 +05:30
onDirectionChange() {
2021-09-04 01:27:46 +05:30
const sort = this.isSortAscending ? DESCENDING_ORDER : ASCENDING_ORDER;
2021-01-29 00:20:46 +05:30
this.setSorting({ sort });
this.$emit('sort:changed');
},
onSortItemClick(item) {
this.setSorting({ orderBy: item });
this.$emit('sort:changed');
},
isActiveSortItem(item) {
return this.orderBy === item;
},
},
};
</script>
<template>
<gl-sorting
:text="sortText"
:is-ascending="isSortAscending"
data-testid="releases-sort"
@sortDirectionChange="onDirectionChange"
>
<gl-sorting-item
v-for="item in sortOptions"
:key="item.orderBy"
:active="isActiveSortItem(item.orderBy)"
@click="onSortItemClick(item.orderBy)"
>
{{ item.label }}
</gl-sorting-item>
</gl-sorting>
</template>