From 5ca5edf204adf23842b129f10fceddd2f505d792 Mon Sep 17 00:00:00 2001 From: Tiago Evangelista Pinto Date: Mon, 21 Jun 2021 19:37:31 -0300 Subject: [PATCH] [FIX] Rewrite CurrentChats to TS (#22424) --- .github/workflows/build_and_test.yml | 6 +- client/components/AutoCompleteAgent.js | 63 ++++++++++------- client/components/AutoCompleteDepartment.js | 10 ++- client/components/GenericTable/HeaderCell.tsx | 4 +- .../Omnichannel/hooks/useAgentsList.ts | 70 +++++++++++++++++++ .../Omnichannel/hooks/useDepartmentsList.ts | 47 +++++++++---- .../Omnichannel/modals/ForwardChatModal.js | 1 + client/components/Page/PageContent.tsx | 7 +- client/contexts/ServerContext/endpoints.ts | 6 ++ .../endpoints/v1/livechat/customFields.ts | 10 +++ .../endpoints/v1/livechat/rooms.ts | 15 ++++ .../endpoints/v1/livechat/usersAgent.ts | 27 +++++++ .../omnichannel/analytics/AnalyticsPage.js | 2 +- .../currentChats/CurrentChatsPage.js | 32 --------- .../currentChats/CurrentChatsPage.tsx | 35 ++++++++++ ...entChatsRoute.js => CurrentChatsRoute.tsx} | 61 +++++++++++----- .../{FilterByText.js => FilterByText.tsx} | 55 +++++++++------ .../views/omnichannel/currentChats/Label.js | 6 -- .../views/omnichannel/currentChats/Label.tsx | 8 +++ ...RemoveAllClosed.js => RemoveAllClosed.tsx} | 7 +- ...moveChatButton.js => RemoveChatButton.tsx} | 12 ++-- .../RealTimeMonitoringPage.js | 43 ++++++------ definition/ILivechatAgentRecord.ts | 17 +++++ .../additionalForms/DepartmentForwarding.js | 1 + package-lock.json | 6 +- package.json | 2 +- packages/rocketchat-i18n/i18n/en.i18n.json | 2 + 27 files changed, 393 insertions(+), 162 deletions(-) create mode 100644 client/components/Omnichannel/hooks/useAgentsList.ts create mode 100644 client/contexts/ServerContext/endpoints/v1/livechat/customFields.ts create mode 100644 client/contexts/ServerContext/endpoints/v1/livechat/rooms.ts create mode 100644 client/contexts/ServerContext/endpoints/v1/livechat/usersAgent.ts delete mode 100644 client/views/omnichannel/currentChats/CurrentChatsPage.js create mode 100644 client/views/omnichannel/currentChats/CurrentChatsPage.tsx rename client/views/omnichannel/currentChats/{CurrentChatsRoute.js => CurrentChatsRoute.tsx} (83%) rename client/views/omnichannel/currentChats/{FilterByText.js => FilterByText.tsx} (80%) delete mode 100644 client/views/omnichannel/currentChats/Label.js create mode 100644 client/views/omnichannel/currentChats/Label.tsx rename client/views/omnichannel/currentChats/{RemoveAllClosed.js => RemoveAllClosed.tsx} (83%) rename client/views/omnichannel/currentChats/{RemoveChatButton.js => RemoveChatButton.tsx} (85%) create mode 100644 definition/ILivechatAgentRecord.ts diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 768d755455f78..8579f0ffd353c 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 4c521fe652b28..7e45c9b1f0428 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 }) =>