feat(v4): Add new conversation filters component (#10502)

Co-authored-by: Pranav <pranav@chatwoot.com>
Co-authored-by: Pranav <pranavrajs@gmail.com>
This commit is contained in:
Shivam Mishra
2024-11-28 09:35:54 +05:30
committed by GitHub
parent 94c918e468
commit 25c61aba25
20 changed files with 1039 additions and 100 deletions

View File

@@ -1,7 +1,33 @@
<script setup>
import { computed } from 'vue';
const { strong } = defineProps({
// Use strong prop when this dropdown is stacked inside another dropdown
// Chrome has issues with stacked backdrop-blur, so we need an extra blur layer when stacked
// Also, stacked dropdowns should have a strong border
strong: {
type: Boolean,
default: false,
},
});
const borderClass = computed(() => {
return strong ? 'border-n-strong' : 'border-n-weak';
});
const beforeClass = computed(() => {
if (!strong) return '';
// Add extra blur layer only when strong prop is true, as a hack for Chrome's stacked backdrop-blur limitation
// https://issues.chromium.org/issues/40835530
return "before:content-['\x00A0'] before:absolute before:bottom-0 before:left-0 before:w-full before:h-full before:backdrop-contrast-70 before:backdrop-blur-sm before:z-0 [&>*]:relative";
});
</script>
<template>
<div class="absolute">
<ul
class="text-sm bg-n-alpha-3 backdrop-blur-[100px] border border-n-weak rounded-xl shadow-sm py-2 n-dropdown-body gap-2 grid list-none px-2 reset-base"
class="text-sm bg-n-alpha-3 backdrop-blur-[100px] border rounded-xl shadow-sm py-2 n-dropdown-body gap-2 grid list-none px-2 reset-base relative"
:class="[borderClass, beforeClass]"
>
<slot />
</ul>

View File

@@ -27,8 +27,8 @@ const componentIs = computed(() => {
const triggerClick = () => {
if (props.click) {
props.click();
if (!props.preserveOpen) closeMenu();
}
if (!props.preserveOpen) closeMenu();
};
</script>

View File

@@ -1,5 +1,5 @@
<script setup>
import { ref } from 'vue';
import { ref, useTemplateRef } from 'vue';
import ConditionRow from './ConditionRow.vue';
import Button from 'next/button/Button.vue';
import { filterTypes } from './fixtures/filterTypes.js';
@@ -12,6 +12,7 @@ const DEFAULT_FILTER = {
};
const filters = ref([{ ...DEFAULT_FILTER }]);
const conditionsRef = useTemplateRef('conditionsRef');
const removeFilter = index => {
filters.value.splice(index, 1);
@@ -22,6 +23,10 @@ const showQueryOperator = true;
const addFilter = () => {
filters.value.push({ ...DEFAULT_FILTER });
};
const saveFilter = () => {
console.log(conditionsRef.value.every(condition => condition.validate()));
};
</script>
<template>
@@ -33,6 +38,7 @@ const addFilter = () => {
<template v-for="(filter, index) in filters" :key="`filter-${index}`">
<ConditionRow
v-if="index === 0"
ref="conditionsRef"
v-model:attribute-key="filter.attributeKey"
v-model:filter-operator="filter.filterOperator"
v-model:values="filter.values"
@@ -43,6 +49,7 @@ const addFilter = () => {
<ConditionRow
v-else
ref="conditionsRef"
v-model:attribute-key="filter.attributeKey"
v-model:filter-operator="filter.filterOperator"
v-model:values="filter.values"
@@ -52,7 +59,10 @@ const addFilter = () => {
@remove="removeFilter(index)"
/>
</template>
<Button sm label="Add Filter" @click="addFilter" />
<div class="flex gap-3 mt-2">
<Button sm ghost label="Add Filter" @click="addFilter" />
<Button sm label="Save Filter" @click="saveFilter" />
</div>
</div>
</Story>
</template>

View File

@@ -6,6 +6,7 @@ import FilterSelect from './inputs/FilterSelect.vue';
import MultiSelect from './inputs/MultiSelect.vue';
import SingleSelect from './inputs/SingleSelect.vue';
import { useSnakeCase } from 'dashboard/composables/useTransformKeys';
import { validateSingleFilter } from 'dashboard/helper/validations.js';
// filterTypes: import('vue').ComputedRef<FilterType[]>
@@ -91,11 +92,14 @@ const booleanOptions = computed(() => [
]);
const validationError = computed(() => {
return validateSingleFilter({
attributeKey: attributeKey.value,
filter_operator: filterOperator.value,
values: values.value,
});
// TOOD: Migrate validateSingleFilter to use camelcase and then remove useSnakeCase here too
return validateSingleFilter(
useSnakeCase({
attributeKey: attributeKey.value,
filterOperator: filterOperator.value,
values: values.value,
})
);
});
const resetModelOnAttributeKeyChange = newAttributeKey => {

View File

@@ -0,0 +1,175 @@
<script setup>
import { useTemplateRef, onBeforeUnmount, computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { useTrack } from 'dashboard/composables';
import { useStore } from 'dashboard/composables/store';
import { vOnClickOutside } from '@vueuse/components';
import { CONVERSATION_EVENTS } from 'dashboard/helper/AnalyticsHelper/events';
import { useConversationFilterContext } from './provider.js';
import { useSnakeCase } from 'dashboard/composables/useTransformKeys';
import Button from 'next/button/Button.vue';
import ConditionRow from './ConditionRow.vue';
const props = defineProps({
isFolderView: {
type: Boolean,
default: false,
},
folderName: {
type: String,
default: '',
},
});
const emit = defineEmits(['applyFilter', 'updateFolder', 'close']);
const { filterTypes } = useConversationFilterContext();
const filters = defineModel({
type: Array,
default: [],
});
const folderNameLocal = ref(props.folderName);
const DEFAULT_FILTER = {
attributeKey: 'status',
filterOperator: 'equal_to',
values: [],
queryOperator: 'and',
};
const { t } = useI18n();
const store = useStore();
const resetFilter = () => {
filters.value = [{ ...DEFAULT_FILTER }];
};
const removeFilter = index => {
if (filters.value.length === 1) {
resetFilter();
} else {
filters.value.splice(index, 1);
}
};
const addFilter = () => {
filters.value.push({ ...DEFAULT_FILTER });
};
const conditionsRef = useTemplateRef('conditionsRef');
const isConditionsValid = () => {
return conditionsRef.value.every(condition => condition.validate());
};
const updateSavedCustomViews = () => {
if (isConditionsValid()) {
emit('updateFolder', filters.value, folderNameLocal.value);
}
};
function validateAndSubmit() {
if (!isConditionsValid()) {
return;
}
store.dispatch(
'setConversationFilters',
useSnakeCase(JSON.parse(JSON.stringify(filters.value)))
);
emit('applyFilter', filters.value);
useTrack(CONVERSATION_EVENTS.APPLY_FILTER, {
appliedFilters: filters.value.map(filter => ({
key: filter.attributeKey,
operator: filter.filterOperator,
queryOperator: filter.queryOperator,
})),
});
}
const filterModalHeaderTitle = computed(() => {
return !props.isFolderView
? t('FILTER.TITLE')
: t('FILTER.EDIT_CUSTOM_FILTER');
});
onBeforeUnmount(() => emit('close'));
const outsideClickHandler = [
() => emit('close'),
{ ignore: ['#toggleConversationFilterButton'] },
];
</script>
<template>
<div
v-on-click-outside="outsideClickHandler"
class="z-40 max-w-3xl lg:w-[750px] overflow-visible w-full border border-n-weak bg-n-alpha-3 backdrop-blur-[100px] shadow-lg rounded-xl p-6 grid gap-6"
>
<h3 class="text-base font-medium leading-6 text-n-slate-12">
{{ filterModalHeaderTitle }}
</h3>
<div v-if="props.isFolderView">
<label class="border-b border-n-weak pb-6">
<div class="text-n-slate-11 text-sm mb-2">
{{ t('FILTER.FOLDER_LABEL') }}
</div>
<input
v-model="folderNameLocal"
class="py-1.5 px-3 text-n-slate-12 bg-n-alpha-1 text-sm rounded-lg reset-base w-full"
:placeholder="t('FILTER.INPUT_PLACEHOLDER')"
/>
</label>
</div>
<ul class="grid gap-4 list-none">
<template v-for="(filter, index) in filters" :key="filter.id">
<ConditionRow
v-if="index === 0"
ref="conditionsRef"
:key="`filter-${filter.attributeKey}-0`"
v-model:attribute-key="filter.attributeKey"
v-model:filter-operator="filter.filterOperator"
v-model:values="filter.values"
:filter-types="filterTypes"
:show-query-operator="false"
@remove="removeFilter(index)"
/>
<ConditionRow
v-else
:key="`filter-${filter.attributeKey}-${index}`"
ref="conditionsRef"
v-model:attribute-key="filter.attributeKey"
v-model:filter-operator="filter.filterOperator"
v-model:query-operator="filters[index - 1].queryOperator"
v-model:values="filter.values"
show-query-operator
:filter-types="filterTypes"
@remove="removeFilter(index)"
/>
</template>
</ul>
<div class="flex gap-2 justify-between">
<Button sm ghost blue @click="addFilter">
{{ $t('FILTER.ADD_NEW_FILTER') }}
</Button>
<div class="flex gap-2">
<Button sm faded slate @click="resetFilter">
{{ t('FILTER.CLEAR_BUTTON_LABEL') }}
</Button>
<Button
v-if="isFolderView"
sm
solid
blue
:disabled="!folderNameLocal"
@click="updateSavedCustomViews"
>
{{ t('FILTER.UPDATE_BUTTON_LABEL') }}
</Button>
<Button v-else sm solid blue @click="validateAndSubmit">
{{ t('FILTER.SUBMIT_BUTTON_LABEL') }}
</Button>
</div>
</div>
</div>
</template>

View File

@@ -0,0 +1,130 @@
<script>
import { useVuelidate } from '@vuelidate/core';
import { required, minLength } from '@vuelidate/validators';
import { useAlert } from 'dashboard/composables';
import { CONTACTS_EVENTS } from 'dashboard/helper/AnalyticsHelper/events';
import { vOnClickOutside } from '@vueuse/components';
import { useTrack } from 'dashboard/composables';
import NextButton from 'next/button/Button.vue';
export default {
components: {
NextButton,
},
directives: {
onClickOutside: vOnClickOutside,
},
props: {
filterType: {
type: Number,
default: 0,
},
customViewsQuery: {
type: Object,
default: () => {},
},
openLastSavedItem: {
type: Function,
default: () => {},
},
},
emits: ['close'],
setup() {
return { v$: useVuelidate() };
},
data() {
return {
show: true,
name: '',
};
},
computed: {
isButtonDisabled() {
return this.v$.name.$invalid;
},
},
validations: {
name: {
required,
minLength: minLength(1),
},
},
methods: {
onClose() {
this.$emit('close');
},
async saveCustomViews() {
this.v$.$touch();
if (this.v$.$invalid) {
return;
}
try {
await this.$store.dispatch('customViews/create', {
name: this.name,
filter_type: this.filterType,
query: this.customViewsQuery,
});
this.alertMessage =
this.filterType === 0
? this.$t('FILTER.CUSTOM_VIEWS.ADD.API_FOLDERS.SUCCESS_MESSAGE')
: this.$t('FILTER.CUSTOM_VIEWS.ADD.API_SEGMENTS.SUCCESS_MESSAGE');
this.onClose();
useTrack(CONTACTS_EVENTS.SAVE_FILTER, {
type: this.filterType === 0 ? 'folder' : 'segment',
});
} catch (error) {
const errorMessage = error?.message;
this.alertMessage =
errorMessage || this.filterType === 0
? errorMessage
: this.$t('FILTER.CUSTOM_VIEWS.ADD.API_SEGMENTS.ERROR_MESSAGE');
} finally {
useAlert(this.alertMessage);
}
this.openLastSavedItem();
},
},
};
</script>
<template>
<div
v-on-click-outside="[
() => $emit('close'),
{ ignore: ['#saveFilterTeleportTarget'] },
]"
class="z-40 max-w-3xl lg:w-[500px] overflow-visible w-full border border-n-weak bg-n-alpha-3 backdrop-blur-[100px] shadow-lg rounded-xl p-6 grid gap-6"
>
<h3 class="text-base font-medium leading-6 text-n-slate-12">
{{ $t('FILTER.CUSTOM_VIEWS.ADD.TITLE') }}
</h3>
<form class="w-full grid gap-6" @submit.prevent="saveCustomViews">
<div>
<input
v-model="name"
class="py-1.5 px-3 text-n-slate-12 bg-n-alpha-1 text-sm rounded-lg reset-base w-full"
:placeholder="$t('FILTER.CUSTOM_VIEWS.ADD.PLACEHOLDER')"
@blur="v$.name.$touch"
/>
<span
v-if="v$.name.$error"
class="text-xs text-n-ruby-11 ml-1 rtl:mr-1"
>
{{ $t('FILTER.CUSTOM_VIEWS.ADD.ERROR_MESSAGE') }}
</span>
</div>
<div class="flex flex-row justify-end w-full gap-2">
<NextButton sm solid blue :disabled="isButtonDisabled">
{{ $t('FILTER.CUSTOM_VIEWS.ADD.SAVE_BUTTON') }}
</NextButton>
<NextButton faded slate sm @click.prevent="onClose">
{{ $t('FILTER.CUSTOM_VIEWS.ADD.CANCEL_BUTTON') }}
</NextButton>
</div>
</form>
</div>
</template>

View File

@@ -61,7 +61,7 @@ const updateSelected = newValue => {
/>
</slot>
</template>
<DropdownBody class="top-0 min-w-48 z-[999]">
<DropdownBody class="top-0 min-w-48 z-50" strong>
<DropdownSection class="max-h-80 overflow-scroll">
<DropdownItem
v-for="option in options"

View File

@@ -122,7 +122,7 @@ const toggleOption = option => {
<span class="text-n-slate-11">{{ t('COMBOBOX.PLACEHOLDER') }}</span>
</Button>
</template>
<DropdownBody class="top-0 min-w-48 z-[999]">
<DropdownBody class="top-0 min-w-48 z-50" strong>
<DropdownSection class="max-h-80 overflow-scroll">
<DropdownItem
v-for="option in options"

View File

@@ -80,7 +80,7 @@ const toggleSelected = option => {
<span class="text-n-slate-11">{{ t('COMBOBOX.PLACEHOLDER') }}</span>
</Button>
</template>
<DropdownBody class="top-0 min-w-56 z-[999]">
<DropdownBody class="top-0 min-w-56 z-50" strong>
<div v-if="!disableSearch" class="relative">
<Icon class="absolute size-4 left-2 top-2" icon="i-lucide-search" />
<input

View File

@@ -0,0 +1,164 @@
import { computed, h } from 'vue';
import { useI18n } from 'vue-i18n';
/**
* @typedef {Object} FilterOperations
* @property {string} EQUAL_TO - Equals comparison
* @property {string} NOT_EQUAL_TO - Not equals comparison
* @property {string} IS_PRESENT - Present check
* @property {string} IS_NOT_PRESENT - Not present check
* @property {string} CONTAINS - Contains check
* @property {string} DOES_NOT_CONTAIN - Does not contain check
* @property {string} IS_GREATER_THAN - Greater than comparison
* @property {string} IS_LESS_THAN - Less than comparison
* @property {string} DAYS_BEFORE - Days before check
* @property {string} STARTS_WITH - Starts with check
*/
/**
* @typedef {Object} Operator
* @property {string} value - Operator value from FILTER_OPS
* @property {string} label - Translated display label
* @property {import('vue').VNode} icon - Vue icon component instance
* @property {string|null} inputOverride - Input field type override
* @property {boolean} hasInput - Whether operator requires an input value
*/
const FILTER_OPS = {
EQUAL_TO: 'equal_to',
NOT_EQUAL_TO: 'not_equal_to',
IS_PRESENT: 'is_present',
IS_NOT_PRESENT: 'is_not_present',
CONTAINS: 'contains',
DOES_NOT_CONTAIN: 'does_not_contain',
IS_GREATER_THAN: 'is_greater_than',
IS_LESS_THAN: 'is_less_than',
DAYS_BEFORE: 'days_before',
STARTS_WITH: 'starts_with',
};
const NO_INPUT_OPTS = [FILTER_OPS.IS_PRESENT, FILTER_OPS.IS_NOT_PRESENT];
const OPS_INPUT_OVERRIDE = {
[FILTER_OPS.DAYS_BEFORE]: 'plainText',
};
/**
* @type {Record<string, string>}
*/
const filterOperatorIcon = {
[FILTER_OPS.EQUAL_TO]: 'i-ph-equals-bold',
[FILTER_OPS.NOT_EQUAL_TO]: 'i-ph-not-equals-bold',
[FILTER_OPS.IS_PRESENT]: 'i-ph-member-of-bold',
[FILTER_OPS.IS_NOT_PRESENT]: 'i-ph-not-member-of-bold',
[FILTER_OPS.CONTAINS]: 'i-ph-superset-of-bold',
[FILTER_OPS.DOES_NOT_CONTAIN]: 'i-ph-not-superset-of-bold',
[FILTER_OPS.IS_GREATER_THAN]: 'i-ph-greater-than-bold',
[FILTER_OPS.IS_LESS_THAN]: 'i-ph-less-than-bold',
[FILTER_OPS.DAYS_BEFORE]: 'i-ph-calendar-minus-bold',
[FILTER_OPS.STARTS_WITH]: 'i-ph-caret-line-right-bold',
};
/**
* Vue composable providing access to filter operators and related functionality
* @returns {Object} Collection of operators and utility functions
* @property {import('vue').ComputedRef<Record<string, Operator>>} operators - All available operators
* @property {import('vue').ComputedRef<Operator[]>} equalityOperators - Equality comparison operators
* @property {import('vue').ComputedRef<Operator[]>} presenceOperators - Presence check operators
* @property {import('vue').ComputedRef<Operator[]>} containmentOperators - Containment check operators
* @property {import('vue').ComputedRef<Operator[]>} comparisonOperators - Numeric comparison operators
* @property {import('vue').ComputedRef<Operator[]>} dateOperators - Date-specific operators
* @property {(key: 'list'|'text'|'number'|'link'|'date'|'checkbox') => Operator[]} getOperatorTypes - Get operators for a field type
*/
export function useOperators() {
const { t } = useI18n();
/** @type {import('vue').ComputedRef<Record<string, Operator>>} */
const operators = computed(() => {
return Object.values(FILTER_OPS).reduce((acc, value) => {
acc[value] = {
value,
label: t(`FILTER.OPERATOR_LABELS.${value}`),
hasInput: !NO_INPUT_OPTS.includes(value),
inputOverride: OPS_INPUT_OVERRIDE[value] || null,
icon: h('span', {
class: `${filterOperatorIcon[value]} !text-n-blue-text`,
}),
};
return acc;
}, {});
});
/** @type {import('vue').ComputedRef<Array<Operator>>} */
const equalityOperators = computed(() => [
operators.value[FILTER_OPS.EQUAL_TO],
operators.value[FILTER_OPS.NOT_EQUAL_TO],
]);
/** @type {import('vue').ComputedRef<Array<Operator>>} */
const presenceOperators = computed(() => [
operators.value[FILTER_OPS.EQUAL_TO],
operators.value[FILTER_OPS.NOT_EQUAL_TO],
operators.value[FILTER_OPS.IS_PRESENT],
operators.value[FILTER_OPS.IS_NOT_PRESENT],
]);
/** @type {import('vue').ComputedRef<Array<Operator>>} */
const containmentOperators = computed(() => [
operators.value[FILTER_OPS.EQUAL_TO],
operators.value[FILTER_OPS.NOT_EQUAL_TO],
operators.value[FILTER_OPS.CONTAINS],
operators.value[FILTER_OPS.DOES_NOT_CONTAIN],
]);
/** @type {import('vue').ComputedRef<Array<Operator>>} */
const comparisonOperators = computed(() => [
operators.value[FILTER_OPS.EQUAL_TO],
operators.value[FILTER_OPS.NOT_EQUAL_TO],
operators.value[FILTER_OPS.IS_PRESENT],
operators.value[FILTER_OPS.IS_NOT_PRESENT],
operators.value[FILTER_OPS.IS_GREATER_THAN],
operators.value[FILTER_OPS.IS_LESS_THAN],
]);
/** @type {import('vue').ComputedRef<Array<Operator>>} */
const dateOperators = computed(() => [
operators.value[FILTER_OPS.IS_GREATER_THAN],
operators.value[FILTER_OPS.IS_LESS_THAN],
operators.value[FILTER_OPS.DAYS_BEFORE],
]);
/**
* Get operator types based on key
* @param {string} key - Type of operator to get
* @returns {Array<Operator>}
*/
const getOperatorTypes = key => {
switch (key) {
case 'list':
return equalityOperators.value;
case 'text':
return containmentOperators.value;
case 'number':
return equalityOperators.value;
case 'link':
return equalityOperators.value;
case 'date':
return comparisonOperators.value;
case 'checkbox':
return equalityOperators.value;
default:
return equalityOperators.value;
}
};
return {
operators,
equalityOperators,
presenceOperators,
containmentOperators,
comparisonOperators,
dateOperators,
getOperatorTypes,
};
}

View File

@@ -0,0 +1,299 @@
import { computed, h } from 'vue';
import { useI18n } from 'vue-i18n';
import { useOperators } from './operators';
import { useMapGetter } from 'dashboard/composables/store.js';
import { useChannelIcon } from 'next/icon/provider';
import countries from 'shared/constants/countries.js';
import languages from 'dashboard/components/widgets/conversation/advancedFilterItems/languages.js';
/**
* @typedef {Object} FilterOption
* @property {string|number} id
* @property {string} name
* @property {import('vue').VNode} [icon]
*/
/**
* @typedef {Object} FilterOperator
* @property {string} value
* @property {string} label
* @property {string} icon
* @property {boolean} hasInput
*/
/**
* @typedef {Object} FilterType
* @property {string} attributeKey - The attribute key
* @property {string} value - This is a proxy for the attribute key used in FilterSelect
* @property {string} attributeName - The attribute name used to display on the UI
* @property {string} label - This is a proxy for the attribute name used in FilterSelect
* @property {'multiSelect'|'searchSelect'|'plainText'|'date'|'booleanSelect'} inputType - The input type for the attribute
* @property {FilterOption[]} [options] - The options available for the attribute if it is a multiSelect or singleSelect type
* @property {'text'|'number'} dataType
* @property {FilterOperator[]} filterOperators - The operators available for the attribute
* @property {'standard'|'additional'|'customAttributes'} attributeModel
*/
/**
* @typedef {Object} FilterGroup
* @property {string} name
* @property {FilterType[]} attributes
*/
/**
* Determines the input type for a custom attribute based on its key
* @param {string} key - The attribute display type key
* @returns {'date'|'plainText'|'searchSelect'|'booleanSelect'} The corresponding input type
*/
const customAttributeInputType = key => {
switch (key) {
case 'date':
return 'date';
case 'text':
return 'plainText';
case 'list':
return 'searchSelect';
case 'checkbox':
return 'booleanSelect';
default:
return 'plainText';
}
};
/**
* Composable that provides conversation filtering context
* @returns {{ filterTypes: import('vue').ComputedRef<FilterType[]>, filterGroups: import('vue').ComputedRef<FilterGroup[]> }}
*/
export function useConversationFilterContext() {
const { t } = useI18n();
const conversationAttributes = useMapGetter(
'attributes/getConversationAttributes'
);
const labels = useMapGetter('labels/getLabels');
const agents = useMapGetter('agents/getAgents');
const inboxes = useMapGetter('inboxes/getInboxes');
const teams = useMapGetter('teams/getTeams');
const campaigns = useMapGetter('campaigns/getAllCampaigns');
const {
equalityOperators,
presenceOperators,
containmentOperators,
dateOperators,
getOperatorTypes,
} = useOperators();
/**
* @type {import('vue').ComputedRef<FilterType[]>}
*/
const customFilterTypes = computed(() => {
return conversationAttributes.value.map(attr => {
return {
attributeKey: attr.attributeKey,
value: attr.attributeKey,
attributeName: attr.attributeDisplayName,
label: attr.attributeDisplayName,
inputType: customAttributeInputType(attr.attributeDisplayType),
filterOperators: getOperatorTypes(attr.attributeDisplayType),
options:
attr.attributeDisplayType === 'list'
? attr.attributeValues.map(item => ({ id: item, name: item }))
: [],
attributeModel: 'customAttributes',
};
});
});
/**
* @type {import('vue').ComputedRef<FilterType[]>}
*/
const filterTypes = computed(() => [
{
attributeKey: 'status',
value: 'status',
attributeName: t('FILTER.ATTRIBUTES.STATUS'),
label: t('FILTER.ATTRIBUTES.STATUS'),
inputType: 'multiSelect',
options: ['open', 'resolved', 'pending', 'snoozed', 'all'].map(id => {
return {
id,
name: t(`CHAT_LIST.CHAT_STATUS_FILTER_ITEMS.${id}.TEXT`),
};
}),
dataType: 'text',
filterOperators: equalityOperators.value,
attributeModel: 'standard',
},
{
attributeKey: 'assignee_id',
value: 'assignee_id',
attributeName: t('FILTER.ATTRIBUTES.ASSIGNEE_NAME'),
label: t('FILTER.ATTRIBUTES.ASSIGNEE_NAME'),
inputType: 'searchSelect',
options: agents.value.map(agent => {
return {
id: agent.id,
name: agent.name,
};
}),
dataType: 'text',
filterOperators: presenceOperators.value,
attributeModel: 'standard',
},
{
attributeKey: 'inbox_id',
value: 'inbox_id',
attributeName: t('FILTER.ATTRIBUTES.INBOX_NAME'),
label: t('FILTER.ATTRIBUTES.INBOX_NAME'),
inputType: 'searchSelect',
options: inboxes.value.map(inbox => {
return {
...inbox,
icon: useChannelIcon(inbox).value,
};
}),
dataType: 'text',
filterOperators: presenceOperators.value,
attributeModel: 'standard',
},
{
attributeKey: 'team_id',
value: 'team_id',
attributeName: t('FILTER.ATTRIBUTES.TEAM_NAME'),
label: t('FILTER.ATTRIBUTES.TEAM_NAME'),
inputType: 'searchSelect',
options: teams.value,
dataType: 'number',
filterOperators: presenceOperators.value,
attributeModel: 'standard',
},
{
attributeKey: 'display_id',
value: 'display_id',
attributeName: t('FILTER.ATTRIBUTES.CONVERSATION_IDENTIFIER'),
label: t('FILTER.ATTRIBUTES.CONVERSATION_IDENTIFIER'),
inputType: 'plainText',
datatype: 'number',
filterOperators: containmentOperators.value,
attributeModel: 'standard',
},
{
attributeKey: 'campaign_id',
value: 'campaign_id',
attributeName: t('FILTER.ATTRIBUTES.CAMPAIGN_NAME'),
label: t('FILTER.ATTRIBUTES.CAMPAIGN_NAME'),
inputType: 'searchSelect',
options: campaigns.value.map(campaign => ({
id: campaign.id,
name: campaign.title,
})),
datatype: 'number',
filterOperators: presenceOperators.value,
attributeModel: 'standard',
},
{
attributeKey: 'labels',
value: 'labels',
attributeName: t('FILTER.ATTRIBUTES.LABELS'),
label: t('FILTER.ATTRIBUTES.LABELS'),
inputType: 'multiSelect',
options: labels.value.map(label => {
return {
id: label.title,
name: label.title,
icon: h('span', {
class: `rounded-full`,
style: {
backgroundColor: label.color,
height: '6px',
width: '6px',
},
}),
};
}),
dataType: 'text',
filterOperators: presenceOperators.value,
attributeModel: 'standard',
},
{
attributeKey: 'browser_language',
value: 'browser_language',
attributeName: t('FILTER.ATTRIBUTES.BROWSER_LANGUAGE'),
label: t('FILTER.ATTRIBUTES.BROWSER_LANGUAGE'),
inputType: 'searchSelect',
options: languages,
dataType: 'text',
filterOperators: equalityOperators.value,
attributeModel: 'additional',
},
{
attributeKey: 'country_code',
value: 'country_code',
attributeName: t('FILTER.ATTRIBUTES.COUNTRY_NAME'),
label: t('FILTER.ATTRIBUTES.COUNTRY_NAME'),
inputType: 'searchSelect',
options: countries,
dataType: 'text',
filterOperators: equalityOperators.value,
attributeModel: 'additional',
},
{
attributeKey: 'referer',
value: 'referer',
attributeName: t('FILTER.ATTRIBUTES.REFERER_LINK'),
label: t('FILTER.ATTRIBUTES.REFERER_LINK'),
inputType: 'plainText',
dataType: 'text',
filterOperators: containmentOperators.value,
attributeModel: 'additional',
},
{
attributeKey: 'created_at',
value: 'created_at',
attributeName: t('FILTER.ATTRIBUTES.CREATED_AT'),
label: t('FILTER.ATTRIBUTES.CREATED_AT'),
inputType: 'date',
dataType: 'text',
filterOperators: dateOperators.value,
attributeModel: 'standard',
},
{
attributeKey: 'last_activity_at',
value: 'last_activity_at',
attributeName: t('FILTER.ATTRIBUTES.LAST_ACTIVITY'),
label: t('FILTER.ATTRIBUTES.LAST_ACTIVITY'),
inputType: 'date',
dataType: 'text',
filterOperators: dateOperators.value,
attributeModel: 'standard',
},
...customFilterTypes.value,
]);
const filterGroups = computed(() => {
return [
{
name: t(`FILTER.GROUPS.STANDARD_FILTERS`),
attributes: filterTypes.value.filter(
filter => filter.attributeModel === 'standard'
),
},
{
name: t(`FILTER.GROUPS.ADDITIONAL_FILTERS`),
attributes: filterTypes.value.filter(
filter => filter.attributeModel === 'additional'
),
},
{
name: t(`FILTER.GROUPS.CUSTOM_ATTRIBUTES`),
attributes: filterTypes.value.filter(
filter => filter.attributeModel === 'customAttributes'
),
},
];
});
return { filterTypes, filterGroups };
}