From e9f5409651f9e6b50b4646534f0254b91687cbf1 Mon Sep 17 00:00:00 2001 From: dougfabris Date: Fri, 2 Aug 2024 18:00:54 -0300 Subject: [PATCH] chore: sanitize `FilterByText` onChange handler --- apps/meteor/client/components/FilterByText.tsx | 13 +++++-------- .../businessHours/BusinessHoursTable.tsx | 2 +- .../client/omnichannel/monitors/MonitorsTable.tsx | 2 +- .../client/omnichannel/slaPolicies/SlaTable.tsx | 2 +- apps/meteor/client/omnichannel/tags/TagsTable.tsx | 2 +- apps/meteor/client/omnichannel/units/UnitsTable.tsx | 2 +- .../client/views/admin/customEmoji/CustomEmoji.tsx | 2 +- .../CustomSoundsTable/CustomSoundsTable.tsx | 2 +- .../CustomUserStatusTable/CustomUserStatusTable.tsx | 2 +- .../DeviceManagementAdminTable.tsx | 2 +- .../views/admin/integrations/IntegrationsTable.tsx | 2 +- .../admin/moderation/helpers/ModerationFilter.tsx | 6 ++---- .../admin/users/UsersTable/UsersTableFilters.tsx | 2 +- .../tabs/channels/ChannelsTable/ChannelsTable.tsx | 2 +- .../directory/tabs/teams/TeamsTable/TeamsTable.tsx | 2 +- .../directory/tabs/users/UsersTable/UsersTable.tsx | 2 +- .../views/marketplace/AppsPage/AppsFilters.tsx | 2 +- .../omnichannel/agents/AgentsTable/AgentsTable.tsx | 2 +- .../omnichannel/customFields/CustomFieldsTable.tsx | 2 +- .../DepartmentsTable/DepartmentsTable.tsx | 2 +- .../views/omnichannel/directory/calls/CallTable.tsx | 2 +- .../views/omnichannel/directory/chats/ChatTable.tsx | 2 +- .../omnichannel/directory/contacts/ContactTable.tsx | 2 +- .../views/omnichannel/managers/ManagersTable.tsx | 2 +- .../WebdavFilePickerModal/WebdavFilePickerModal.tsx | 2 +- 25 files changed, 30 insertions(+), 35 deletions(-) diff --git a/apps/meteor/client/components/FilterByText.tsx b/apps/meteor/client/components/FilterByText.tsx index 285c04164ce35..5db4c5f2fbd39 100644 --- a/apps/meteor/client/components/FilterByText.tsx +++ b/apps/meteor/client/components/FilterByText.tsx @@ -2,10 +2,10 @@ import { Box, Icon, TextInput, Margins } from '@rocket.chat/fuselage'; import { useAutoFocus, useMergedRefs } from '@rocket.chat/fuselage-hooks'; import { useTranslation } from '@rocket.chat/ui-contexts'; import type { ChangeEvent, FormEvent, AllHTMLAttributes } from 'react'; -import React, { forwardRef, memo, useCallback, useEffect, useState } from 'react'; +import React, { forwardRef, memo, useCallback, useState } from 'react'; type FilterByTextProps = { - onChange: (filter: { text: string }) => void; + onChange: (filter: string) => void; shouldAutoFocus?: boolean; } & Omit, 'is' | 'onChange'>; @@ -18,13 +18,10 @@ const FilterByText = forwardRef(function Fi const autoFocusRef = useAutoFocus(shouldAutoFocus); const mergedRefs = useMergedRefs(ref, autoFocusRef); - const handleInputChange = useCallback((event: ChangeEvent) => { + const handleInputChange = (event: ChangeEvent) => { setText(event.currentTarget.value); - }, []); - - useEffect(() => { - setFilter({ text }); - }, [setFilter, text]); + setFilter(event.currentTarget.value); + }; const handleFormSubmit = useCallback((event: FormEvent) => { event.preventDefault(); diff --git a/apps/meteor/client/omnichannel/businessHours/BusinessHoursTable.tsx b/apps/meteor/client/omnichannel/businessHours/BusinessHoursTable.tsx index 6fddd95859d82..b4220e420a9ab 100644 --- a/apps/meteor/client/omnichannel/businessHours/BusinessHoursTable.tsx +++ b/apps/meteor/client/omnichannel/businessHours/BusinessHoursTable.tsx @@ -47,7 +47,7 @@ const BusinessHoursTable = () => { return ( <> - setText(text)} /> + {isLoading && ( {headers} diff --git a/apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx b/apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx index a67057b9add16..62adc2a0405fe 100644 --- a/apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx +++ b/apps/meteor/client/omnichannel/monitors/MonitorsTable.tsx @@ -144,7 +144,7 @@ const MonitorsTable = () => { - {((isSuccess && data?.monitors.length > 0) || queryHasChanged) && setText(text)} />} + {((isSuccess && data?.monitors.length > 0) || queryHasChanged) && } {isLoading && ( {headers} diff --git a/apps/meteor/client/omnichannel/slaPolicies/SlaTable.tsx b/apps/meteor/client/omnichannel/slaPolicies/SlaTable.tsx index d550118a5017d..01b4bfe903748 100644 --- a/apps/meteor/client/omnichannel/slaPolicies/SlaTable.tsx +++ b/apps/meteor/client/omnichannel/slaPolicies/SlaTable.tsx @@ -84,7 +84,7 @@ const SlaTable = ({ reload }: { reload: MutableRefObject<() => void> }) => { return ( <> - {((isSuccess && data?.sla.length > 0) || queryHasChanged) && setFilter(text)} />} + {((isSuccess && data?.sla.length > 0) || queryHasChanged) && } {isLoading && ( {headers} diff --git a/apps/meteor/client/omnichannel/tags/TagsTable.tsx b/apps/meteor/client/omnichannel/tags/TagsTable.tsx index 3b9757134bedd..a4b31cd4755c3 100644 --- a/apps/meteor/client/omnichannel/tags/TagsTable.tsx +++ b/apps/meteor/client/omnichannel/tags/TagsTable.tsx @@ -70,7 +70,7 @@ const TagsTable = () => { return ( <> - {((isSuccess && data?.tags.length > 0) || queryHasChanged) && setFilter(text)} />} + {((isSuccess && data?.tags.length > 0) || queryHasChanged) && } {isLoading && ( {headers} diff --git a/apps/meteor/client/omnichannel/units/UnitsTable.tsx b/apps/meteor/client/omnichannel/units/UnitsTable.tsx index fe95bc90d8a20..93734acb8de0d 100644 --- a/apps/meteor/client/omnichannel/units/UnitsTable.tsx +++ b/apps/meteor/client/omnichannel/units/UnitsTable.tsx @@ -69,7 +69,7 @@ const UnitsTable = () => { return ( <> - {((isSuccess && data?.units.length > 0) || queryHasChanged) && setFilter(text)} />} + {((isSuccess && data?.units.length > 0) || queryHasChanged) && } {isLoading && ( {headers} diff --git a/apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx b/apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx index abfa438d9ced8..2bd795c3ccab7 100644 --- a/apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx +++ b/apps/meteor/client/views/admin/customEmoji/CustomEmoji.tsx @@ -66,7 +66,7 @@ const CustomEmoji = ({ onClick, reload }: CustomEmojiProps) => { return ( <> - setText(text)} /> + {isLoading && ( {headers} diff --git a/apps/meteor/client/views/admin/customSounds/CustomSoundsTable/CustomSoundsTable.tsx b/apps/meteor/client/views/admin/customSounds/CustomSoundsTable/CustomSoundsTable.tsx index 58b1c4ea7b8af..5e8bd0c0fac9b 100644 --- a/apps/meteor/client/views/admin/customSounds/CustomSoundsTable/CustomSoundsTable.tsx +++ b/apps/meteor/client/views/admin/customSounds/CustomSoundsTable/CustomSoundsTable.tsx @@ -64,7 +64,7 @@ const CustomSoundsTable = ({ reload, onClick }: CustomSoundsTableProps) => { return ( <> - setParams(text)} /> + {isLoading && ( {headers} diff --git a/apps/meteor/client/views/admin/customUserStatus/CustomUserStatusTable/CustomUserStatusTable.tsx b/apps/meteor/client/views/admin/customUserStatus/CustomUserStatusTable/CustomUserStatusTable.tsx index 59c4cdd74eb33..d18fc4a706a8b 100644 --- a/apps/meteor/client/views/admin/customUserStatus/CustomUserStatusTable/CustomUserStatusTable.tsx +++ b/apps/meteor/client/views/admin/customUserStatus/CustomUserStatusTable/CustomUserStatusTable.tsx @@ -70,7 +70,7 @@ const CustomUserStatus = ({ reload, onClick }: CustomUserStatusProps): ReactElem return ( <> - setText(text)} /> + {data.length === 0 && } {data && data.length > 0 && ( <> diff --git a/apps/meteor/client/views/admin/deviceManagement/DeviceManagementAdminTable/DeviceManagementAdminTable.tsx b/apps/meteor/client/views/admin/deviceManagement/DeviceManagementAdminTable/DeviceManagementAdminTable.tsx index 026f1cb0de30b..ebd1e762ff805 100644 --- a/apps/meteor/client/views/admin/deviceManagement/DeviceManagementAdminTable/DeviceManagementAdminTable.tsx +++ b/apps/meteor/client/views/admin/deviceManagement/DeviceManagementAdminTable/DeviceManagementAdminTable.tsx @@ -76,7 +76,7 @@ const DeviceManagementAdminTable = ({ reloadRef }: { reloadRef: MutableRefObject return ( <> - setText(text)} /> + { return ( <> - setText(text)} /> + {isLoading && ( {headers} diff --git a/apps/meteor/client/views/admin/moderation/helpers/ModerationFilter.tsx b/apps/meteor/client/views/admin/moderation/helpers/ModerationFilter.tsx index 4fde3568b2aa3..5414e3d06aa54 100644 --- a/apps/meteor/client/views/admin/moderation/helpers/ModerationFilter.tsx +++ b/apps/meteor/client/views/admin/moderation/helpers/ModerationFilter.tsx @@ -1,5 +1,5 @@ import { useTranslation } from '@rocket.chat/ui-contexts'; -import React, { useCallback } from 'react'; +import React from 'react'; import FilterByText from '../../../../components/FilterByText'; import DateRangePicker from './DateRangePicker'; @@ -12,10 +12,8 @@ type ModerationFilterProps = { const ModerationFilter = ({ setText, setDateRange }: ModerationFilterProps) => { const t = useTranslation(); - const handleChange = useCallback(({ text }): void => setText(text), [setText]); - return ( - + ); diff --git a/apps/meteor/client/views/admin/users/UsersTable/UsersTableFilters.tsx b/apps/meteor/client/views/admin/users/UsersTable/UsersTableFilters.tsx index 28508ac94ac5c..e3b919ae4a029 100644 --- a/apps/meteor/client/views/admin/users/UsersTable/UsersTableFilters.tsx +++ b/apps/meteor/client/views/admin/users/UsersTable/UsersTableFilters.tsx @@ -20,7 +20,7 @@ const UsersTableFilters = ({ roleData, setUsersFilters }: UsersTableFiltersProps const [text, setText] = useState(''); const handleSearchTextChange = useCallback( - ({ text }) => { + (text) => { setUsersFilters({ text, roles: selectedRoles }); setText(text); }, diff --git a/apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTable.tsx b/apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTable.tsx index 8ec510eed76dd..cbd4671bc0765 100644 --- a/apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTable.tsx +++ b/apps/meteor/client/views/directory/tabs/channels/ChannelsTable/ChannelsTable.tsx @@ -96,7 +96,7 @@ const ChannelsTable = () => { return ( <> - setText(text)} /> + {isLoading && ( {headers} diff --git a/apps/meteor/client/views/directory/tabs/teams/TeamsTable/TeamsTable.tsx b/apps/meteor/client/views/directory/tabs/teams/TeamsTable/TeamsTable.tsx index f33b359e4b073..43e6e0e6cdf61 100644 --- a/apps/meteor/client/views/directory/tabs/teams/TeamsTable/TeamsTable.tsx +++ b/apps/meteor/client/views/directory/tabs/teams/TeamsTable/TeamsTable.tsx @@ -73,7 +73,7 @@ const TeamsTable = () => { return ( <> - setText(text)} /> + {isLoading && ( {headers} diff --git a/apps/meteor/client/views/directory/tabs/users/UsersTable/UsersTable.tsx b/apps/meteor/client/views/directory/tabs/users/UsersTable/UsersTable.tsx index 5b69a59909ca6..db01bdf59201d 100644 --- a/apps/meteor/client/views/directory/tabs/users/UsersTable/UsersTable.tsx +++ b/apps/meteor/client/views/directory/tabs/users/UsersTable/UsersTable.tsx @@ -95,7 +95,7 @@ const UsersTable = ({ workspace = 'local' }): ReactElement => { return ( <> - setText(text)} /> + {isLoading && ( {headers} diff --git a/apps/meteor/client/views/marketplace/AppsPage/AppsFilters.tsx b/apps/meteor/client/views/marketplace/AppsPage/AppsFilters.tsx index c411366c6b1f6..a1f486395dbba 100644 --- a/apps/meteor/client/views/marketplace/AppsPage/AppsFilters.tsx +++ b/apps/meteor/client/views/marketplace/AppsPage/AppsFilters.tsx @@ -60,7 +60,7 @@ const AppsFilters = ({ return ( - setText(text)}> + {!isPrivateAppsPage && ( )} diff --git a/apps/meteor/client/views/omnichannel/agents/AgentsTable/AgentsTable.tsx b/apps/meteor/client/views/omnichannel/agents/AgentsTable/AgentsTable.tsx index 5d0e89e1008a2..13e1498d7422b 100644 --- a/apps/meteor/client/views/omnichannel/agents/AgentsTable/AgentsTable.tsx +++ b/apps/meteor/client/views/omnichannel/agents/AgentsTable/AgentsTable.tsx @@ -73,7 +73,7 @@ const AgentsTable = () => { return ( <> - {((isSuccess && data?.users.length > 0) || queryHasChanged) && setFilter(text)} />} + {((isSuccess && data?.users.length > 0) || queryHasChanged) && } {isLoading && ( {headers} diff --git a/apps/meteor/client/views/omnichannel/customFields/CustomFieldsTable.tsx b/apps/meteor/client/views/omnichannel/customFields/CustomFieldsTable.tsx index d8609293c2c5e..f8043a1788579 100644 --- a/apps/meteor/client/views/omnichannel/customFields/CustomFieldsTable.tsx +++ b/apps/meteor/client/views/omnichannel/customFields/CustomFieldsTable.tsx @@ -75,7 +75,7 @@ const CustomFieldsTable = () => { return ( <> - {((isSuccess && data?.customFields.length > 0) || queryHasChanged) && setFilter(text)} />} + {((isSuccess && data?.customFields.length > 0) || queryHasChanged) && } {isLoading && ( {headers} diff --git a/apps/meteor/client/views/omnichannel/departments/DepartmentsTable/DepartmentsTable.tsx b/apps/meteor/client/views/omnichannel/departments/DepartmentsTable/DepartmentsTable.tsx index 7aee3f534d420..46ef80d5b0e32 100644 --- a/apps/meteor/client/views/omnichannel/departments/DepartmentsTable/DepartmentsTable.tsx +++ b/apps/meteor/client/views/omnichannel/departments/DepartmentsTable/DepartmentsTable.tsx @@ -91,7 +91,7 @@ const DepartmentsTable = ({ archived }: { archived: boolean }) => { return ( <> - {((isSuccess && data?.departments.length > 0) || queryHasChanged) && setText(text)} />} + {((isSuccess && data?.departments.length > 0) || queryHasChanged) && } {isLoading && ( {headers} diff --git a/apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx b/apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx index 916a866b0431b..2b529999fea16 100644 --- a/apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx +++ b/apps/meteor/client/views/omnichannel/directory/calls/CallTable.tsx @@ -95,7 +95,7 @@ const CallTable = () => { return ( <> - {((isSuccess && data?.rooms.length > 0) || queryHasChanged) && setText(text)} />} + {((isSuccess && data?.rooms.length > 0) || queryHasChanged) && } {isLoading && ( {headers} diff --git a/apps/meteor/client/views/omnichannel/directory/chats/ChatTable.tsx b/apps/meteor/client/views/omnichannel/directory/chats/ChatTable.tsx index e11a1c3320663..c6d090c7547c3 100644 --- a/apps/meteor/client/views/omnichannel/directory/chats/ChatTable.tsx +++ b/apps/meteor/client/views/omnichannel/directory/chats/ChatTable.tsx @@ -134,7 +134,7 @@ const ChatTable = () => { return ( <> - {((isSuccess && data?.rooms.length > 0) || queryHasChanged) && setText(text)} />} + {((isSuccess && data?.rooms.length > 0) || queryHasChanged) && } {isLoading && ( {headers} diff --git a/apps/meteor/client/views/omnichannel/directory/contacts/ContactTable.tsx b/apps/meteor/client/views/omnichannel/directory/contacts/ContactTable.tsx index 901bff74121da..09ec19e6a2fee 100644 --- a/apps/meteor/client/views/omnichannel/directory/contacts/ContactTable.tsx +++ b/apps/meteor/client/views/omnichannel/directory/contacts/ContactTable.tsx @@ -106,7 +106,7 @@ function ContactTable(): ReactElement { return ( <> {((isSuccess && data?.visitors.length > 0) || queryHasChanged) && ( - setTerm(text)}> + diff --git a/apps/meteor/client/views/omnichannel/managers/ManagersTable.tsx b/apps/meteor/client/views/omnichannel/managers/ManagersTable.tsx index afb2ae8f351bf..a60d41c0c3aaa 100644 --- a/apps/meteor/client/views/omnichannel/managers/ManagersTable.tsx +++ b/apps/meteor/client/views/omnichannel/managers/ManagersTable.tsx @@ -80,7 +80,7 @@ const ManagersTable = () => { return ( <> - {((isSuccess && data?.users.length > 0) || queryHasChanged) && setText(text)} />} + {((isSuccess && data?.users.length > 0) || queryHasChanged) && } {isLoading && ( {headers} diff --git a/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/WebdavFilePickerModal.tsx b/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/WebdavFilePickerModal.tsx index 4b75e496cefe8..38895d4c211e0 100644 --- a/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/WebdavFilePickerModal.tsx +++ b/apps/meteor/client/views/room/webdav/WebdavFilePickerModal/WebdavFilePickerModal.tsx @@ -196,7 +196,7 @@ const WebdavFilePickerModal = ({ onUpload, onClose, account }: WebdavFilePickerM - setFilterText(text)}> + {typeView === 'grid' && (