summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/packages_and_registries/package_registry/components/list/package_search.vue
blob: 280d292ce0bddfccc13ba1b128a0dab6d11bcd0c (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
<script>
import { mapState, mapActions } from 'vuex';
import { s__ } from '~/locale';
import { sortableFields } from '~/packages/list/utils';
import { OPERATOR_IS_ONLY } from '~/vue_shared/components/filtered_search_bar/constants';
import RegistrySearch from '~/vue_shared/components/registry/registry_search.vue';
import UrlSync from '~/vue_shared/components/url_sync.vue';
import PackageTypeToken from './tokens/package_type_token.vue';

export default {
  tokens: [
    {
      type: 'type',
      icon: 'package',
      title: s__('PackageRegistry|Type'),
      unique: true,
      token: PackageTypeToken,
      operators: OPERATOR_IS_ONLY,
    },
  ],
  components: { RegistrySearch, UrlSync },
  computed: {
    ...mapState({
      isGroupPage: (state) => state.config.isGroupPage,
      sorting: (state) => state.sorting,
      filter: (state) => state.filter,
    }),
    sortableFields() {
      return sortableFields(this.isGroupPage);
    },
  },
  methods: {
    ...mapActions(['setSorting', 'setFilter']),
    updateSorting(newValue) {
      this.setSorting(newValue);
      this.$emit('update');
    },
  },
};
</script>

<template>
  <url-sync>
    <template #default="{ updateQuery }">
      <registry-search
        :filter="filter"
        :sorting="sorting"
        :tokens="$options.tokens"
        :sortable-fields="sortableFields"
        @sorting:changed="updateSorting"
        @filter:changed="setFilter"
        @filter:submit="$emit('update')"
        @query:changed="updateQuery"
      />
    </template>
  </url-sync>
</template>