react-native-macos/Libraries/LogBox/UI/LogBoxInspectorFooter.js

145 строки
3.4 KiB
JavaScript
Исходник Обычный вид История

Add LogBox for warnings Summary: # Overview This diff adds the initial LogBox redesign implementing only Warnings for now. The following diffs include the tests for this, as well as a way to enable an experimental flag to opt-in. Changelog: [Internal] ## Changes To init LogBox, we've taken the core of YellowBox and rewritten it entirely. Differences from Yellowbox include: - Data model re-written - More performant - Allows a future listing of logs in order - Allows a future toggle to show ignored logs - Moves category into a property - Groups by the same sequential message (as chrome does) instead of by category - Does not store dupes of the same messages, only a count - UI revamp - Color and design refresh - Does not spam UI with logs - Only shows the most recent log - Dismiss all button is always in one place - Allows navigating through all of the warnings in the list, not just ones in the same category - Collapses message to 5 lines (tap to expand) - Collapses unrelated stack frames (tap to expand) - Moves React stack to it's own section - Formats React Stack like a stack frame - Collapses any React frames over 3 deep (tap to expand) - Adds a "Meta" information (to be expanded on later) - De-emphasizes the source map indicator - Better Engineering - Rewrote almost all components to hooks (will follow up with the rest) - Added more tests for Data files - Added testes for UI components (previously there were none) - Refactored some imperative render code to declarative ## Known Problems - The first major problem is that in the collapsed state (which is meant to model the FBLogger on Comet) does not show the user how many logs are in the console (only the count of the current log). - The way we're doing symbolication and navigation is slow. We will follow up with perf improvements - The React Stack logic is too simple and missed cases - We need to get properly scaled images for the close button ## What's next Next up we'll be: - Move over Moti's improvements to filtering and YellowBox changes since I started this - Adding in Errors, and not using the native redbox when LogBox is available - Adding in a list of all errors and a way to navigate to it - Adding in Logs, so users can see console.log in the app - Make React stack frames clickable - And many more Reviewed By: cpojer Differential Revision: D17965726 fbshipit-source-id: 2f28584ecb7e3ca8d3df034ea1e1a4a50e018c02
2019-10-22 07:05:47 +03:00
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
Add LogBox for warnings Summary: # Overview This diff adds the initial LogBox redesign implementing only Warnings for now. The following diffs include the tests for this, as well as a way to enable an experimental flag to opt-in. Changelog: [Internal] ## Changes To init LogBox, we've taken the core of YellowBox and rewritten it entirely. Differences from Yellowbox include: - Data model re-written - More performant - Allows a future listing of logs in order - Allows a future toggle to show ignored logs - Moves category into a property - Groups by the same sequential message (as chrome does) instead of by category - Does not store dupes of the same messages, only a count - UI revamp - Color and design refresh - Does not spam UI with logs - Only shows the most recent log - Dismiss all button is always in one place - Allows navigating through all of the warnings in the list, not just ones in the same category - Collapses message to 5 lines (tap to expand) - Collapses unrelated stack frames (tap to expand) - Moves React stack to it's own section - Formats React Stack like a stack frame - Collapses any React frames over 3 deep (tap to expand) - Adds a "Meta" information (to be expanded on later) - De-emphasizes the source map indicator - Better Engineering - Rewrote almost all components to hooks (will follow up with the rest) - Added more tests for Data files - Added testes for UI components (previously there were none) - Refactored some imperative render code to declarative ## Known Problems - The first major problem is that in the collapsed state (which is meant to model the FBLogger on Comet) does not show the user how many logs are in the console (only the count of the current log). - The way we're doing symbolication and navigation is slow. We will follow up with perf improvements - The React Stack logic is too simple and missed cases - We need to get properly scaled images for the close button ## What's next Next up we'll be: - Move over Moti's improvements to filtering and YellowBox changes since I started this - Adding in Errors, and not using the native redbox when LogBox is available - Adding in a list of all errors and a way to navigate to it - Adding in Logs, so users can see console.log in the app - Make React stack frames clickable - And many more Reviewed By: cpojer Differential Revision: D17965726 fbshipit-source-id: 2f28584ecb7e3ca8d3df034ea1e1a4a50e018c02
2019-10-22 07:05:47 +03:00
* @format
*/
'use strict';
LogBox - Add syntax error handling Summary: This diff adds handling for syntax errors. ## Strategy To do this we introduce a new log level type syntax, giving us these levels with semantics: - `warn` - console warns, show collapsed, dismissible - `error` - console errors, show collapsed, dismissible - `fatal` - thrown exceptions, show expanded, not dismissible - `syntax` - thrown exceptions for invalid syntax, show expanded, not dismissible Syntax errors shows expanded, covers all other errors, and are only dismissible when the syntax error is fixed and updated with Fast Refresh. Once the syntax error is fixed, it reveals any previously covered fatals, errors, or warnings behind it In many ways, this makes syntax errors the highest level error. ## Visuals Syntax errors also have their own display formatting. Stack traces for syntax errors don't make sense, so we don't show them. Instead, we show the syntax error message and a code frame for the error. The code frame is also updated so that is doesn't wrap and is horizontally scrollable, making it easier to read. ## Detecting syntax errors To detect syntax errors we've updated `LogBoxData.addException` to call the parse function `parseLogBoxException`. This method will perform a regex on the error message to detect: - file name - location - error message - codeframe If this regex fails for any reason to find all four parts, we'll fall back to a fatal. Over time we'll update this regex to be more robust and handle more cases we've missed. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D18278862 fbshipit-source-id: 59069aba38a27c44787e5248b2973c3a345c4a0a
2019-11-02 02:05:02 +03:00
import type {LogLevel} from '../Data/LogBoxLog';
Add LogBox for warnings Summary: # Overview This diff adds the initial LogBox redesign implementing only Warnings for now. The following diffs include the tests for this, as well as a way to enable an experimental flag to opt-in. Changelog: [Internal] ## Changes To init LogBox, we've taken the core of YellowBox and rewritten it entirely. Differences from Yellowbox include: - Data model re-written - More performant - Allows a future listing of logs in order - Allows a future toggle to show ignored logs - Moves category into a property - Groups by the same sequential message (as chrome does) instead of by category - Does not store dupes of the same messages, only a count - UI revamp - Color and design refresh - Does not spam UI with logs - Only shows the most recent log - Dismiss all button is always in one place - Allows navigating through all of the warnings in the list, not just ones in the same category - Collapses message to 5 lines (tap to expand) - Collapses unrelated stack frames (tap to expand) - Moves React stack to it's own section - Formats React Stack like a stack frame - Collapses any React frames over 3 deep (tap to expand) - Adds a "Meta" information (to be expanded on later) - De-emphasizes the source map indicator - Better Engineering - Rewrote almost all components to hooks (will follow up with the rest) - Added more tests for Data files - Added testes for UI components (previously there were none) - Refactored some imperative render code to declarative ## Known Problems - The first major problem is that in the collapsed state (which is meant to model the FBLogger on Comet) does not show the user how many logs are in the console (only the count of the current log). - The way we're doing symbolication and navigation is slow. We will follow up with perf improvements - The React Stack logic is too simple and missed cases - We need to get properly scaled images for the close button ## What's next Next up we'll be: - Move over Moti's improvements to filtering and YellowBox changes since I started this - Adding in Errors, and not using the native redbox when LogBox is available - Adding in a list of all errors and a way to navigate to it - Adding in Logs, so users can see console.log in the app - Make React stack frames clickable - And many more Reviewed By: cpojer Differential Revision: D17965726 fbshipit-source-id: 2f28584ecb7e3ca8d3df034ea1e1a4a50e018c02
2019-10-22 07:05:47 +03:00
import * as React from 'react';
import SafeAreaView from '../../Components/SafeAreaView/SafeAreaView';
import StyleSheet from '../../StyleSheet/StyleSheet';
import Text from '../../Text/Text';
import View from '../../Components/View/View';
import LogBoxButton from './LogBoxButton';
import * as LogBoxStyle from './LogBoxStyle';
type Props = $ReadOnly<{|
onDismiss: () => void,
onMinimize: () => void,
fatalType?: ?LogLevel,
Add LogBox for warnings Summary: # Overview This diff adds the initial LogBox redesign implementing only Warnings for now. The following diffs include the tests for this, as well as a way to enable an experimental flag to opt-in. Changelog: [Internal] ## Changes To init LogBox, we've taken the core of YellowBox and rewritten it entirely. Differences from Yellowbox include: - Data model re-written - More performant - Allows a future listing of logs in order - Allows a future toggle to show ignored logs - Moves category into a property - Groups by the same sequential message (as chrome does) instead of by category - Does not store dupes of the same messages, only a count - UI revamp - Color and design refresh - Does not spam UI with logs - Only shows the most recent log - Dismiss all button is always in one place - Allows navigating through all of the warnings in the list, not just ones in the same category - Collapses message to 5 lines (tap to expand) - Collapses unrelated stack frames (tap to expand) - Moves React stack to it's own section - Formats React Stack like a stack frame - Collapses any React frames over 3 deep (tap to expand) - Adds a "Meta" information (to be expanded on later) - De-emphasizes the source map indicator - Better Engineering - Rewrote almost all components to hooks (will follow up with the rest) - Added more tests for Data files - Added testes for UI components (previously there were none) - Refactored some imperative render code to declarative ## Known Problems - The first major problem is that in the collapsed state (which is meant to model the FBLogger on Comet) does not show the user how many logs are in the console (only the count of the current log). - The way we're doing symbolication and navigation is slow. We will follow up with perf improvements - The React Stack logic is too simple and missed cases - We need to get properly scaled images for the close button ## What's next Next up we'll be: - Move over Moti's improvements to filtering and YellowBox changes since I started this - Adding in Errors, and not using the native redbox when LogBox is available - Adding in a list of all errors and a way to navigate to it - Adding in Logs, so users can see console.log in the app - Make React stack frames clickable - And many more Reviewed By: cpojer Differential Revision: D17965726 fbshipit-source-id: 2f28584ecb7e3ca8d3df034ea1e1a4a50e018c02
2019-10-22 07:05:47 +03:00
|}>;
function LogBoxInspectorFooter(props: Props): React.Node {
if (props.fatalType === 'fatal' || props.fatalType === 'syntax') {
return (
<View style={[styles.root, fatalStyles.root]}>
LogBox - Add syntax error handling Summary: This diff adds handling for syntax errors. ## Strategy To do this we introduce a new log level type syntax, giving us these levels with semantics: - `warn` - console warns, show collapsed, dismissible - `error` - console errors, show collapsed, dismissible - `fatal` - thrown exceptions, show expanded, not dismissible - `syntax` - thrown exceptions for invalid syntax, show expanded, not dismissible Syntax errors shows expanded, covers all other errors, and are only dismissible when the syntax error is fixed and updated with Fast Refresh. Once the syntax error is fixed, it reveals any previously covered fatals, errors, or warnings behind it In many ways, this makes syntax errors the highest level error. ## Visuals Syntax errors also have their own display formatting. Stack traces for syntax errors don't make sense, so we don't show them. Instead, we show the syntax error message and a code frame for the error. The code frame is also updated so that is doesn't wrap and is horizontally scrollable, making it easier to read. ## Detecting syntax errors To detect syntax errors we've updated `LogBoxData.addException` to call the parse function `parseLogBoxException`. This method will perform a regex on the error message to detect: - file name - location - error message - codeframe If this regex fails for any reason to find all four parts, we'll fall back to a fatal. Over time we'll update this regex to be more robust and handle more cases we've missed. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D18278862 fbshipit-source-id: 59069aba38a27c44787e5248b2973c3a345c4a0a
2019-11-02 02:05:02 +03:00
<LogBoxButton
backgroundColor={{
default: LogBoxStyle.getFatalColor(),
pressed: LogBoxStyle.getFatalDarkColor(),
}}
onPress={() =>
require('../../Utilities/DevSettings').reload('LogBox fatal')
}
style={fatalStyles.button}>
<View style={[fatalStyles.content]}>
<Text style={fatalStyles.label}>Reload</Text>
<Text style={fatalStyles.subtextLabel}>
{{fatal: 'Fatal', syntax: 'Syntax'}[props.fatalType]} errors
require a full reload
LogBox - Add syntax error handling Summary: This diff adds handling for syntax errors. ## Strategy To do this we introduce a new log level type syntax, giving us these levels with semantics: - `warn` - console warns, show collapsed, dismissible - `error` - console errors, show collapsed, dismissible - `fatal` - thrown exceptions, show expanded, not dismissible - `syntax` - thrown exceptions for invalid syntax, show expanded, not dismissible Syntax errors shows expanded, covers all other errors, and are only dismissible when the syntax error is fixed and updated with Fast Refresh. Once the syntax error is fixed, it reveals any previously covered fatals, errors, or warnings behind it In many ways, this makes syntax errors the highest level error. ## Visuals Syntax errors also have their own display formatting. Stack traces for syntax errors don't make sense, so we don't show them. Instead, we show the syntax error message and a code frame for the error. The code frame is also updated so that is doesn't wrap and is horizontally scrollable, making it easier to read. ## Detecting syntax errors To detect syntax errors we've updated `LogBoxData.addException` to call the parse function `parseLogBoxException`. This method will perform a regex on the error message to detect: - file name - location - error message - codeframe If this regex fails for any reason to find all four parts, we'll fall back to a fatal. Over time we'll update this regex to be more robust and handle more cases we've missed. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D18278862 fbshipit-source-id: 59069aba38a27c44787e5248b2973c3a345c4a0a
2019-11-02 02:05:02 +03:00
</Text>
</View>
<SafeAreaView />
</LogBoxButton>
</View>
);
}
Add LogBox for warnings Summary: # Overview This diff adds the initial LogBox redesign implementing only Warnings for now. The following diffs include the tests for this, as well as a way to enable an experimental flag to opt-in. Changelog: [Internal] ## Changes To init LogBox, we've taken the core of YellowBox and rewritten it entirely. Differences from Yellowbox include: - Data model re-written - More performant - Allows a future listing of logs in order - Allows a future toggle to show ignored logs - Moves category into a property - Groups by the same sequential message (as chrome does) instead of by category - Does not store dupes of the same messages, only a count - UI revamp - Color and design refresh - Does not spam UI with logs - Only shows the most recent log - Dismiss all button is always in one place - Allows navigating through all of the warnings in the list, not just ones in the same category - Collapses message to 5 lines (tap to expand) - Collapses unrelated stack frames (tap to expand) - Moves React stack to it's own section - Formats React Stack like a stack frame - Collapses any React frames over 3 deep (tap to expand) - Adds a "Meta" information (to be expanded on later) - De-emphasizes the source map indicator - Better Engineering - Rewrote almost all components to hooks (will follow up with the rest) - Added more tests for Data files - Added testes for UI components (previously there were none) - Refactored some imperative render code to declarative ## Known Problems - The first major problem is that in the collapsed state (which is meant to model the FBLogger on Comet) does not show the user how many logs are in the console (only the count of the current log). - The way we're doing symbolication and navigation is slow. We will follow up with perf improvements - The React Stack logic is too simple and missed cases - We need to get properly scaled images for the close button ## What's next Next up we'll be: - Move over Moti's improvements to filtering and YellowBox changes since I started this - Adding in Errors, and not using the native redbox when LogBox is available - Adding in a list of all errors and a way to navigate to it - Adding in Logs, so users can see console.log in the app - Make React stack frames clickable - And many more Reviewed By: cpojer Differential Revision: D17965726 fbshipit-source-id: 2f28584ecb7e3ca8d3df034ea1e1a4a50e018c02
2019-10-22 07:05:47 +03:00
return (
<View style={styles.root}>
<FooterButton text="Minimize" onPress={props.onMinimize} />
<FooterButton text="Dismiss" onPress={props.onDismiss} />
</View>
);
}
type ButtonProps = $ReadOnly<{|
onPress: () => void,
text: string,
|}>;
function FooterButton(props: ButtonProps): React.Node {
return (
<LogBoxButton
backgroundColor={{
default: 'transparent',
pressed: LogBoxStyle.getBackgroundDarkColor(),
Add LogBox for warnings Summary: # Overview This diff adds the initial LogBox redesign implementing only Warnings for now. The following diffs include the tests for this, as well as a way to enable an experimental flag to opt-in. Changelog: [Internal] ## Changes To init LogBox, we've taken the core of YellowBox and rewritten it entirely. Differences from Yellowbox include: - Data model re-written - More performant - Allows a future listing of logs in order - Allows a future toggle to show ignored logs - Moves category into a property - Groups by the same sequential message (as chrome does) instead of by category - Does not store dupes of the same messages, only a count - UI revamp - Color and design refresh - Does not spam UI with logs - Only shows the most recent log - Dismiss all button is always in one place - Allows navigating through all of the warnings in the list, not just ones in the same category - Collapses message to 5 lines (tap to expand) - Collapses unrelated stack frames (tap to expand) - Moves React stack to it's own section - Formats React Stack like a stack frame - Collapses any React frames over 3 deep (tap to expand) - Adds a "Meta" information (to be expanded on later) - De-emphasizes the source map indicator - Better Engineering - Rewrote almost all components to hooks (will follow up with the rest) - Added more tests for Data files - Added testes for UI components (previously there were none) - Refactored some imperative render code to declarative ## Known Problems - The first major problem is that in the collapsed state (which is meant to model the FBLogger on Comet) does not show the user how many logs are in the console (only the count of the current log). - The way we're doing symbolication and navigation is slow. We will follow up with perf improvements - The React Stack logic is too simple and missed cases - We need to get properly scaled images for the close button ## What's next Next up we'll be: - Move over Moti's improvements to filtering and YellowBox changes since I started this - Adding in Errors, and not using the native redbox when LogBox is available - Adding in a list of all errors and a way to navigate to it - Adding in Logs, so users can see console.log in the app - Make React stack frames clickable - And many more Reviewed By: cpojer Differential Revision: D17965726 fbshipit-source-id: 2f28584ecb7e3ca8d3df034ea1e1a4a50e018c02
2019-10-22 07:05:47 +03:00
}}
onPress={props.onPress}
style={buttonStyles.button}>
<View style={buttonStyles.content}>
<Text style={buttonStyles.label}>{props.text}</Text>
</View>
<SafeAreaView />
</LogBoxButton>
);
}
const fatalStyles = StyleSheet.create({
root: {
shadowColor: LogBoxStyle.getBackgroundDarkColor(1),
},
button: {
flex: 1,
},
content: {
alignItems: 'center',
height: 60,
justifyContent: 'center',
},
subtext: {
height: 60,
},
label: {
color: LogBoxStyle.getTextColor(1),
fontSize: 14,
fontWeight: '600',
includeFontPadding: false,
lineHeight: 20,
},
subtextLabel: {
color: LogBoxStyle.getTextColor(0.8),
fontSize: 11,
includeFontPadding: false,
lineHeight: 12,
},
});
Add LogBox for warnings Summary: # Overview This diff adds the initial LogBox redesign implementing only Warnings for now. The following diffs include the tests for this, as well as a way to enable an experimental flag to opt-in. Changelog: [Internal] ## Changes To init LogBox, we've taken the core of YellowBox and rewritten it entirely. Differences from Yellowbox include: - Data model re-written - More performant - Allows a future listing of logs in order - Allows a future toggle to show ignored logs - Moves category into a property - Groups by the same sequential message (as chrome does) instead of by category - Does not store dupes of the same messages, only a count - UI revamp - Color and design refresh - Does not spam UI with logs - Only shows the most recent log - Dismiss all button is always in one place - Allows navigating through all of the warnings in the list, not just ones in the same category - Collapses message to 5 lines (tap to expand) - Collapses unrelated stack frames (tap to expand) - Moves React stack to it's own section - Formats React Stack like a stack frame - Collapses any React frames over 3 deep (tap to expand) - Adds a "Meta" information (to be expanded on later) - De-emphasizes the source map indicator - Better Engineering - Rewrote almost all components to hooks (will follow up with the rest) - Added more tests for Data files - Added testes for UI components (previously there were none) - Refactored some imperative render code to declarative ## Known Problems - The first major problem is that in the collapsed state (which is meant to model the FBLogger on Comet) does not show the user how many logs are in the console (only the count of the current log). - The way we're doing symbolication and navigation is slow. We will follow up with perf improvements - The React Stack logic is too simple and missed cases - We need to get properly scaled images for the close button ## What's next Next up we'll be: - Move over Moti's improvements to filtering and YellowBox changes since I started this - Adding in Errors, and not using the native redbox when LogBox is available - Adding in a list of all errors and a way to navigate to it - Adding in Logs, so users can see console.log in the app - Make React stack frames clickable - And many more Reviewed By: cpojer Differential Revision: D17965726 fbshipit-source-id: 2f28584ecb7e3ca8d3df034ea1e1a4a50e018c02
2019-10-22 07:05:47 +03:00
const buttonStyles = StyleSheet.create({
button: {
flex: 1,
},
content: {
alignItems: 'center',
height: 48,
justifyContent: 'center',
},
label: {
color: LogBoxStyle.getTextColor(1),
fontSize: 14,
includeFontPadding: false,
lineHeight: 20,
Add LogBox for warnings Summary: # Overview This diff adds the initial LogBox redesign implementing only Warnings for now. The following diffs include the tests for this, as well as a way to enable an experimental flag to opt-in. Changelog: [Internal] ## Changes To init LogBox, we've taken the core of YellowBox and rewritten it entirely. Differences from Yellowbox include: - Data model re-written - More performant - Allows a future listing of logs in order - Allows a future toggle to show ignored logs - Moves category into a property - Groups by the same sequential message (as chrome does) instead of by category - Does not store dupes of the same messages, only a count - UI revamp - Color and design refresh - Does not spam UI with logs - Only shows the most recent log - Dismiss all button is always in one place - Allows navigating through all of the warnings in the list, not just ones in the same category - Collapses message to 5 lines (tap to expand) - Collapses unrelated stack frames (tap to expand) - Moves React stack to it's own section - Formats React Stack like a stack frame - Collapses any React frames over 3 deep (tap to expand) - Adds a "Meta" information (to be expanded on later) - De-emphasizes the source map indicator - Better Engineering - Rewrote almost all components to hooks (will follow up with the rest) - Added more tests for Data files - Added testes for UI components (previously there were none) - Refactored some imperative render code to declarative ## Known Problems - The first major problem is that in the collapsed state (which is meant to model the FBLogger on Comet) does not show the user how many logs are in the console (only the count of the current log). - The way we're doing symbolication and navigation is slow. We will follow up with perf improvements - The React Stack logic is too simple and missed cases - We need to get properly scaled images for the close button ## What's next Next up we'll be: - Move over Moti's improvements to filtering and YellowBox changes since I started this - Adding in Errors, and not using the native redbox when LogBox is available - Adding in a list of all errors and a way to navigate to it - Adding in Logs, so users can see console.log in the app - Make React stack frames clickable - And many more Reviewed By: cpojer Differential Revision: D17965726 fbshipit-source-id: 2f28584ecb7e3ca8d3df034ea1e1a4a50e018c02
2019-10-22 07:05:47 +03:00
},
});
const styles = StyleSheet.create({
root: {
backgroundColor: LogBoxStyle.getBackgroundColor(1),
shadowColor: '#000',
shadowOffset: {width: 0, height: -2},
shadowRadius: 2,
shadowOpacity: 0.5,
elevation: 1,
flexDirection: 'row',
},
});
export default LogBoxInspectorFooter;