Skip to content

Commit ba0abfd

Browse files
authored
Merge pull request #2884 from StoDevX/debug
List redux info in beta settings
2 parents 713488a + 190467f commit ba0abfd

File tree

7 files changed

+138
-1
lines changed

7 files changed

+138
-1
lines changed

modules/constants/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ let IS_RC: boolean
2626
export const isRc = () => IS_RC
2727

2828
// checks if the build should show debugging tools
29-
export const isDevMode = () => !IS_PRODUCTION || (IS_ALPHA || IS_BETA || IS_PRE || IS_RC)
29+
export const isDevMode = () =>
30+
!IS_PRODUCTION || (IS_ALPHA || IS_BETA || IS_PRE || IS_RC)
3031

3132
export const setVersionInfo = (versionStr: string) => {
3233
let [version, buildNum] = versionStr.split('+')

source/navigation/routes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
SettingsView,
3636
IconSettingsView,
3737
CreditsView,
38+
DebugView,
3839
LegalView,
3940
PrivacyView,
4041
PushNotificationsSettingsView,
@@ -65,6 +66,7 @@ export const routes = {
6566
ContactsView: {screen: ContactsView},
6667
ContactsDetailView: {screen: ContactsDetailView},
6768
CreditsView: {screen: CreditsView},
69+
DebugView: {screen: DebugView},
6870
DictionaryDetailView: {screen: DictionaryDetailView},
6971
DictionaryView: {screen: DictionaryView},
7072
DictionaryEditorView: {screen: DictionaryEditorView},

source/views/settings/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
export {SettingsView} from './screens/overview'
44
export {IconSettingsView} from './screens/change-icon'
55
export {CreditsView} from './screens/credits'
6+
export {DebugView} from './screens/debug'
67
export {LegalView} from './screens/legal'
78
export {PrivacyView} from './screens/privacy'
89
export {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @flow
2+
3+
export {ConnectedDebugListView as DebugView} from './list'
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// @flow
2+
3+
import * as React from 'react'
4+
import {FlatList} from 'react-native'
5+
import {DebugRow} from './row'
6+
import {connect} from 'react-redux'
7+
import {NoticeView} from '@frogpond/notice'
8+
import {ListSeparator} from '@frogpond/lists'
9+
import toPairs from 'lodash/toPairs'
10+
import {toLaxTitleCase} from 'titlecase'
11+
import get from 'lodash/get'
12+
import type {NavigationState} from 'react-navigation'
13+
import type {TopLevelViewPropsType} from '../../../types'
14+
15+
type Props = TopLevelViewPropsType & {
16+
state: any,
17+
}
18+
19+
export class DebugListView extends React.PureComponent<Props> {
20+
static navigationOptions = ({navigation}: NavigationState) => {
21+
let titleParam = navigation.getParam('keyPath', 'Debug')
22+
let title =
23+
titleParam === 'Debug' ? titleParam : titleParam[titleParam.length - 1]
24+
25+
return {
26+
title: toLaxTitleCase(title),
27+
}
28+
}
29+
30+
onPressRow = (row: any) => {
31+
let keyPath = this.props.navigation.getParam('keyPath', [])
32+
keyPath = [...keyPath, row.key]
33+
this.props.navigation.push('DebugView', {keyPath: keyPath})
34+
}
35+
36+
keyExtractor = (item: any) => item.key
37+
38+
renderItem = ({item}: {item: any}) => (
39+
<DebugRow
40+
data={item}
41+
navigation={this.props.navigation}
42+
onPress={() => this.onPressRow(item)}
43+
/>
44+
)
45+
46+
render() {
47+
let keyed = toPairs(this.props.state).map(([key, value]) => {
48+
return {key, value}
49+
})
50+
51+
return (
52+
<FlatList
53+
ItemSeparatorComponent={ListSeparator}
54+
ListEmptyComponent={<NoticeView text="Nothing found in redux." />}
55+
data={keyed}
56+
keyExtractor={this.keyExtractor}
57+
renderItem={this.renderItem}
58+
/>
59+
)
60+
}
61+
}
62+
63+
function mapStateToProps(state, ownProps) {
64+
if (!ownProps.navigation.getParam('keyPath', null)) {
65+
return {state}
66+
}
67+
68+
return {
69+
state: get(state, ownProps.navigation.getParam('keyPath')),
70+
}
71+
}
72+
73+
export const ConnectedDebugListView = connect(mapStateToProps)(DebugListView)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// @flow
2+
3+
import * as React from 'react'
4+
import {Cell} from 'react-native-tableview-simple'
5+
import type {TopLevelViewPropsType} from '../../../types'
6+
7+
type Props = TopLevelViewPropsType & {
8+
data: {key: string, value: any},
9+
onPress: string => any,
10+
}
11+
12+
export class DebugRow extends React.PureComponent<Props> {
13+
render() {
14+
const {data} = this.props
15+
16+
let rowDetail = '<unknown>'
17+
let arrowPosition = 'none'
18+
19+
if (Array.isArray(data.value)) {
20+
// Array(0), Array(100), etc
21+
rowDetail = `Array(${data.value.length})`
22+
arrowPosition = 'center'
23+
} else if (typeof data.value === 'object' && data.value !== null) {
24+
// [object Object], [object Symbol], etc
25+
rowDetail = data.value.toString()
26+
arrowPosition = 'center'
27+
} else if (typeof data.value === 'string') {
28+
if (data.value.length > 20) {
29+
rowDetail = `"${data.value.substr(0, 20)}…"`
30+
} else {
31+
rowDetail = JSON.stringify(data.value)
32+
}
33+
} else {
34+
rowDetail = JSON.stringify(data.value)
35+
}
36+
37+
const arrowStyle = arrowPosition === 'none' ? false : 'DisclosureIndicator'
38+
const onPress = arrowPosition === 'none' ? null : this.props.onPress
39+
40+
return (
41+
<Cell
42+
accessory={arrowStyle}
43+
cellStyle="RightDetail"
44+
detail={rowDetail}
45+
onPress={onPress}
46+
title={data.key}
47+
/>
48+
)
49+
}
50+
}

source/views/settings/screens/overview/odds-and-ends.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@ import {setFeedbackStatus} from '../../../../redux/parts/settings'
66
import type {ReduxState} from '../../../../redux'
77
import {connect} from 'react-redux'
88
import {type NavigationScreenProp} from 'react-navigation'
9+
import {isDevMode} from '@frogpond/constants'
910

1011
type Props = {
1112
navigation: NavigationScreenProp<*>,
1213
}
1314

1415
export class OddsAndEndsSection extends React.Component<Props> {
16+
onDebugButton = () => this.props.navigation.navigate('DebugView')
17+
1518
onNotificationsButton = () => {
1619
this.props.navigation.navigate('PushNotificationsSettingsView')
1720
}
@@ -30,6 +33,10 @@ export class OddsAndEndsSection extends React.Component<Props> {
3033
<ConnectedAnalyticsCell />
3134

3235
<ConnectedNotificationsCell onPress={this.onNotificationsButton} />
36+
37+
{isDevMode && (
38+
<PushButtonCell onPress={this.onDebugButton} title="Debug" />
39+
)}
3340
</Section>
3441
)
3542
}

0 commit comments

Comments
 (0)