Skip to content

Commit 5a943ec

Browse files
rickhanloniifacebook-github-bot
authored andcommitted
LogBox - Fix for buttons forcing refresh on fatals
Summary: Fixes an issue in LogBox that allowed users to try to dismiss warnings/errors when there was a fatal or syntax error up. Changelog: [Internal] Reviewed By: motiz88 Differential Revision: D18285678 fbshipit-source-id: 9d137fab63405c28b2bfa94a35c11c2f63b6d085
1 parent 38678f7 commit 5a943ec

File tree

8 files changed

+101
-22
lines changed

8 files changed

+101
-22
lines changed

Libraries/LogBox/UI/LogBoxContainer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function LogBoxContainer(props: Props): React.Node {
7676
onMinimize={handleInspectorMinimize}
7777
onChangeSelectedIndex={setSelectedLog}
7878
logs={logs}
79-
hasFatal={true}
79+
fatalType={logs[fatalIndex].level}
8080
selectedIndex={fatalIndex}
8181
/>
8282
</View>
@@ -91,7 +91,7 @@ function LogBoxContainer(props: Props): React.Node {
9191
onMinimize={handleInspectorMinimize}
9292
onChangeSelectedIndex={setSelectedLog}
9393
logs={logs}
94-
hasFatal={fatalIndex != null}
94+
fatalType={fatalIndex != null ? logs[fatalIndex].level : null}
9595
selectedIndex={selectedLogIndex}
9696
/>
9797
</View>

Libraries/LogBox/UI/LogBoxInspector.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ import LogBoxInspectorMeta from './LogBoxInspectorMeta';
2525
import LogBoxInspectorHeader from './LogBoxInspectorHeader';
2626
import * as LogBoxStyle from './LogBoxStyle';
2727

28-
import type LogBoxLog from '../Data/LogBoxLog';
28+
import type LogBoxLog, {LogLevel} from '../Data/LogBoxLog';
2929

3030
type Props = $ReadOnly<{|
3131
onDismiss: () => void,
3232
onChangeSelectedIndex: (index: number) => void,
3333
onMinimize: () => void,
3434
logs: $ReadOnlyArray<LogBoxLog>,
3535
selectedIndex: number,
36-
hasFatal: boolean,
36+
fatalType?: ?LogLevel,
3737
|}>;
3838

3939
function LogBoxInspector(props: Props): React.Node {
@@ -79,7 +79,7 @@ function LogBoxInspector(props: Props): React.Node {
7979
<LogBoxInspectorFooter
8080
onDismiss={props.onDismiss}
8181
onMinimize={props.onMinimize}
82-
level={log.level}
82+
fatalType={props.fatalType}
8383
/>
8484
</View>
8585
);

Libraries/LogBox/UI/LogBoxInspectorFooter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ import * as LogBoxStyle from './LogBoxStyle';
2323
type Props = $ReadOnly<{|
2424
onDismiss: () => void,
2525
onMinimize: () => void,
26-
level: LogLevel,
26+
fatalType?: ?LogLevel,
2727
|}>;
2828

2929
function LogBoxInspectorFooter(props: Props): React.Node {
30-
if (props.level === 'fatal' || props.level === 'syntax') {
30+
if (props.fatalType === 'fatal' || props.fatalType === 'syntax') {
3131
return (
3232
<View style={styles.root}>
3333
<LogBoxButton
@@ -42,8 +42,8 @@ function LogBoxInspectorFooter(props: Props): React.Node {
4242
<View style={[fatalStyles.content]}>
4343
<Text style={fatalStyles.label}>Reload</Text>
4444
<Text style={fatalStyles.subtextLabel}>
45-
{{fatal: 'Fatal', syntax: 'Syntax'}[props.level]} errors require a
46-
full reload
45+
{{fatal: 'Fatal', syntax: 'Syntax'}[props.fatalType]} errors
46+
require a full reload
4747
</Text>
4848
</View>
4949
<SafeAreaView />

Libraries/LogBox/UI/__tests__/LogBoxInspector-test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ describe('LogBoxContainer', () => {
5858
onChangeSelectedIndex={() => {}}
5959
logs={[]}
6060
selectedIndex={0}
61-
hasFatal={false}
6261
/>,
6362
);
6463

@@ -73,7 +72,6 @@ describe('LogBoxContainer', () => {
7372
onChangeSelectedIndex={() => {}}
7473
logs={logs}
7574
selectedIndex={0}
76-
hasFatal={false}
7775
/>,
7876
);
7977

@@ -88,7 +86,7 @@ describe('LogBoxContainer', () => {
8886
onChangeSelectedIndex={() => {}}
8987
logs={logs}
9088
selectedIndex={2}
91-
hasFatal={true}
89+
fatalType="fatal"
9290
/>,
9391
);
9492

Libraries/LogBox/UI/__tests__/LogBoxInspectorFooter-test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,20 @@ const LogBoxInspectorFooter = require('../LogBoxInspectorFooter').default;
1616
const render = require('../../../../jest/renderer');
1717

1818
describe('LogBoxInspectorFooter', () => {
19-
it('should render two buttons', () => {
19+
it('should render two buttons for warning with no fatal', () => {
20+
const output = render.shallowRender(
21+
<LogBoxInspectorFooter onMinimize={() => {}} onDismiss={() => {}} />,
22+
);
23+
24+
expect(output).toMatchSnapshot();
25+
});
26+
27+
it('should render fatal for warning with a fatal', () => {
2028
const output = render.shallowRender(
2129
<LogBoxInspectorFooter
2230
onMinimize={() => {}}
2331
onDismiss={() => {}}
24-
level="warn"
32+
fatalType="syntax"
2533
/>,
2634
);
2735

@@ -33,7 +41,7 @@ describe('LogBoxInspectorFooter', () => {
3341
<LogBoxInspectorFooter
3442
onMinimize={() => {}}
3543
onDismiss={() => {}}
36-
level="fatal"
44+
fatalType="fatal"
3745
/>,
3846
);
3947

@@ -45,7 +53,7 @@ describe('LogBoxInspectorFooter', () => {
4553
<LogBoxInspectorFooter
4654
onMinimize={() => {}}
4755
onDismiss={() => {}}
48-
level="syntax"
56+
fatalType="syntax"
4957
/>,
5058
);
5159

Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxContainer-test.js.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ exports[`LogBoxContainer should render fatal before warn and error 1`] = `
106106
}
107107
>
108108
<LogBoxInspector
109-
hasFatal={true}
109+
fatalType="fatal"
110110
logs={
111111
Array [
112112
LogBoxLog {
@@ -183,7 +183,7 @@ exports[`LogBoxContainer should render most recent fatal 1`] = `
183183
}
184184
>
185185
<LogBoxInspector
186-
hasFatal={true}
186+
fatalType="fatal"
187187
logs={
188188
Array [
189189
LogBoxLog {
@@ -243,7 +243,7 @@ exports[`LogBoxContainer should render most recent syntax error 1`] = `
243243
}
244244
>
245245
<LogBoxInspector
246-
hasFatal={true}
246+
fatalType="syntax"
247247
logs={
248248
Array [
249249
LogBoxLog {

Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspector-test.js.snap

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ exports[`LogBoxContainer should render fatal with selectedIndex 2 1`] = `
3939
onRetry={[Function]}
4040
/>
4141
<LogBoxInspectorFooter
42-
level="fatal"
42+
fatalType="fatal"
4343
onDismiss={[Function]}
4444
onMinimize={[Function]}
4545
/>
@@ -87,7 +87,6 @@ exports[`LogBoxContainer should render warning with selectedIndex 0 1`] = `
8787
onRetry={[Function]}
8888
/>
8989
<LogBoxInspectorFooter
90-
level="warn"
9190
onDismiss={[Function]}
9291
onMinimize={[Function]}
9392
/>

Libraries/LogBox/UI/__tests__/__snapshots__/LogBoxInspectorFooter-test.js.snap

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,81 @@ exports[`LogBoxInspectorFooter should render fatal button for syntax erorr 1`] =
148148
</View>
149149
`;
150150

151-
exports[`LogBoxInspectorFooter should render two buttons 1`] = `
151+
exports[`LogBoxInspectorFooter should render fatal for warning with a fatal 1`] = `
152+
<View
153+
style={
154+
Object {
155+
"backgroundColor": "rgba(51, 51, 51, 1)",
156+
"elevation": 1,
157+
"flexDirection": "row",
158+
"shadowColor": "#000",
159+
"shadowOffset": Object {
160+
"height": -2,
161+
"width": 0,
162+
},
163+
"shadowOpacity": 0.5,
164+
"shadowRadius": 2,
165+
}
166+
}
167+
>
168+
<LogBoxButton
169+
backgroundColor={
170+
Object {
171+
"default": "rgba(243, 83, 105, 1)",
172+
"pressed": "rgba(208, 75, 95, 1)",
173+
}
174+
}
175+
onPress={[Function]}
176+
style={
177+
Object {
178+
"flex": 1,
179+
}
180+
}
181+
>
182+
<View
183+
style={
184+
Array [
185+
Object {
186+
"alignItems": "center",
187+
"height": 60,
188+
"justifyContent": "center",
189+
},
190+
]
191+
}
192+
>
193+
<Text
194+
style={
195+
Object {
196+
"color": "rgba(255, 255, 255, 1)",
197+
"fontSize": 14,
198+
"fontWeight": "600",
199+
"includeFontPadding": false,
200+
"lineHeight": 20,
201+
}
202+
}
203+
>
204+
Reload
205+
</Text>
206+
<Text
207+
style={
208+
Object {
209+
"color": "rgba(255, 255, 255, 0.8)",
210+
"fontSize": 11,
211+
"includeFontPadding": false,
212+
"lineHeight": 12,
213+
}
214+
}
215+
>
216+
Syntax
217+
errors require a full reload
218+
</Text>
219+
</View>
220+
<ForwardRef(SafeAreaView) />
221+
</LogBoxButton>
222+
</View>
223+
`;
224+
225+
exports[`LogBoxInspectorFooter should render two buttons for warning with no fatal 1`] = `
152226
<View
153227
style={
154228
Object {

0 commit comments

Comments
 (0)