2021-05-26 12:10:41 +00:00
|
|
|
<script>
|
|
|
|
import { cloneDeep } from 'lodash';
|
2021-08-23 15:10:43 +00:00
|
|
|
import { __ } from '~/locale';
|
2021-05-26 12:10:41 +00:00
|
|
|
import FilteredSearch from '~/vue_shared/components/filtered_search_bar/filtered_search_bar_root.vue';
|
2021-08-23 15:10:43 +00:00
|
|
|
import { CREATED_DESC, CREATED_ASC, CONTACTED_DESC, CONTACTED_ASC } from '../constants';
|
2021-05-26 12:10:41 +00:00
|
|
|
|
|
|
|
const sortOptions = [
|
|
|
|
{
|
|
|
|
id: 1,
|
|
|
|
title: __('Created date'),
|
|
|
|
sortDirection: {
|
|
|
|
descending: CREATED_DESC,
|
|
|
|
ascending: CREATED_ASC,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: 2,
|
|
|
|
title: __('Last contact'),
|
|
|
|
sortDirection: {
|
|
|
|
descending: CONTACTED_DESC,
|
|
|
|
ascending: CONTACTED_ASC,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
FilteredSearch,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
validator(val) {
|
|
|
|
return Array.isArray(val?.filters) && typeof val?.sort === 'string';
|
|
|
|
},
|
|
|
|
},
|
2021-06-23 12:07:58 +00:00
|
|
|
namespace: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
2021-05-26 12:10:41 +00:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
// filtered_search_bar_root.vue may mutate the inital
|
|
|
|
// filters. Use `cloneDeep` to prevent those mutations
|
|
|
|
// from affecting this component
|
|
|
|
const { filters, sort } = cloneDeep(this.value);
|
|
|
|
return {
|
|
|
|
initialFilterValue: filters,
|
|
|
|
initialSortBy: sort,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onFilter(filters) {
|
|
|
|
const { sort } = this.value;
|
|
|
|
|
|
|
|
this.$emit('input', {
|
|
|
|
filters,
|
|
|
|
sort,
|
2021-06-02 00:09:56 +00:00
|
|
|
pagination: { page: 1 },
|
2021-05-26 12:10:41 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
onSort(sort) {
|
|
|
|
const { filters } = this.value;
|
|
|
|
|
|
|
|
this.$emit('input', {
|
|
|
|
filters,
|
|
|
|
sort,
|
2021-06-02 00:09:56 +00:00
|
|
|
pagination: { page: 1 },
|
2021-05-26 12:10:41 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
sortOptions,
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
<template>
|
2021-07-12 18:09:09 +00:00
|
|
|
<div>
|
|
|
|
<filtered-search
|
|
|
|
v-bind="$attrs"
|
|
|
|
:namespace="namespace"
|
|
|
|
recent-searches-storage-key="runners-search"
|
|
|
|
:sort-options="$options.sortOptions"
|
|
|
|
:initial-filter-value="initialFilterValue"
|
|
|
|
:initial-sort-by="initialSortBy"
|
|
|
|
:search-input-placeholder="__('Search or filter results...')"
|
|
|
|
data-testid="runners-filtered-search"
|
|
|
|
@onFilter="onFilter"
|
|
|
|
@onSort="onSort"
|
|
|
|
/>
|
2021-08-23 15:10:43 +00:00
|
|
|
<div class="gl-text-right" data-testid="runner-count">
|
|
|
|
<slot name="runner-count"></slot>
|
|
|
|
</div>
|
2021-07-12 18:09:09 +00:00
|
|
|
</div>
|
2021-05-26 12:10:41 +00:00
|
|
|
</template>
|