-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into @chrispader/prevent-simultaneous-calls-to-Ge…
…tMissingOnyxMessages
- Loading branch information
Showing
52 changed files
with
937 additions
and
301 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,6 @@ | ||
# Every PR gets a review from an internal Expensify engineer | ||
* @Expensify/pullerbear | ||
|
||
# Assign the Design team to review changes to our styles & assets | ||
src/styles/ @Expensify/design @Expensify/pullerbear | ||
assets/ @Expensify/design @Expensify/pullerbear |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/components/ClientSideLoggingToolMenu/BaseClientSideLoggingToolMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React from 'react'; | ||
import {Alert} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import Button from '@components/Button'; | ||
import Switch from '@components/Switch'; | ||
import TestToolRow from '@components/TestToolRow'; | ||
import Text from '@components/Text'; | ||
import useLocalize from '@hooks/useLocalize'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import * as Console from '@libs/actions/Console'; | ||
import {parseStringifiedMessages} from '@libs/Console'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {CapturedLogs, Log} from '@src/types/onyx'; | ||
|
||
type BaseClientSideLoggingToolMenuOnyxProps = { | ||
/** Logs captured on the current device */ | ||
capturedLogs: OnyxEntry<CapturedLogs>; | ||
|
||
/** Whether or not logs should be stored */ | ||
shouldStoreLogs: OnyxEntry<boolean>; | ||
}; | ||
|
||
type BaseClientSideLoggingToolProps = { | ||
/** Locally created file */ | ||
file?: {path: string; newFileName: string; size: number}; | ||
/** Action to run when pressing Share button */ | ||
onShareLogs?: () => void; | ||
/** Action to run when disabling the switch */ | ||
onDisableLogging: (logs: Log[]) => void; | ||
/** Action to run when enabling logging */ | ||
onEnableLogging?: () => void; | ||
} & BaseClientSideLoggingToolMenuOnyxProps; | ||
|
||
function BaseClientSideLoggingToolMenu({shouldStoreLogs, capturedLogs, file, onShareLogs, onDisableLogging, onEnableLogging}: BaseClientSideLoggingToolProps) { | ||
const {translate} = useLocalize(); | ||
|
||
const onToggle = () => { | ||
if (!shouldStoreLogs) { | ||
Console.setShouldStoreLogs(true); | ||
|
||
if (onEnableLogging) { | ||
onEnableLogging(); | ||
} | ||
|
||
return; | ||
} | ||
|
||
if (!capturedLogs) { | ||
Alert.alert(translate('initialSettingsPage.troubleshoot.noLogsToShare')); | ||
Console.disableLoggingAndFlushLogs(); | ||
return; | ||
} | ||
|
||
const logs = Object.values(capturedLogs); | ||
const logsWithParsedMessages = parseStringifiedMessages(logs); | ||
|
||
onDisableLogging(logsWithParsedMessages); | ||
Console.disableLoggingAndFlushLogs(); | ||
}; | ||
const styles = useThemeStyles(); | ||
return ( | ||
<> | ||
<TestToolRow title={translate('initialSettingsPage.troubleshoot.clientSideLogging')}> | ||
<Switch | ||
accessibilityLabel={translate('initialSettingsPage.troubleshoot.clientSideLogging')} | ||
isOn={!!shouldStoreLogs} | ||
onToggle={onToggle} | ||
/> | ||
</TestToolRow> | ||
{!!file && ( | ||
<> | ||
<Text style={[styles.textLabelSupporting, styles.mb4]}>{`path: ${file.path}`}</Text> | ||
<TestToolRow title={translate('initialSettingsPage.debugConsole.logs')}> | ||
<Button | ||
small | ||
text={translate('common.share')} | ||
onPress={onShareLogs} | ||
/> | ||
</TestToolRow> | ||
</> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
BaseClientSideLoggingToolMenu.displayName = 'BaseClientSideLoggingToolMenu'; | ||
|
||
export default withOnyx<BaseClientSideLoggingToolProps, BaseClientSideLoggingToolMenuOnyxProps>({ | ||
capturedLogs: { | ||
key: ONYXKEYS.LOGS, | ||
}, | ||
shouldStoreLogs: { | ||
key: ONYXKEYS.SHOULD_STORE_LOGS, | ||
}, | ||
})(BaseClientSideLoggingToolMenu); |
47 changes: 47 additions & 0 deletions
47
src/components/ClientSideLoggingToolMenu/index.android.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React, {useState} from 'react'; | ||
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 BaseClientSideLoggingToolMenu from './BaseClientSideLoggingToolMenu'; | ||
|
||
function ClientSideLoggingToolMenu() { | ||
const [file, setFile] = useState<{path: string; newFileName: string; size: number}>(); | ||
|
||
const createAndSaveFile = (logs: Log[]) => { | ||
localFileCreate('logs', JSON.stringify(logs, null, 2)).then((localFile) => { | ||
RNFetchBlob.MediaCollection.copyToMediaStore( | ||
{ | ||
name: localFile.newFileName, | ||
parentFolder: '', | ||
mimeType: 'text/plain', | ||
}, | ||
'Download', | ||
localFile.path, | ||
); | ||
setFile(localFile); | ||
}); | ||
}; | ||
|
||
const shareLogs = () => { | ||
if (!file) { | ||
return; | ||
} | ||
Share.open({ | ||
url: `file://${file.path}`, | ||
}); | ||
}; | ||
|
||
return ( | ||
<BaseClientSideLoggingToolMenu | ||
file={file} | ||
onEnableLogging={() => setFile(undefined)} | ||
onDisableLogging={createAndSaveFile} | ||
onShareLogs={shareLogs} | ||
/> | ||
); | ||
} | ||
|
||
ClientSideLoggingToolMenu.displayName = 'ClientSideLoggingToolMenu'; | ||
|
||
export default ClientSideLoggingToolMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import React, {useState} from 'react'; | ||
import Share from 'react-native-share'; | ||
import type {Log} from '@libs/Console'; | ||
import localFileCreate from '@libs/localFileCreate'; | ||
import BaseClientSideLoggingToolMenu from './BaseClientSideLoggingToolMenu'; | ||
|
||
function ClientSideLoggingToolMenu() { | ||
const [file, setFile] = useState<{path: string; newFileName: string; size: number}>(); | ||
|
||
const createFile = (logs: Log[]) => { | ||
localFileCreate('logs', JSON.stringify(logs, null, 2)).then((localFile) => { | ||
setFile(localFile); | ||
}); | ||
}; | ||
|
||
const shareLogs = () => { | ||
if (!file) { | ||
return; | ||
} | ||
Share.open({ | ||
url: `file://${file.path}`, | ||
}); | ||
}; | ||
|
||
return ( | ||
<BaseClientSideLoggingToolMenu | ||
file={file} | ||
onEnableLogging={() => setFile(undefined)} | ||
onDisableLogging={createFile} | ||
onShareLogs={shareLogs} | ||
/> | ||
); | ||
} | ||
|
||
ClientSideLoggingToolMenu.displayName = 'ClientSideLoggingToolMenu'; | ||
|
||
export default ClientSideLoggingToolMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import type {Log} from '@libs/Console'; | ||
import localFileDownload from '@libs/localFileDownload'; | ||
import BaseClientSideLoggingToolMenu from './BaseClientSideLoggingToolMenu'; | ||
|
||
function ClientSideLoggingToolMenu() { | ||
const downloadFile = (logs: Log[]) => { | ||
localFileDownload('logs', JSON.stringify(logs, null, 2)); | ||
}; | ||
|
||
return <BaseClientSideLoggingToolMenu onDisableLogging={downloadFile} />; | ||
} | ||
|
||
ClientSideLoggingToolMenu.displayName = 'ClientSideLoggingToolMenu'; | ||
|
||
export default ClientSideLoggingToolMenu; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.