diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 768d755455f7..8579f0ffd353 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -64,7 +64,7 @@ jobs: path: | ./node_modules ./ee/server/services/node_modules - key: ${{ runner.OS }}-node_modules-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }} + key: ${{ runner.OS }}-node_modules-2-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }} - name: Cache meteor local uses: actions/cache@v2 @@ -246,7 +246,7 @@ jobs: path: | ./node_modules ./ee/server/services/node_modules - key: ${{ runner.OS }}-build-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }} + key: ${{ runner.OS }}-node_modules-2-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }} - name: NPM install if: steps.cache-nodemodules.outputs.cache-hit != 'true' || steps.cache-cypress.outputs.cache-hit != 'true' @@ -310,7 +310,7 @@ jobs: path: | ./node_modules ./ee/server/services/node_modules - key: ${{ runner.OS }}-node_modules-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }} + key: ${{ runner.OS }}-node_modules-2-${{ hashFiles('**/package-lock.json', '.github/workflows/build_and_test.yml') }} - name: Cache meteor local uses: actions/cache@v2 diff --git a/client/components/AutoCompleteAgent.js b/client/components/AutoCompleteAgent.js index 4c521fe652b2..7e45c9b1f042 100644 --- a/client/components/AutoCompleteAgent.js +++ b/client/components/AutoCompleteAgent.js @@ -1,38 +1,51 @@ -import { AutoComplete, Option } from '@rocket.chat/fuselage'; +import { PaginatedSelectFiltered } from '@rocket.chat/fuselage'; +import { useDebouncedValue } from '@rocket.chat/fuselage-hooks'; import React, { memo, useMemo, useState } from 'react'; -import { useTranslation } from '../contexts/TranslationContext'; -import { useEndpointData } from '../hooks/useEndpointData'; +import { useRecordList } from '../hooks/lists/useRecordList'; +import { AsyncStatePhase } from '../lib/asyncState'; +import { useAgentsList } from './Omnichannel/hooks/useAgentsList'; const AutoCompleteAgent = (props) => { - const t = useTranslation(); - const [filter, setFilter] = useState(''); - const { value: data } = useEndpointData( - 'livechat/users/agent', - useMemo(() => ({ text: filter }), [filter]), - ); + const [agentsFilter, setAgentsFilter] = useState(''); + + const debouncedAgentsFilter = useDebouncedValue(agentsFilter, 500); - const options = useMemo( - () => (data && [...data.users.map((user) => ({ value: user._id, label: user.name }))]) || [], - [data], + const { itemsList: AgentsList, loadMoreItems: loadMoreAgents } = useAgentsList( + useMemo(() => ({ text: debouncedAgentsFilter }), [debouncedAgentsFilter]), ); - const optionsWithAll = useMemo( - () => - (data && [ - { value: 'all', label: t('All') }, - ...data.users.map((user) => ({ value: user._id, label: user.name })), - ]) || [{ value: 'all', label: t('All') }], - [data, t], + + const { phase: agentsPhase, items: agentsItems, itemCount: agentsTotal } = useRecordList( + AgentsList, ); + const sortedByName = agentsItems.sort((a, b) => { + if (a.value === 'all') { + return -1; + } + + if (a.usename > b.usename) { + return 1; + } + if (a.usename < b.usename) { + return -1; + } + + return 0; + }); + return ( - <>{label}} - renderItem={({ value, ...props }) =>