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

@@ -6,6 +6,24 @@ export const VALUE_MUST_BE_BETWEEN_1_AND_998 =
export const ACTION_PARAMETERS_REQUIRED = 'ACTION_PARAMETERS_REQUIRED';
export const ATLEAST_ONE_CONDITION_REQUIRED = 'ATLEAST_ONE_CONDITION_REQUIRED';
export const ATLEAST_ONE_ACTION_REQUIRED = 'ATLEAST_ONE_ACTION_REQUIRED';
const isEmptyValue = value => {
if (!value) {
return true;
}
if (Array.isArray(value)) {
return !value.length;
}
// We can safely check the type here as both the null value
// and the array is ruled out earlier.
if (typeof value === 'object') {
return !Object.keys(value).length;
}
return false;
};
// ------------------------------------------------------------------
// ------------------------ Filter Validation -----------------------
// ------------------------------------------------------------------
@@ -29,12 +47,11 @@ export const validateSingleFilter = filter => {
return FILTER_OPERATOR_REQUIRED;
}
if (
filter.filter_operator !== 'is_present' &&
filter.filter_operator !== 'is_not_present' &&
(!filter.values ||
(Array.isArray(filter.values) && filter.values.length === 0))
) {
const operatorRequiresValue = !['is_present', 'is_not_present'].includes(
filter.filter_operator
);
if (operatorRequiresValue && isEmptyValue(filter.values)) {
return VALUE_REQUIRED;
}