Skip to content
Open
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
43 changes: 43 additions & 0 deletions packages/react-native/Libraries/LogBox/UI/LogBoxInspector.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @format
*/

import Clipboard from '../../Components/Clipboard/Clipboard';
import Keyboard from '../../Components/Keyboard/Keyboard';
import View from '../../Components/View/View';
import StyleSheet from '../../StyleSheet/StyleSheet';
Expand Down Expand Up @@ -59,6 +60,47 @@ export default function LogBoxInspector(props: Props): React.Node {
LogBoxData.retrySymbolicateLogNow(log);
}

function _handleCopy() {
const headerTitleMap = {
warn: 'Console Warning',
error: 'Console Error',
fatal: 'Uncaught Error',
syntax: 'Syntax Error',
component: 'Render Error',
};

const title =
log.type ??
headerTitleMap[log.isComponentError ? 'component' : log.level];

const parts = [title, '', log.message.content];

if (log.codeFrame != null) {
const location = log.codeFrame.location;
parts.push(
'',
'Source:',
location != null
? `${log.codeFrame.fileName} (${location.row}:${location.column})`
: log.codeFrame.fileName,
);
}

const stack = log.getAvailableStack();
if (stack.length > 0) {
parts.push('', 'Call Stack:');
for (const frame of stack) {
const methodName = frame.methodName ?? '?';
const file = frame.file ?? '?';
const lineNumber =
frame.lineNumber != null ? `:${frame.lineNumber}` : '';
parts.push(`${methodName} (${file}${lineNumber})`);
}
}

Clipboard.setString(parts.join('\n'));
}

if (log == null) {
return null;
}
Expand All @@ -75,6 +117,7 @@ export default function LogBoxInspector(props: Props): React.Node {
<LogBoxInspectorFooter
onDismiss={props.onDismiss}
onMinimize={props.onMinimize}
onCopy={_handleCopy}
level={log.level}
/>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as React from 'react';
type Props = Readonly<{
onDismiss: () => void,
onMinimize: () => void,
onCopy: () => void,
level?: ?LogLevel,
}>;

Expand Down Expand Up @@ -48,6 +49,11 @@ export default function LogBoxInspectorFooter(props: Props): React.Node {
text="Minimize"
onPress={props.onMinimize}
/>
<LogBoxInspectorFooterButton
id="logbox_footer_button_copy"
text="Copy"
onPress={props.onCopy}
/>
</View>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ describe('LogBoxInspectorFooter', () => {
<LogBoxInspectorFooter
onMinimize={() => {}}
onDismiss={() => {}}
onCopy={() => {}}
level="warn"
/>,
);
Expand All @@ -39,6 +40,7 @@ describe('LogBoxInspectorFooter', () => {
<LogBoxInspectorFooter
onMinimize={() => {}}
onDismiss={() => {}}
onCopy={() => {}}
level="error"
/>,
);
Expand All @@ -51,6 +53,7 @@ describe('LogBoxInspectorFooter', () => {
<LogBoxInspectorFooter
onMinimize={() => {}}
onDismiss={() => {}}
onCopy={() => {}}
level="fatal"
/>,
);
Expand All @@ -63,6 +66,7 @@ describe('LogBoxInspectorFooter', () => {
<LogBoxInspectorFooter
onMinimize={() => {}}
onDismiss={() => {}}
onCopy={() => {}}
level="syntax"
/>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ exports[`LogBoxContainer should render fatal with selectedIndex 2 1`] = `
/>
<LogBoxInspectorFooter
level="fatal"
onCopy={[Function]}
onDismiss={[Function]}
onMinimize={[Function]}
/>
Expand Down Expand Up @@ -106,6 +107,7 @@ exports[`LogBoxContainer should render warning with selectedIndex 0 1`] = `
/>
<LogBoxInspectorFooter
level="warn"
onCopy={[Function]}
onDismiss={[Function]}
onMinimize={[Function]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ exports[`LogBoxInspectorFooter should render two buttons for error 1`] = `
onPress={[Function]}
text="Minimize"
/>
<LogBoxInspectorFooterButton
id="logbox_footer_button_copy"
onPress={[Function]}
text="Copy"
/>
</View>
`;

Expand Down Expand Up @@ -100,6 +105,11 @@ exports[`LogBoxInspectorFooter should render two buttons for fatal 1`] = `
onPress={[Function]}
text="Minimize"
/>
<LogBoxInspectorFooterButton
id="logbox_footer_button_copy"
onPress={[Function]}
text="Copy"
/>
</View>
`;

Expand Down Expand Up @@ -129,5 +139,10 @@ exports[`LogBoxInspectorFooter should render two buttons for warning 1`] = `
onPress={[Function]}
text="Minimize"
/>
<LogBoxInspectorFooterButton
id="logbox_footer_button_copy"
onPress={[Function]}
text="Copy"
/>
</View>
`;