From 6deb3764dcd629b9d9d0bc82016ff9d7359095c4 Mon Sep 17 00:00:00 2001 From: Fayaz Ahmed <15716057+fayazara@users.noreply.github.com> Date: Mon, 17 Jan 2022 20:35:53 +0530 Subject: [PATCH] Fix: Pagination bug with filters payload (#3747) * Removes the last operators value * Moved removing the last operator to the payload generator * Update app/javascript/dashboard/helper/filterQueryGenerator.js This makes sure the last operator is never sent to the request Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> * Fixed the test specs * Fixed the intendation and added comments Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Nithin David Thomas <1277421+nithindavid@users.noreply.github.com> --- .../widgets/conversation/ConversationAdvancedFilter.vue | 1 - app/javascript/dashboard/helper/filterQueryGenerator.js | 5 ++++- .../dashboard/helper/specs/filterQueryGenerator.spec.js | 3 +-- .../contacts/components/ContactsAdvancedFilters.vue | 1 - 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/conversation/ConversationAdvancedFilter.vue b/app/javascript/dashboard/components/widgets/conversation/ConversationAdvancedFilter.vue index c79731425..acf7f3cfd 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ConversationAdvancedFilter.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ConversationAdvancedFilter.vue @@ -192,7 +192,6 @@ export default { 'setConversationFilters', JSON.parse(JSON.stringify(this.appliedFilters)) ); - this.appliedFilters[this.appliedFilters.length - 1].query_operator = null; this.$emit('applyFilter', this.appliedFilters); }, resetFilter(index, currentFilter) { diff --git a/app/javascript/dashboard/helper/filterQueryGenerator.js b/app/javascript/dashboard/helper/filterQueryGenerator.js index f2fbd39aa..590debf03 100644 --- a/app/javascript/dashboard/helper/filterQueryGenerator.js +++ b/app/javascript/dashboard/helper/filterQueryGenerator.js @@ -11,7 +11,10 @@ const generatePayload = data => { } return item; }); - + // For every query added, the query_operator is set default to and so the + // last query will have an extra query_operator, this would break the api. + // Setting this to null for all query payload + payload[payload.length - 1].query_operator = undefined; return { payload }; }; diff --git a/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js b/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js index aee524c5e..9120ea930 100644 --- a/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js +++ b/app/javascript/dashboard/helper/specs/filterQueryGenerator.spec.js @@ -31,7 +31,7 @@ const testData = [ attribute_key: 'id', filter_operator: 'equal_to', values: 'This is a test', - query_operator: null, + query_operator: 'or', }, ]; @@ -53,7 +53,6 @@ const finalResult = { attribute_key: 'id', filter_operator: 'equal_to', values: ['This is a test'], - query_operator: null, }, ], }; diff --git a/app/javascript/dashboard/routes/dashboard/contacts/components/ContactsAdvancedFilters.vue b/app/javascript/dashboard/routes/dashboard/contacts/components/ContactsAdvancedFilters.vue index 5c0aae26c..a91f4e6d4 100644 --- a/app/javascript/dashboard/routes/dashboard/contacts/components/ContactsAdvancedFilters.vue +++ b/app/javascript/dashboard/routes/dashboard/contacts/components/ContactsAdvancedFilters.vue @@ -160,7 +160,6 @@ export default { 'contacts/setContactFilters', JSON.parse(JSON.stringify(this.appliedFilters)) ); - this.appliedFilters[this.appliedFilters.length - 1].query_operator = null; this.$emit('applyFilter', this.appliedFilters); }, resetFilter(index, currentFilter) {