fix: Avoid filter payload changing to null on load more conversations (#3926)

Co-authored-by: Pranav Raj S <pranav@chatwoot.com>
Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com>
This commit is contained in:
Fayaz Ahmed 2022-02-07 22:14:21 +05:30 committed by GitHub
parent 4c0f6c1333
commit 375d943a48
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View file

@ -1,5 +1,6 @@
const generatePayload = data => {
let payload = data.map(item => {
const actions = JSON.parse(JSON.stringify(data));
let payload = actions.map(item => {
if (Array.isArray(item.action_params)) {
item.action_params = item.action_params.map(val => val.id);
} else if (typeof item.values === 'object') {

View file

@ -1,5 +1,19 @@
const lowerCaseValues = (operator, values) => {
if (operator === 'equal_to' || operator === 'not_equal_to') {
values = values.map(val => {
if (typeof val === 'string') {
return val.toLowerCase();
}
return val;
});
}
return values;
};
const generatePayload = data => {
let payload = data.map(item => {
// Make a copy of data to avoid vue data reactivity issues
const filters = JSON.parse(JSON.stringify(data));
let payload = filters.map(item => {
if (Array.isArray(item.values)) {
item.values = item.values.map(val => val.id);
} else if (typeof item.values === 'object') {
@ -9,6 +23,8 @@ const generatePayload = data => {
} else {
item.values = [item.values];
}
// Convert all values to lowerCase if operator_type is 'equal_to' or 'not_equal_to'
item.values = lowerCaseValues(item.filter_operator, item.values);
return item;
});
// For every query added, the query_operator is set default to and so the

View file

@ -5,7 +5,7 @@ const testData = [
attribute_key: 'status',
filter_operator: 'equal_to',
values: [
{ id: 'pending', name: 'Pending' },
{ id: 'PENDING', name: 'Pending' },
{ id: 'resolved', name: 'Resolved' },
],
query_operator: 'and',
@ -52,7 +52,7 @@ const finalResult = {
{
attribute_key: 'id',
filter_operator: 'equal_to',
values: ['This is a test'],
values: ['this is a test'],
},
],
};