From bd7fc43ea5ccd2541c702a38aec6931067163684 Mon Sep 17 00:00:00 2001 From: Yuwen Memon Date: Wed, 29 Jan 2025 12:30:36 -0800 Subject: [PATCH] Revert "fix: On selecting a category/ tags by multiple tapping, user directed to conversation page." --- src/components/SelectionList/BaseSelectionList.tsx | 4 ---- src/pages/WorkspaceSwitcherPage/index.tsx | 7 ++++++- tests/unit/BaseSelectionListTest.tsx | 10 ---------- 3 files changed, 6 insertions(+), 15 deletions(-) diff --git a/src/components/SelectionList/BaseSelectionList.tsx b/src/components/SelectionList/BaseSelectionList.tsx index b38e7fbbe0db..86a9d8adbd76 100644 --- a/src/components/SelectionList/BaseSelectionList.tsx +++ b/src/components/SelectionList/BaseSelectionList.tsx @@ -361,9 +361,6 @@ function BaseSelectionList( */ const selectRow = useCallback( (item: TItem, indexToFocus?: number) => { - if (!isFocused) { - return; - } // In single-selection lists we don't care about updating the focused index, because the list is closed after selecting an item if (canSelectMultiple) { if (sections.length > 1) { @@ -404,7 +401,6 @@ function BaseSelectionList( setFocusedIndex, onSelectRow, shouldPreventDefaultFocusOnSelectRow, - isFocused, ], ); diff --git a/src/pages/WorkspaceSwitcherPage/index.tsx b/src/pages/WorkspaceSwitcherPage/index.tsx index ba39c2789c38..493c0c6e2994 100644 --- a/src/pages/WorkspaceSwitcherPage/index.tsx +++ b/src/pages/WorkspaceSwitcherPage/index.tsx @@ -1,3 +1,4 @@ +import {useIsFocused} from '@react-navigation/native'; import React, {useCallback, useMemo} from 'react'; import {useOnyx} from 'react-native-onyx'; import FullScreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; @@ -38,6 +39,7 @@ function WorkspaceSwitcherPage() { const [searchTerm, debouncedSearchTerm, setSearchTerm] = useDebouncedState(''); const {translate} = useLocalize(); const {activeWorkspaceID, setActiveWorkspaceID} = useActiveWorkspace(); + const isFocused = useIsFocused(); const [reports] = useOnyx(ONYXKEYS.COLLECTION.REPORT); const [reportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS); @@ -81,6 +83,9 @@ function WorkspaceSwitcherPage() { const selectPolicy = useCallback( (policyID?: string) => { + if (!isFocused) { + return; + } const newPolicyID = policyID === activeWorkspaceID ? undefined : policyID; Navigation.goBack(); @@ -88,7 +93,7 @@ function WorkspaceSwitcherPage() { // Therefore we delay switching the workspace until after back navigation, using the InteractionManager. switchPolicyAfterInteractions(newPolicyID, () => setActiveWorkspaceID(newPolicyID)); }, - [activeWorkspaceID, setActiveWorkspaceID], + [activeWorkspaceID, setActiveWorkspaceID, isFocused], ); const usersWorkspaces = useMemo(() => { diff --git a/tests/unit/BaseSelectionListTest.tsx b/tests/unit/BaseSelectionListTest.tsx index a1083c840f6f..673ea50b58d6 100644 --- a/tests/unit/BaseSelectionListTest.tsx +++ b/tests/unit/BaseSelectionListTest.tsx @@ -1,4 +1,3 @@ -import * as NativeNavigation from '@react-navigation/native'; import {fireEvent, render, screen} from '@testing-library/react-native'; import BaseSelectionList from '@components/SelectionList/BaseSelectionList'; import RadioListItem from '@components/SelectionList/RadioListItem'; @@ -42,15 +41,7 @@ describe('BaseSelectionList', () => { ); } - it('should not trigger item press if screen is not focused', () => { - (NativeNavigation.useIsFocused as jest.Mock).mockReturnValue(false); - render(); - fireEvent.press(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`)); - expect(onSelectRowMock).toHaveBeenCalledTimes(0); - }); - it('should handle item press correctly', () => { - (NativeNavigation.useIsFocused as jest.Mock).mockReturnValue(true); render(); fireEvent.press(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`)); expect(onSelectRowMock).toHaveBeenCalledWith({ @@ -64,7 +55,6 @@ describe('BaseSelectionList', () => { ...section, isSelected: section.keyForList === '2', })); - (NativeNavigation.useIsFocused as jest.Mock).mockReturnValue(true); const {rerender} = render(); expect(screen.getByTestId(`${CONST.BASE_LIST_ITEM_TEST_ID}1`)).toBeSelected(); rerender();