Skip to content

Commit c0d3d47

Browse files
committed
Devtools sub components
1 parent a2c0e5a commit c0d3d47

14 files changed

Lines changed: 260 additions & 0 deletions

File tree

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import React from 'react';
2+
3+
import { Pressable, StyleSheet, View } from 'react-native';
4+
5+
const CloseButton: React.FC<{ onPress: () => void }> = ({ onPress }) => {
6+
return (
7+
<Pressable style={styles.container} onPress={onPress}>
8+
<View style={styles.close} />
9+
</Pressable>
10+
);
11+
};
12+
13+
const styles = StyleSheet.create({
14+
container: {
15+
width: 40,
16+
height: 20,
17+
alignContent: 'center',
18+
justifyContent: 'center',
19+
},
20+
close: {
21+
width: 20,
22+
alignSelf: 'flex-end',
23+
borderWidth: 2,
24+
borderRadius: 3,
25+
borderColor: 'white',
26+
},
27+
});
28+
29+
export default CloseButton;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import React from 'react';
2+
3+
import { View } from 'react-native';
4+
5+
import JSONTreeSearcheable from '../JSONTreeSearcheable';
6+
import { styles } from './style';
7+
8+
const DataExplorer = ({ selectedQuery }) => {
9+
if (!selectedQuery) return null;
10+
11+
return (
12+
<View style={styles.container}>
13+
<JSONTreeSearcheable data={selectedQuery} />
14+
</View>
15+
);
16+
};
17+
18+
export default DataExplorer;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { StyleSheet } from 'react-native';
2+
3+
export const styles = StyleSheet.create({
4+
container: {
5+
backgroundColor: '#0b1521',
6+
},
7+
});
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import React from 'react';
2+
3+
import { Text, View } from 'react-native';
4+
5+
import JSONTree from 'react-native-json-tree';
6+
7+
import theme from './treeTheme';
8+
import JSONTreeSearcheableProps from './types';
9+
10+
import { styles } from './styles';
11+
12+
const JSONTreeSearcheable: React.FC<JSONTreeSearcheableProps> = ({
13+
data,
14+
searchTerm = '',
15+
}) => {
16+
const valueRenderer = (value: string) => {
17+
if (!searchTerm.trim()) return value;
18+
19+
const regex = new RegExp(searchTerm, 'gi');
20+
const parts = value.toString().split(regex);
21+
22+
return parts.map((part, index) => (
23+
<Text key={index}>
24+
{index > 0 && <Text style={styles.yellowBackground}>{searchTerm}</Text>}
25+
{part}
26+
</Text>
27+
));
28+
};
29+
30+
return (
31+
<View style={styles.container}>
32+
<JSONTree
33+
data={data}
34+
theme={{
35+
...theme,
36+
valueLabel: {
37+
fontWeight: 'bold',
38+
fontFamily: 'Courier New',
39+
},
40+
}}
41+
invertTheme={false}
42+
// labelRenderer={labelRenderer}
43+
valueRenderer={valueRenderer}
44+
/>
45+
</View>
46+
);
47+
};
48+
49+
export default JSONTreeSearcheable;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { StyleSheet } from 'react-native';
2+
3+
export const styles = StyleSheet.create({
4+
container: {
5+
backgroundColor: '#0b1521',
6+
},
7+
yellowBackground: {
8+
backgroundColor: 'yellow',
9+
},
10+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const theme = {
2+
scheme: "monokai",
3+
base00: "#0b1521", // background
4+
base03: "#75715e", // # of key when open
5+
base04: "#a59f85",
6+
base09: "#f92672", // numbers
7+
base0B: "#f92672", // values
8+
base0D: "#fff", // keys
9+
};
10+
11+
export default theme;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
interface JSONTreeSearcheableProps {
2+
data: unknown | any;
3+
searchTerm: string;
4+
}
5+
6+
export default JSONTreeSearcheableProps;
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import React from 'react';
2+
3+
import { Text, TouchableOpacity, View } from 'react-native';
4+
5+
import { QueryDevtoolData } from '../../types';
6+
import { styles } from './style';
7+
import QueryRowProps from './types';
8+
9+
const QueryRow: React.FC<QueryRowProps> = ({
10+
item,
11+
index,
12+
isSelected,
13+
handleSelectedRow,
14+
}) => {
15+
const getStyle = (query: QueryDevtoolData) => {
16+
if (query.observers === 0) {
17+
return { backgroundColor: 'gray' };
18+
}
19+
20+
if (query.isFetching) {
21+
return { backgroundColor: 'blue' };
22+
}
23+
24+
if (query.isStale) {
25+
return { backgroundColor: 'orange' };
26+
}
27+
28+
return { backgroundColor: 'green' };
29+
};
30+
31+
return (
32+
<TouchableOpacity onPress={() => handleSelectedRow(index)}>
33+
<View style={styles.container}>
34+
<View style={[styles.observersContainer, getStyle(item)]}>
35+
<Text style={styles.observerNumber}>{item.observers}</Text>
36+
</View>
37+
<Text
38+
style={[styles.queryKey, isSelected ? styles.queryKeySelected : {}]}
39+
>
40+
{JSON.stringify(item?.queryKey)}
41+
</Text>
42+
</View>
43+
</TouchableOpacity>
44+
);
45+
};
46+
47+
export default QueryRow;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { StyleSheet } from 'react-native';
2+
3+
export const styles = StyleSheet.create({
4+
container: {
5+
flexDirection: 'row',
6+
alignItems: 'center',
7+
marginVertical: 2,
8+
},
9+
observersContainer: {
10+
width: 20,
11+
height: 20,
12+
padding: 3,
13+
alignItems: 'center',
14+
justifyContent: 'center',
15+
},
16+
observerNumber: {
17+
textAlign: 'center',
18+
fontWeight: 'bold',
19+
color: 'white',
20+
fontSize: 12,
21+
},
22+
queryKey: {
23+
color: 'white',
24+
fontSize: 16,
25+
fontFamily: 'Courier New',
26+
marginLeft: 3,
27+
},
28+
queryKeySelected: {
29+
fontWeight: 'bold',
30+
},
31+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { QueryDevtoolData } from '../../types';
2+
3+
interface QueryRowProps {
4+
index: number;
5+
item: QueryDevtoolData;
6+
isSelected?: boolean;
7+
handleSelectedRow: (index: number) => void;
8+
}
9+
10+
export default QueryRowProps;

0 commit comments

Comments
 (0)