Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save logs data in downloads and show meaningful path #40777

Merged
merged 19 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/CONST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4695,6 +4695,14 @@ const CONST = {
MAX_TAX_RATE_INTEGER_PLACES: 4,
MAX_TAX_RATE_DECIMAL_PLACES: 4,

DOWNLOADS_PATH: '/Downloads',
NEW_EXPENSIFY_PATH: '/New Expensify',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this path will be different for all type build dev/staging/prod we have useEnvironment to know which environment we are in

IMG_0FAE46FA1CC0-1


ENVIRONMENT_SUFFIX: {
DEV: ' Dev',
ADHOC: ' AdHoc',
},

SEARCH_TRANSACTION_TYPE: {
CASH: 'cash',
CARD: 'card',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ type BaseClientSideLoggingToolProps = {
onDisableLogging: (logs: Log[]) => void;
/** Action to run when enabling logging */
onEnableLogging?: () => void;
/** Path used to display location of saved file */
displayPath?: string;
} & BaseClientSideLoggingToolMenuOnyxProps;

function BaseClientSideLoggingToolMenu({shouldStoreLogs, capturedLogs, file, onShareLogs, onDisableLogging, onEnableLogging}: BaseClientSideLoggingToolProps) {
function BaseClientSideLoggingToolMenu({shouldStoreLogs, capturedLogs, file, onShareLogs, onDisableLogging, onEnableLogging, displayPath}: BaseClientSideLoggingToolProps) {
const {translate} = useLocalize();

const onToggle = () => {
Expand Down Expand Up @@ -70,7 +72,7 @@ function BaseClientSideLoggingToolMenu({shouldStoreLogs, capturedLogs, file, onS
</TestToolRow>
{!!file && (
<>
<Text style={[styles.textLabelSupporting, styles.mb4]}>{`path: ${file.path}`}</Text>
<Text style={[styles.textLabelSupporting, styles.mb4]}>{`path: ${displayPath}`}</Text>
<TestToolRow title={translate('initialSettingsPage.debugConsole.logs')}>
<Button
small
Expand Down
2 changes: 2 additions & 0 deletions src/components/ClientSideLoggingToolMenu/index.android.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import RNFetchBlob from 'react-native-blob-util';
import Share from 'react-native-share';
import type {Log} from '@libs/Console';
import localFileCreate from '@libs/localFileCreate';
import CONST from '@src/CONST';
import BaseClientSideLoggingToolMenu from './BaseClientSideLoggingToolMenu';

function ClientSideLoggingToolMenu() {
Expand Down Expand Up @@ -38,6 +39,7 @@ function ClientSideLoggingToolMenu() {
onEnableLogging={() => setFile(undefined)}
onDisableLogging={createAndSaveFile}
onShareLogs={shareLogs}
displayPath={`${CONST.DOWNLOADS_PATH}/${file?.newFileName ?? ''}`}
/>
);
}
Expand Down
5 changes: 5 additions & 0 deletions src/components/ClientSideLoggingToolMenu/index.ios.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import React, {useState} from 'react';
import Share from 'react-native-share';
import useEnvironment from '@hooks/useEnvironment';
import type {Log} from '@libs/Console';
import getDownloadFolderPathSuffixForIOS from '@libs/getDownloadFolderPathSuffixForIOS';
import localFileCreate from '@libs/localFileCreate';
import CONST from '@src/CONST';
import BaseClientSideLoggingToolMenu from './BaseClientSideLoggingToolMenu';

function ClientSideLoggingToolMenu() {
const [file, setFile] = useState<{path: string; newFileName: string; size: number}>();
const {environment} = useEnvironment();

const createFile = (logs: Log[]) => {
localFileCreate('logs', JSON.stringify(logs, null, 2)).then((localFile) => {
Expand All @@ -28,6 +32,7 @@ function ClientSideLoggingToolMenu() {
onEnableLogging={() => setFile(undefined)}
onDisableLogging={createFile}
onShareLogs={shareLogs}
displayPath={`${CONST.NEW_EXPENSIFY_PATH}${getDownloadFolderPathSuffixForIOS(environment)}/${file?.newFileName ?? ''}`}
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import pkg from '../../../package.json';

type ProfilingToolMenuOnyxProps = {
type BaseProfilingToolMenuOnyxProps = {
isProfilingInProgress: OnyxEntry<boolean>;
};

type ProfilingToolMenuProps = ProfilingToolMenuOnyxProps;
type BaseProfilingToolMenuProps = {
/** Path used to save the file */
pathToBeUsed: string;
/** Path used to display location of saved file */
displayPath: string;
} & BaseProfilingToolMenuOnyxProps;

function formatBytes(bytes: number, decimals = 2) {
if (!+bytes) {
Expand All @@ -39,7 +44,9 @@ function formatBytes(bytes: number, decimals = 2) {
return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
}

function ProfilingToolMenu({isProfilingInProgress = false}: ProfilingToolMenuProps) {
const newFileName = `Profile_trace_for_${pkg.version}.cpuprofile`;

function BaseProfilingToolMenu({isProfilingInProgress = false, pathToBeUsed, displayPath}: BaseProfilingToolMenuProps) {
const styles = useThemeStyles();
const [pathIOS, setPathIOS] = useState('');
const [sharePath, setSharePath] = useState('');
Expand Down Expand Up @@ -90,8 +97,7 @@ function ProfilingToolMenu({isProfilingInProgress = false}: ProfilingToolMenuPro

// eslint-disable-next-line @lwc/lwc/no-async-await
const rename = async () => {
const newFileName = `Profile_trace_for_${pkg.version}.cpuprofile`;
const newFilePath = `${RNFS.DocumentDirectoryPath}/${newFileName}`;
const newFilePath = `${pathToBeUsed}/${newFileName}`;

try {
const fileExists = await RNFS.exists(newFilePath);
Expand All @@ -117,7 +123,7 @@ function ProfilingToolMenu({isProfilingInProgress = false}: ProfilingToolMenuPro
};

rename();
}, [pathIOS]);
}, [pathIOS, pathToBeUsed]);

const onDownloadProfiling = useCallback(() => {
// eslint-disable-next-line @lwc/lwc/no-async-await
Expand Down Expand Up @@ -153,7 +159,7 @@ function ProfilingToolMenu({isProfilingInProgress = false}: ProfilingToolMenuPro
</TestToolRow>
{!!pathIOS && (
<>
<Text style={[styles.textLabelSupporting, styles.mb4]}>{`path: ${pathIOS}`}</Text>
<Text style={[styles.textLabelSupporting, styles.mb4]}>{`path: ${displayPath}/${newFileName}`}</Text>
<TestToolRow title={translate('initialSettingsPage.troubleshoot.profileTrace')}>
<Button
small
Expand All @@ -167,10 +173,10 @@ function ProfilingToolMenu({isProfilingInProgress = false}: ProfilingToolMenuPro
);
}

ProfilingToolMenu.displayName = 'ProfilingToolMenu';
BaseProfilingToolMenu.displayName = 'BaseProfilingToolMenu';

export default withOnyx<ProfilingToolMenuProps, ProfilingToolMenuOnyxProps>({
export default withOnyx<BaseProfilingToolMenuProps, BaseProfilingToolMenuOnyxProps>({
isProfilingInProgress: {
key: ONYXKEYS.APP_PROFILING_IN_PROGRESS,
},
})(ProfilingToolMenu);
})(BaseProfilingToolMenu);
17 changes: 17 additions & 0 deletions src/components/ProfilingToolMenu/index.android.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import RNFS from 'react-native-fs';
import CONST from '@src/CONST';
import BaseProfilingToolMenu from './BaseProfilingToolMenu';

function ProfilingToolMenu() {
return (
<BaseProfilingToolMenu
pathToBeUsed={RNFS.DownloadDirectoryPath}
displayPath={`${CONST.DOWNLOADS_PATH}`}
/>
);
}

ProfilingToolMenu.displayName = 'ProfilingToolMenu';

export default ProfilingToolMenu;
21 changes: 21 additions & 0 deletions src/components/ProfilingToolMenu/index.ios.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import RNFS from 'react-native-fs';
import useEnvironment from '@hooks/useEnvironment';
import getDownloadFolderPathSuffixForIOS from '@libs/getDownloadFolderPathSuffixForIOS';
import CONST from '@src/CONST';
import BaseProfilingToolMenu from './BaseProfilingToolMenu';

function ProfilingToolMenu() {
const {environment} = useEnvironment();

return (
<BaseProfilingToolMenu
pathToBeUsed={RNFS.DocumentDirectoryPath}
displayPath={`${CONST.NEW_EXPENSIFY_PATH}${getDownloadFolderPathSuffixForIOS(environment)}`}
/>
);
}

ProfilingToolMenu.displayName = 'ProfilingToolMenu';

export default ProfilingToolMenu;
24 changes: 24 additions & 0 deletions src/libs/getDownloadFolderPathSuffixForIOS.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import CONST from '@src/CONST';

function getDownloadFolderPathSuffixForIOS(environment: string) {
let folderSuffix = '';

switch (environment) {
case CONST.ENVIRONMENT.PRODUCTION:
folderSuffix = '';
break;
case CONST.ENVIRONMENT.ADHOC:
folderSuffix = CONST.ENVIRONMENT_SUFFIX.ADHOC;
break;
case CONST.ENVIRONMENT.DEV:
folderSuffix = CONST.ENVIRONMENT_SUFFIX.DEV;
break;
default:
folderSuffix = '';
break;
}

return folderSuffix;
}

export default getDownloadFolderPathSuffixForIOS;
Loading