diff --git a/app/javascript/dashboard/store/modules/conversations/helpers/filterHelpers.js b/app/javascript/dashboard/store/modules/conversations/helpers/filterHelpers.js index d64d3c56b..3f1c32059 100644 --- a/app/javascript/dashboard/store/modules/conversations/helpers/filterHelpers.js +++ b/app/javascript/dashboard/store/modules/conversations/helpers/filterHelpers.js @@ -167,7 +167,14 @@ const contains = (filterValue, conversationValue) => { */ const compareDates = (conversationValue, filterValue, compareFn) => { const conversationDate = coerceToDate(conversationValue); - const filterDate = coerceToDate(filterValue); + + // In saved views, the filterValue might be returned as an Array + // In conversation list, when filtering, the filterValue will be returned as a string + const valueToCompare = Array.isArray(filterValue) + ? filterValue[0] + : filterValue; + const filterDate = coerceToDate(valueToCompare); + if (conversationDate === null || filterDate === null) return false; return compareFn(conversationDate, filterDate); }; diff --git a/app/javascript/dashboard/store/modules/conversations/helpers/specs/filterHelpers.spec.js b/app/javascript/dashboard/store/modules/conversations/helpers/specs/filterHelpers.spec.js index 0c9e6a5c0..b36128819 100644 --- a/app/javascript/dashboard/store/modules/conversations/helpers/specs/filterHelpers.spec.js +++ b/app/javascript/dashboard/store/modules/conversations/helpers/specs/filterHelpers.spec.js @@ -602,6 +602,59 @@ describe('filterHelpers', () => { expect(matchesFilters(conversation, filters)).toBe(false); }); + // Test for array filter values (saved views) + it('should handle array filter values for date comparison in saved views', () => { + const conversation = { created_at: 1647777600000 }; // March 20, 2022 + const filters = [ + { + attribute_key: 'created_at', + filter_operator: 'is_greater_than', + values: ['2022-03-19'], // Array format from saved views + query_operator: 'and', + }, + ]; + expect(matchesFilters(conversation, filters)).toBe(true); + }); + + it('should handle array filter values with is_less_than operator', () => { + const conversation = { created_at: 1647777600000 }; // March 20, 2022 + const filters = [ + { + attribute_key: 'created_at', + filter_operator: 'is_less_than', + values: ['2022-03-21'], // Array format from saved views + query_operator: 'and', + }, + ]; + expect(matchesFilters(conversation, filters)).toBe(true); + }); + + it('should handle array filter values with timestamp', () => { + const conversation = { created_at: 1647777600000 }; // March 20, 2022 + const filters = [ + { + attribute_key: 'created_at', + filter_operator: 'is_greater_than', + values: [1647691200], // March 19, 2022 as array (in seconds) + query_operator: 'and', + }, + ]; + expect(matchesFilters(conversation, filters)).toBe(true); + }); + + it('should handle empty array filter values', () => { + const conversation = { created_at: 1647777600000 }; // March 20, 2022 + const filters = [ + { + attribute_key: 'created_at', + filter_operator: 'is_greater_than', + values: [], // Empty array + query_operator: 'and', + }, + ]; + expect(matchesFilters(conversation, filters)).toBe(false); + }); + it('should handle non-date string values in date comparison', () => { const conversation = { created_at: 1647777600000 }; // March 20, 2022 const filters = [ @@ -721,6 +774,19 @@ describe('filterHelpers', () => { ]; expect(matchesFilters(conversation, filters)).toBe(true); }); + + it('should handle array values for days_before operator', () => { + const conversation = { created_at: 1647777600000 }; // March 20, 2022 + const filters = [ + { + attribute_key: 'created_at', + filter_operator: 'days_before', + values: ['3'], // Array format from saved views + query_operator: 'and', + }, + ]; + expect(matchesFilters(conversation, filters)).toBe(true); + }); }); // Multiple filters tests