mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 19:17:48 +00:00 
			
		
		
		
	feat: Add support for frontend filtering of conversations (#11111)
This pull request includes significant changes to the filtering logic for conversations in the frontend, here's a summary of the changes This includes adding a `matchesFilters` method that evaluates a conversation against the applied filters. It does so by first evaluating all the conditions, and later converting the results into a JSONLogic object that can be evaluated according to Postgres operator precedence ### Alignment Specs To ensure the frontend and backend implementations always align, we've added tests on both sides with same cases, for anyone fixing any regressions found in the frontend implementation, they need to ensure the existing tests always pass. Test Case | JavaScript Spec | Ruby Spec | Match? -- | -- | -- | -- **A AND B OR C** | Present | Present | Yes Matches when all conditions are true | Present | Present | Yes Matches when first condition is false but third is true | Present | Present | Yes Matches when first and second conditions are false but third is true | Present | Present | Yes Does not match when all conditions are false | Present | Present | Yes **A OR B AND C** | Present | Present | Yes Matches when first condition is true | Present | Present | Yes Matches when second and third conditions are true | Present | Present | Yes **A AND B OR C AND D** | Present | Present | Yes Matches when first two conditions are true | Present | Present | Yes Matches when last two conditions are true | Present | Present | Yes **Mixed Operators (A AND (B OR C) AND D)** | Present | Present | Yes Matches when all conditions in the chain are true | Present | Present | Yes Does not match when the last condition is false | Present | Present | Yes --------- Co-authored-by: Sivin Varghese <64252451+iamsivin@users.noreply.github.com> Co-authored-by: Muhsin Keloth <muhsinkeramam@gmail.com> Co-authored-by: Pranav <pranav@chatwoot.com>
This commit is contained in:
		| @@ -61,6 +61,7 @@ import { | ||||
|   getUserPermissions, | ||||
|   filterItemsByPermission, | ||||
| } from 'dashboard/helper/permissionsHelper.js'; | ||||
| import { matchesFilters } from '../store/modules/conversations/helpers/filterHelpers'; | ||||
| import { CONVERSATION_EVENTS } from '../helper/AnalyticsHelper/events'; | ||||
| import { ASSIGNEE_TYPE_TAB_PERMISSIONS } from 'dashboard/constants/permissions.js'; | ||||
|  | ||||
| @@ -105,7 +106,7 @@ const advancedFilterTypes = ref( | ||||
| ); | ||||
|  | ||||
| const currentUser = useMapGetter('getCurrentUser'); | ||||
| const chatLists = useMapGetter('getAllConversations'); | ||||
| const chatLists = useMapGetter('getFilteredConversations'); | ||||
| const mineChatsList = useMapGetter('getMineChats'); | ||||
| const allChatList = useMapGetter('getAllStatusChats'); | ||||
| const unAssignedChatsList = useMapGetter('getUnAssignedChats'); | ||||
| @@ -324,6 +325,14 @@ const conversationList = computed(() => { | ||||
|   } else { | ||||
|     localConversationList = [...chatLists.value]; | ||||
|   } | ||||
|  | ||||
|   if (activeFolder.value) { | ||||
|     const { payload } = activeFolder.value.query; | ||||
|     localConversationList = localConversationList.filter(conversation => { | ||||
|       return matchesFilters(conversation, payload); | ||||
|     }); | ||||
|   } | ||||
|  | ||||
|   return localConversationList; | ||||
| }); | ||||
|  | ||||
| @@ -460,6 +469,12 @@ function setParamsForEditFolderModal() { | ||||
|     campaigns: campaigns.value, | ||||
|     languages: languages, | ||||
|     countries: countries, | ||||
|     priority: [ | ||||
|       { id: 'low', name: t('CONVERSATION.PRIORITY.OPTIONS.LOW') }, | ||||
|       { id: 'medium', name: t('CONVERSATION.PRIORITY.OPTIONS.MEDIUM') }, | ||||
|       { id: 'high', name: t('CONVERSATION.PRIORITY.OPTIONS.HIGH') }, | ||||
|       { id: 'urgent', name: t('CONVERSATION.PRIORITY.OPTIONS.URGENT') }, | ||||
|     ], | ||||
|     filterTypes: advancedFilterTypes.value, | ||||
|     allCustomAttributes: conversationCustomAttributes.value, | ||||
|   }; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Shivam Mishra
					Shivam Mishra