Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sort_dropdown.vue « filter_sort « components « members « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9fa8772faf42edc34b26cb54959685aeab9cc54b (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
73
74
75
76
77
<script>
import { GlSorting, GlSortingItem } from '@gitlab/ui';
import { mapState } from 'vuex';
import { visitUrl } from '~/lib/utils/url_utility';
import { FIELDS } from '~/members/constants';
import { parseSortParam, buildSortHref } from '~/members/utils';

export default {
  name: 'SortDropdown',
  components: { GlSorting, GlSortingItem },
  computed: {
    ...mapState(['tableSortableFields', 'filteredSearchBar']),
    sort() {
      return parseSortParam(this.tableSortableFields);
    },
    activeOption() {
      return FIELDS.find((field) => field.key === this.sort.sortByKey);
    },
    activeOptionLabel() {
      return this.activeOption?.label;
    },
    isAscending() {
      return !this.sort.sortDesc;
    },
    filteredOptions() {
      return FIELDS.filter(
        (field) => this.tableSortableFields.includes(field.key) && field.sort,
      ).map((field) => ({
        key: field.key,
        label: field.label,
        href: buildSortHref({
          sortBy: field.key,
          sortDesc: false,
          filteredSearchBarTokens: this.filteredSearchBar.tokens,
          filteredSearchBarSearchParam: this.filteredSearchBar.searchParam,
        }),
      }));
    },
  },
  methods: {
    isActive(key) {
      return this.activeOption.key === key;
    },
    handleSortDirectionChange() {
      visitUrl(
        buildSortHref({
          sortBy: this.activeOption.key,
          sortDesc: !this.sort.sortDesc,
          filteredSearchBarTokens: this.filteredSearchBar.tokens,
          filteredSearchBarSearchParam: this.filteredSearchBar.searchParam,
        }),
      );
    },
  },
};
</script>

<template>
  <gl-sorting
    class="gl-display-flex"
    dropdown-class="gl-w-full"
    data-testid="members-sort-dropdown"
    :text="activeOptionLabel"
    :is-ascending="isAscending"
    :sort-direction-tool-tip="__('Sort direction')"
    @sortDirectionChange="handleSortDirectionChange"
  >
    <gl-sorting-item
      v-for="option in filteredOptions"
      :key="option.key"
      :href="option.href"
      :active="isActive(option.key)"
    >
      {{ option.label }}
    </gl-sorting-item>
  </gl-sorting>
</template>