Skip to content

Commit

Permalink
Merge pull request #40656 from ShridharGoel/view-logs
Browse files Browse the repository at this point in the history
Show console debug logs via test tools menu
  • Loading branch information
Beamanator authored May 30, 2024
2 parents 9e9d8cd + f7d5ead commit ef6e012
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ const ROUTES = {
SETTINGS_STATUS_CLEAR_AFTER_DATE: 'settings/profile/status/clear-after/date',
SETTINGS_STATUS_CLEAR_AFTER_TIME: 'settings/profile/status/clear-after/time',
SETTINGS_TROUBLESHOOT: 'settings/troubleshoot',
SETTINGS_CONSOLE: 'settings/troubleshoot/console',
SETTINGS_CONSOLE: {
route: 'settings/troubleshoot/console',
getRoute: (backTo?: string) => getUrlWithBackToParam(`settings/troubleshoot/console`, backTo),
},
SETTINGS_SHARE_LOG: {
route: 'settings/troubleshoot/console/share-log',
getRoute: (source: string) => `settings/troubleshoot/console/share-log?source=${encodeURI(source)}` as const,
Expand Down
24 changes: 23 additions & 1 deletion src/components/TestToolsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,30 @@ import useLocalize from '@hooks/useLocalize';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@navigation/Navigation';
import toggleTestToolsModal from '@userActions/TestTool';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import Button from './Button';
import ClientSideLoggingToolMenu from './ClientSideLoggingToolMenu';
import Modal from './Modal';
import ProfilingToolMenu from './ProfilingToolMenu';
import TestToolMenu from './TestToolMenu';
import TestToolRow from './TestToolRow';
import Text from './Text';

type TestToolsModalOnyxProps = {
/** Whether the test tools modal is open */
isTestToolsModalOpen: OnyxEntry<boolean>;

/** Whether or not logs should be stored */
shouldStoreLogs: OnyxEntry<boolean>;
};

type TestToolsModalProps = TestToolsModalOnyxProps;

function TestToolsModal({isTestToolsModalOpen = false}: TestToolsModalProps) {
function TestToolsModal({isTestToolsModalOpen = false, shouldStoreLogs = false}: TestToolsModalProps) {
const {isDevelopment} = useEnvironment();
const {windowWidth} = useWindowDimensions();
const StyleUtils = useStyleUtils();
Expand All @@ -46,6 +53,18 @@ function TestToolsModal({isTestToolsModalOpen = false}: TestToolsModalProps) {
</Text>
<ProfilingToolMenu />
<ClientSideLoggingToolMenu />
{!!shouldStoreLogs && (
<TestToolRow title={translate('initialSettingsPage.troubleshoot.debugConsole')}>
<Button
small
text={translate('initialSettingsPage.debugConsole.viewConsole')}
onPress={() => {
toggleTestToolsModal();
Navigation.navigate(ROUTES.SETTINGS_CONSOLE.getRoute(Navigation.getActiveRoute()));
}}
/>
</TestToolRow>
)}
</View>
</Modal>
);
Expand All @@ -57,4 +76,7 @@ export default withOnyx<TestToolsModalProps, TestToolsModalOnyxProps>({
isTestToolsModalOpen: {
key: ONYXKEYS.IS_TEST_TOOLS_MODAL_OPEN,
},
shouldStoreLogs: {
key: ONYXKEYS.SHOULD_STORE_LOGS,
},
})(TestToolsModal);
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ export default {
noLogsAvailable: 'No logs available',
logSizeTooLarge: ({size}: LogSizeParams) => `Log size exceeds the limit of ${size} MB. Please use "Save log" to download the log file instead.`,
logs: 'Logs',
viewConsole: 'View console',
},
security: 'Security',
signOut: 'Sign out',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ export default {
noLogsAvailable: 'No hay registros disponibles',
logSizeTooLarge: ({size}: LogSizeParams) => `El tamaño del registro excede el límite de ${size} MB. Utilice "Guardar registro" para descargar el archivo de registro.`,
logs: 'Logs',
viewConsole: 'Ver consola',
},
security: 'Seguridad',
restoreStashed: 'Restablecer login guardado',
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
exact: true,
},
[SCREENS.SETTINGS.CONSOLE]: {
path: ROUTES.SETTINGS_CONSOLE,
path: ROUTES.SETTINGS_CONSOLE.route,
exact: true,
},
[SCREENS.SETTINGS.SHARE_LOG]: ROUTES.SETTINGS_SHARE_LOG.route,
Expand Down
5 changes: 4 additions & 1 deletion src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,13 @@ type SettingsNavigatorParamList = {
[SCREENS.SETTINGS.TROUBLESHOOT]: undefined;
[SCREENS.SETTINGS.APP_DOWNLOAD_LINKS]: undefined;
[SCREENS.SETTINGS.TROUBLESHOOT]: undefined;
[SCREENS.SETTINGS.CONSOLE]: undefined;
[SCREENS.SETTINGS.CONSOLE]: {
backTo: Routes;
};
[SCREENS.SETTINGS.SHARE_LOG]: {
/** URL of the generated file to share logs in a report */
source: string;
backTo: Routes;
};
[SCREENS.SETTINGS.WALLET.ROOT]: undefined;
[SCREENS.SETTINGS.WALLET.CARDS_DIGITAL_DETAILS_UPDATE_ADDRESS]: undefined;
Expand Down
8 changes: 7 additions & 1 deletion src/pages/settings/AboutPage/ConsolePage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type {RouteProp} from '@react-navigation/native';
import {useRoute} from '@react-navigation/native';
import {format} from 'date-fns';
import React, {useCallback, useEffect, useMemo, useState} from 'react';
import {View} from 'react-native';
Expand All @@ -21,9 +23,11 @@ import type {Log} from '@libs/Console';
import localFileCreate from '@libs/localFileCreate';
import localFileDownload from '@libs/localFileDownload';
import Navigation from '@libs/Navigation/Navigation';
import type {SettingsNavigatorParamList} from '@navigation/types';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {CapturedLogs} from '@src/types/onyx';

type ConsolePageOnyxProps = {
Expand All @@ -44,6 +48,8 @@ function ConsolePage({capturedLogs, shouldStoreLogs}: ConsolePageProps) {
const {translate} = useLocalize();
const styles = useThemeStyles();

const route = useRoute<RouteProp<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.CONSOLE>>();

const logsList = useMemo(
() =>
Object.entries(logs ?? {})
Expand Down Expand Up @@ -114,7 +120,7 @@ function ConsolePage({capturedLogs, shouldStoreLogs}: ConsolePageProps) {
<ScreenWrapper testID={ConsolePage.displayName}>
<HeaderWithBackButton
title={translate('initialSettingsPage.troubleshoot.debugConsole')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_TROUBLESHOOT)}
onBackButtonPress={() => Navigation.goBack(route.params?.backTo)}
/>
<View style={[styles.border, styles.highlightBG, styles.borderNone, styles.mh5, styles.flex1]}>
<InvertedFlatList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function BaseShareLogList({onAttachLogToReport}: BaseShareLogListProps) {
<>
<HeaderWithBackButton
title={translate('initialSettingsPage.debugConsole.shareLog')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_CONSOLE)}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_CONSOLE.getRoute())}
/>
<SelectionList
ListItem={UserListItem}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/settings/Troubleshoot/TroubleshootPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function TroubleshootPage({shouldStoreLogs}: TroubleshootPageProps) {
const debugConsoleItem: BaseMenuItem = {
translationKey: 'initialSettingsPage.troubleshoot.viewConsole',
icon: Expensicons.Gear,
action: waitForNavigate(() => Navigation.navigate(ROUTES.SETTINGS_CONSOLE)),
action: waitForNavigate(() => Navigation.navigate(ROUTES.SETTINGS_CONSOLE.getRoute(ROUTES.SETTINGS_TROUBLESHOOT))),
};

const baseMenuItems: BaseMenuItem[] = [
Expand Down

0 comments on commit ef6e012

Please sign in to comment.