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 2 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
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}/${file.newFileName}`}</Text>
Copy link
Contributor

@ishpaul777 ishpaul777 Apr 25, 2024

Choose a reason for hiding this comment

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

I think we dont need file and displaypath both here, pass the display path (${displayPath}/${file.newFileName}`) only and build it in parent component

<TestToolRow title={translate('initialSettingsPage.debugConsole.logs')}>
<Button
small
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ function ClientSideLoggingToolMenu() {
onEnableLogging={() => setFile(undefined)}
onDisableLogging={createAndSaveFile}
onShareLogs={shareLogs}
displayPath="/Downloads"
Copy link
Contributor

Choose a reason for hiding this comment

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

use constant for /Downloads

/>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/ClientSideLoggingToolMenu/index.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function ClientSideLoggingToolMenu() {
onEnableLogging={() => setFile(undefined)}
onDisableLogging={createFile}
onShareLogs={shareLogs}
displayPath="/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.

use constant

/>
);
}
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,7 @@ function formatBytes(bytes: number, decimals = 2) {
return `${parseFloat((bytes / k ** i).toFixed(dm))} ${sizes[i]}`;
}

function ProfilingToolMenu({isProfilingInProgress = false}: ProfilingToolMenuProps) {
function BaseProfilingToolMenu({isProfilingInProgress = false, pathToBeUsed, displayPath}: BaseProfilingToolMenuProps) {
const styles = useThemeStyles();
const [pathIOS, setPathIOS] = useState('');
const [sharePath, setSharePath] = useState('');
Expand Down Expand Up @@ -83,15 +88,16 @@ function ProfilingToolMenu({isProfilingInProgress = false}: ProfilingToolMenuPro
[totalMemory, usedMemory],
);

const newFileName = `Profile_trace_for_${pkg.version}.cpuprofile`;
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this can be moved outside the component


useEffect(() => {
if (!pathIOS) {
return;
}

// 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, newFileName, 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);
16 changes: 16 additions & 0 deletions src/components/ProfilingToolMenu/index.android.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import RNFS from 'react-native-fs';
import BaseProfilingToolMenu from './BaseProfilingToolMenu';

function ProfilingToolMenu() {
return (
<BaseProfilingToolMenu
pathToBeUsed={RNFS.DownloadDirectoryPath}
displayPath="/Downloads"
/>
);
}

ProfilingToolMenu.displayName = 'ProfilingToolMenu';

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

function ProfilingToolMenu() {
return (
<BaseProfilingToolMenu
pathToBeUsed={RNFS.DocumentDirectoryPath}
displayPath="/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.

use costant whereever we use /Downloads and /New Expensify

/>
);
}

ProfilingToolMenu.displayName = 'ProfilingToolMenu';

export default ProfilingToolMenu;
Loading