From 375d943a48dede8c24c1b57d88442c72fa891892 Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Date: Mon, 7 Feb 2022 22:14:21 +0530 Subject: [PATCH] fix: Avoid filter payload changing to null on load more conversations (#3926) Co-authored-by: Pranav Raj S Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> --- .../dashboard/helper/actionQueryGenerator.js | 3 ++- .../dashboard/helper/filterQueryGenerator.js | 18 +++++++++++++++++- .../helper/specs/filterQueryGenerator.spec.js | 4 ++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/app/javascript/dashboard/helper/actionQueryGenerator.js b/app/javascript/dashboard/helper/actionQueryGenerator.js index f5ff7c19e..d8f57b572 100644 --- a/app/javascript/dashboard/helper/actionQueryGenerator.js +++ b/app/javascript/dashboard/helper/actionQueryGenerator.js @@ -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') { diff --git a/app/javascript/dashboard/helper/filterQueryGenerator.js b/app/javascript/dashboard/helper/filterQueryGenerator.js index 590debf03..d549c490c 100644 --- a/app/javascript/dashboard/helper/filterQueryGenerator.js +++ b/app/javascript/dashboard/helper/filterQueryGenerator.js @@ -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 diff --git a/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js b/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js index 9120ea930..6b38b094a 100644 --- a/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js +++ b/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js @@ -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'], }, ], };