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

group_filter.vue « components « topbar « search « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e5edb21792a48ba278b4eaa27adb644d6149c4c1 (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
<script>
import { isEmpty } from 'lodash';
import { mapState, mapActions, mapGetters } from 'vuex';
import { visitUrl, setUrlParams } from '~/lib/utils/url_utility';
import { ANY_OPTION, GROUP_DATA, PROJECT_DATA } from '../constants';
import SearchableDropdown from './searchable_dropdown.vue';

export default {
  name: 'GroupFilter',
  components: {
    SearchableDropdown,
  },
  props: {
    initialData: {
      type: Object,
      required: false,
      default: () => ({}),
    },
  },
  computed: {
    ...mapState(['query', 'groups', 'fetchingGroups']),
    ...mapGetters(['frequentGroups']),
    selectedGroup() {
      return isEmpty(this.initialData) ? ANY_OPTION : this.initialData;
    },
  },
  created() {
    // This tracks groups searched via the top nav search bar
    if (this.query.nav_source === 'navbar' && this.initialData?.id) {
      this.setFrequentGroup(this.initialData);
    }
  },
  methods: {
    ...mapActions(['fetchGroups', 'setFrequentGroup', 'loadFrequentGroups']),
    handleGroupChange(group) {
      // If group.id is null we are clearing the filter and don't need to store that in LS.
      if (group.id) {
        this.setFrequentGroup(group);
      }

      visitUrl(
        setUrlParams({
          [GROUP_DATA.queryParam]: group.id,
          [PROJECT_DATA.queryParam]: null,
          nav_source: null,
        }),
      );
    },
  },
  GROUP_DATA,
};
</script>

<template>
  <searchable-dropdown
    data-testid="group-filter"
    :header-text="$options.GROUP_DATA.headerText"
    :name="$options.GROUP_DATA.name"
    :full-name="$options.GROUP_DATA.fullName"
    :loading="fetchingGroups"
    :selected-item="selectedGroup"
    :items="groups"
    :frequent-items="frequentGroups"
    @first-open="loadFrequentGroups"
    @search="fetchGroups"
    @change="handleGroupChange"
  />
</template>