Skip to content

Commit

Permalink
Merge pull request #25 from webitel/feature/contacts-variables-search
Browse files Browse the repository at this point in the history
feature: variables search added to contacts list [WTEL-3888]
  • Loading branch information
dlohvinov authored Oct 23, 2023
2 parents f7fa313 + 6173ff3 commit 5bfcee2
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 8 deletions.
22 changes: 16 additions & 6 deletions src/modules/contacts/api/ContactsAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const getList = async (params) => {
} else if (params[SearchMode.ABOUT]) {
searchValue = params[SearchMode.ABOUT];
searchKey = SearchMode.ABOUT;
} else if (params[SearchMode.VARIABLES]) {
searchValue = params[SearchMode.VARIABLES];
searchKey = SearchMode.VARIABLES;
}

const changedParams = {
Expand All @@ -50,6 +53,17 @@ const getList = async (params) => {
qin: searchKey,
};

const transformations = [
sanitize(fieldsToSend),
merge(getDefaultGetParams()),
camelToSnake(),
];

// This code needed for adding starToSearch method to applyTransform while searchKey !== SearchMode.VARIABLES because '*' in variables search mode brokes backend logic.
if (searchKey !== SearchMode.VARIABLES) {
transformations.push(starToSearch('q'));
}

const {
page,
size,
Expand All @@ -58,12 +72,8 @@ const getList = async (params) => {
fields,
id,
qin,
} = applyTransform(changedParams, [
sanitize(fieldsToSend),
merge(getDefaultGetParams()),
starToSearch('q'),
camelToSnake(),
]);
} = applyTransform(changedParams, transformations);

try {
const response = await service.searchContacts(
page,
Expand Down
31 changes: 29 additions & 2 deletions src/modules/contacts/modules/filters/components/filter-search.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<template>
<form
class="filter-search"
@submit.prevent>
@submit.prevent
>
<wt-search-bar
:hint="searchBarHint"
:v="v$.localValue"
:value="localValue"
debounce
@search="setLocalValue($event)"
>
<template v-slot:additional-actions>
<template v-slot:additional-actions="options">
<wt-context-menu
:options="searchModeOptions"
@click="changeMode($event.option)"
Expand All @@ -16,6 +19,7 @@
<wt-tooltip>
<template v-slot:activator>
<wt-icon-btn
:color="options.invalid ? 'error' : 'default'"
icon="filter"
></wt-icon-btn>
</template>
Expand All @@ -36,6 +40,7 @@
</template>

<script setup>
import { useVuelidate } from '@vuelidate/core';
import getNamespacedState from '@webitel/ui-sdk/src/store/helpers/getNamespacedState';
import {
watch,
Expand All @@ -45,6 +50,7 @@ import {
} from 'vue';
import { useI18n } from 'vue-i18n';
import { useStore } from 'vuex';
import variableSearchValidator from '@webitel/ui-sdk/src/validators/variableSearchValidator';
import SearchMode from '../enums/SearchMode.enum';
const props = defineProps({
Expand Down Expand Up @@ -72,12 +78,33 @@ const searchModeOptions = computed(() => [
value: SearchMode.ABOUT,
text: t('vocabulary.description'),
},
{
value: SearchMode.VARIABLES,
text: t('vocabulary.variables', 1),
},
]);
const filterQuery = ref(SearchMode.NAME);
const filterSchema = computed(() => (
getNamespacedState(store.state, `${props.namespace}`)[filterQuery.value]));
const searchBarHint = computed(() => {
switch (filterQuery.value) {
case SearchMode.VARIABLES:
return t('webitelUI.searchBar.variableSearchHint');
default:
return null;
}
});
const v$ = useVuelidate(computed(() => {
return {
localValue: filterQuery.value === SearchMode.VARIABLES ? { variableSearchValidator } : {},
};
}), { localValue }, { $autoDirty: true });
v$.value.$touch();
function getValue(filter) {
return store.getters[`${props.namespace}/GET_FILTER`](filter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const SearchMode = Object.freeze({
NAME: 'name',
LABELS: 'labels',
ABOUT: 'about',
VARIABLES: 'variables',
});

export default SearchMode;
1 change: 1 addition & 0 deletions src/modules/contacts/modules/filters/store/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const state = {
[SearchMode.NAME]: new BaseFilterSchema(),
[SearchMode.LABELS]: new BaseFilterSchema(),
[SearchMode.ABOUT]: new BaseFilterSchema(),
[SearchMode.VARIABLES]: new BaseFilterSchema(),
};

const getters = {
Expand Down

0 comments on commit 5bfcee2

Please sign in to comment.