mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-10-31 19:17:48 +00:00 
			
		
		
		
	 c63a6ed8ec
			
		
	
	c63a6ed8ec
	
	
	
		
			
			# Pull Request Template ## Description This PR will replace the usage of `agentMixin`with the utility helpers functions. **Files updated** 1. dashboard/components/widgets/conversation/contextMenu/Index.vue 2. dashboard/components/widgets/conversation/ConversationHeader.vue **(Not used)** 3. dashboard/routes/dashboard/commands/commandbar.vue 4. dashboard/routes/dashboard/conversation/ConversationAction.vue 5. dashboard/routes/dashboard/conversation/ConversationParticipant.vue Fixes https://linear.app/chatwoot/issue/CW-3442/rewrite-agentmixin-mixin-to-a-composable ## Type of change - [x] New feature (non-breaking change which adds functionality) ## How Has This Been Tested? **Test cases** 1. See agent list sorting based on availability, if agents are on the same status, then sorted by name. 2. Test actions like assigning/unassigning agent from conversation sidebar, CMD bar, Context menu. 3. Test actions like adding/removing participants from conversation sidebar. 4. See agent list is generated properly, none value. ## Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my code - [x] I have commented on my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] Any dependent changes have been merged and published in downstream modules
		
			
				
	
	
		
			58 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			58 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import { computed } from 'vue';
 | |
| import { useMapGetter } from 'dashboard/composables/store';
 | |
| import {
 | |
|   getAgentsByUpdatedPresence,
 | |
|   getSortedAgentsByAvailability,
 | |
|   getCombinedAgents,
 | |
| } from 'dashboard/helper/agentHelper';
 | |
| 
 | |
| /**
 | |
|  * A composable function that provides a list of agents for assignment.
 | |
|  *
 | |
|  * @param {boolean} [includeNoneAgent=true] - Whether to include a 'None' agent option.
 | |
|  * @returns {Object} An object containing the agents list and assignable agents.
 | |
|  */
 | |
| export function useAgentsList(includeNoneAgent = true) {
 | |
|   const currentUser = useMapGetter('getCurrentUser');
 | |
|   const currentChat = useMapGetter('getSelectedChat');
 | |
|   const currentAccountId = useMapGetter('getCurrentAccountId');
 | |
|   const assignable = useMapGetter('inboxAssignableAgents/getAssignableAgents');
 | |
| 
 | |
|   const inboxId = computed(() => currentChat.value?.inbox_id);
 | |
|   const isAgentSelected = computed(() => currentChat.value?.meta?.assignee);
 | |
| 
 | |
|   /**
 | |
|    * @type {import('vue').ComputedRef<Array>}
 | |
|    */
 | |
|   const assignableAgents = computed(() => {
 | |
|     return inboxId.value ? assignable.value(inboxId.value) : [];
 | |
|   });
 | |
| 
 | |
|   /**
 | |
|    * @type {import('vue').ComputedRef<Array>}
 | |
|    */
 | |
|   const agentsList = computed(() => {
 | |
|     const agents = assignableAgents.value || [];
 | |
|     const agentsByUpdatedPresence = getAgentsByUpdatedPresence(
 | |
|       agents,
 | |
|       currentUser.value,
 | |
|       currentAccountId.value
 | |
|     );
 | |
| 
 | |
|     const filteredAgentsByAvailability = getSortedAgentsByAvailability(
 | |
|       agentsByUpdatedPresence
 | |
|     );
 | |
| 
 | |
|     return getCombinedAgents(
 | |
|       filteredAgentsByAvailability,
 | |
|       includeNoneAgent,
 | |
|       isAgentSelected.value
 | |
|     );
 | |
|   });
 | |
| 
 | |
|   return {
 | |
|     agentsList,
 | |
|     assignableAgents,
 | |
|   };
 | |
| }
 |