From 75a6657d793973aca67d155130de79fc8c2923e9 Mon Sep 17 00:00:00 2001 From: Github Date: Tue, 11 Feb 2025 18:17:59 +0100 Subject: [PATCH 1/6] Add Troubleshoot menu to PublicScreens --- src/hooks/useDebugShortcut.ts | 26 +++++++++++++++++++ .../Navigation/AppNavigator/AuthScreens.tsx | 12 ++------- .../Navigation/AppNavigator/PublicScreens.tsx | 5 ++++ 3 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 src/hooks/useDebugShortcut.ts diff --git a/src/hooks/useDebugShortcut.ts b/src/hooks/useDebugShortcut.ts new file mode 100644 index 000000000000..38b2abccce0c --- /dev/null +++ b/src/hooks/useDebugShortcut.ts @@ -0,0 +1,26 @@ +import {useEffect} from 'react'; +import KeyboardShortcut from '@libs/KeyboardShortcut'; +import toggleTestToolsModal from '@userActions/TestTool'; +import CONST from '@src/CONST'; + +function useDebugShortcut() { + useEffect(() => { + const debugShortcutConfig = CONST.KEYBOARD_SHORTCUTS.DEBUG; + const unsubscribeDebugShortcut = KeyboardShortcut.subscribe( + debugShortcutConfig.shortcutKey, + () => toggleTestToolsModal(), + debugShortcutConfig.descriptionKey, + debugShortcutConfig.modifiers, + true, + ); + + return () => { + unsubscribeDebugShortcut(); + }; + + // Rule disabled because this effect is only for component did mount & will component unmount lifecycle event + // eslint-disable-next-line react-compiler/react-compiler, react-hooks/exhaustive-deps + }, []); +} + +export default useDebugShortcut; diff --git a/src/libs/Navigation/AppNavigator/AuthScreens.tsx b/src/libs/Navigation/AppNavigator/AuthScreens.tsx index 4ed6f22f3f3b..11ae9ed797c1 100644 --- a/src/libs/Navigation/AppNavigator/AuthScreens.tsx +++ b/src/libs/Navigation/AppNavigator/AuthScreens.tsx @@ -13,6 +13,7 @@ import {useSearchRouterContext} from '@components/Search/SearchRouter/SearchRout import SearchRouterModal from '@components/Search/SearchRouter/SearchRouterModal'; import TestToolsModal from '@components/TestToolsModal'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; +import useDebugShortcut from '@hooks/useDebugShortcut'; import useOnboardingFlowRouter from '@hooks/useOnboardingFlow'; import {ReportIDsContextProvider} from '@hooks/useReportIDs'; import useResponsiveLayout from '@hooks/useResponsiveLayout'; @@ -219,6 +220,7 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie const rootNavigatorScreenOptions = useRootNavigatorScreenOptions(); const currentUserPersonalDetails = useCurrentUserPersonalDetails(); const {toggleSearch} = useSearchRouterContext(); + useDebugShortcut(); const modal = useRef({}); const {isOnboardingCompleted} = useOnboardingFlowRouter(); @@ -248,7 +250,6 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie const shortcutsOverviewShortcutConfig = CONST.KEYBOARD_SHORTCUTS.SHORTCUTS; const searchShortcutConfig = CONST.KEYBOARD_SHORTCUTS.SEARCH; const chatShortcutConfig = CONST.KEYBOARD_SHORTCUTS.NEW_CHAT; - const debugShortcutConfig = CONST.KEYBOARD_SHORTCUTS.DEBUG; const currentUrl = getCurrentUrl(); const isLoggingInAsNewUser = !!session?.email && SessionUtils.isLoggingInAsNewUser(currentUrl, session.email); // Sign out the current user if we're transitioning with a different user @@ -364,21 +365,12 @@ function AuthScreens({session, lastOpenedPublicRoomID, initialLastUpdateIDApplie true, ); - const unsubscribeDebugShortcut = KeyboardShortcut.subscribe( - debugShortcutConfig.shortcutKey, - () => toggleTestToolsModal(), - debugShortcutConfig.descriptionKey, - debugShortcutConfig.modifiers, - true, - ); - return () => { unsubscribeEscapeKey(); unsubscribeOnyxModal(); unsubscribeShortcutsOverviewShortcut(); unsubscribeSearchShortcut(); unsubscribeChatShortcut(); - unsubscribeDebugShortcut(); Session.cleanupSession(); }; diff --git a/src/libs/Navigation/AppNavigator/PublicScreens.tsx b/src/libs/Navigation/AppNavigator/PublicScreens.tsx index 77e379e80293..b6945e9e3b17 100644 --- a/src/libs/Navigation/AppNavigator/PublicScreens.tsx +++ b/src/libs/Navigation/AppNavigator/PublicScreens.tsx @@ -1,5 +1,7 @@ import React from 'react'; import {NativeModules} from 'react-native'; +import TestToolsModal from '@components/TestToolsModal'; +import useDebugShortcut from '@hooks/useDebugShortcut'; import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator'; import type {PublicScreensParamList} from '@navigation/types'; import ConnectionCompletePage from '@pages/ConnectionCompletePage'; @@ -18,6 +20,8 @@ import defaultScreenOptions from './defaultScreenOptions'; const RootStack = createPlatformStackNavigator(); function PublicScreens() { + useDebugShortcut(); + return ( {/* The structure for the HOME route has to be the same in public and auth screens. That's why the name for SignInPage is REPORTS_SPLIT_NAVIGATOR. */} @@ -59,6 +63,7 @@ function PublicScreens() { name={SCREENS.SAML_SIGN_IN} component={SAMLSignInPage} /> + ); } From 9ee1e608788d686644d4ca9c2748038147c89707 Mon Sep 17 00:00:00 2001 From: Github Date: Mon, 17 Feb 2025 14:21:35 +0100 Subject: [PATCH 2/6] disable viewConsole for unauthenticated users --- src/Expensify.tsx | 5 +++++ src/components/TestToolsModal.tsx | 7 +++++-- src/libs/Navigation/AppNavigator/AuthScreens.tsx | 5 ----- src/libs/Navigation/AppNavigator/PublicScreens.tsx | 5 ----- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/Expensify.tsx b/src/Expensify.tsx index e446f1e725a9..6e4e2d4e36fc 100644 --- a/src/Expensify.tsx +++ b/src/Expensify.tsx @@ -12,9 +12,11 @@ import GrowlNotification from './components/GrowlNotification'; import RequireTwoFactorAuthenticationModal from './components/RequireTwoFactorAuthenticationModal'; import AppleAuthWrapper from './components/SignInButtons/AppleAuthWrapper'; import SplashScreenHider from './components/SplashScreenHider'; +import TestToolsModal from './components/TestToolsModal'; import UpdateAppModal from './components/UpdateAppModal'; import * as CONFIG from './CONFIG'; import CONST from './CONST'; +import useDebugShortcut from './hooks/useDebugShortcut'; import useLocalize from './hooks/useLocalize'; import {updateLastRoute} from './libs/actions/App'; import * as EmojiPickerAction from './libs/actions/EmojiPickerAction'; @@ -96,6 +98,8 @@ function Expensify() { const [focusModeNotification] = useOnyx(ONYXKEYS.FOCUS_MODE_NOTIFICATION, {initWithStoredValues: false}); const [lastVisitedPath] = useOnyx(ONYXKEYS.LAST_VISITED_PATH); + useDebugShortcut(); + useEffect(() => { if (!account?.needsTwoFactorAuthSetup || account.requiresTwoFactorAuth) { return; @@ -295,6 +299,7 @@ function Expensify() { /> )} {shouldHideSplash && } + ); } diff --git a/src/components/TestToolsModal.tsx b/src/components/TestToolsModal.tsx index 7c2e161b2d11..4128d8d594f8 100644 --- a/src/components/TestToolsModal.tsx +++ b/src/components/TestToolsModal.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useMemo} from 'react'; import {View} from 'react-native'; import {useOnyx} from 'react-native-onyx'; import useLocalize from '@hooks/useLocalize'; @@ -25,7 +25,10 @@ function TestToolsModal() { const StyleUtils = useStyleUtils(); const styles = useThemeStyles(); const {translate} = useLocalize(); + const [session] = useOnyx(ONYXKEYS.SESSION); + // Check if the user is authenticated to show the debug console as Right Modal is not visible for unauthenticated users + const isAuthenticated = useMemo(() => !!(session?.authToken ?? null), [session]); return ( - {!!shouldStoreLogs && ( + {!!shouldStoreLogs && isAuthenticated && (