Skip to content

Commit b334515

Browse files
authored
Merge pull request #5 from jossydeleon/actionsheet-devtool
Feature: Actionsheet Devtool
2 parents 94a5bf5 + ce71146 commit b334515

30 files changed

Lines changed: 921 additions & 81 deletions

File tree

packages/react-native-query-devtool/README.md

Lines changed: 46 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,21 @@
33
## Features
44

55
- Provides a component for integrating query data in React Native applications running react-query v3, and @tanstack/react-query v4 and v5.
6-
- Includes a standalone app to visualize and help debug query data.
7-
8-
## Standalone App
9-
10-
The standalone app allows you to visualize and debug query data from your React Native application using the `@jsmdeleon/react-native-query-devtool` package.
6+
- (Optional) Includes a standalone app to visualize and help debug query data.
117

128
## Installation
139

14-
You can download the standalone app from the following link. Currently, it's available only for **macOS M1** and **Windows x64**:
15-
16-
[Download latest App](https://github.com/jossydeleon/react-native-query-devtool-monorepo/releases)
17-
18-
**Linux users:** You need to build the app from source as it's currently only available for **macOS M1** and **Windows x64**. Ensure to set up your environment accordingly before building the app.
19-
20-
```bash
21-
# Go to app folder
22-
cd react-native-query-devtool-app
23-
24-
# Install dependencies
25-
yarn
26-
27-
# Build
28-
yarn build-server
29-
```
30-
31-
After running the build command, you'll find the freshly built app in a new folder named **'out'**.
32-
33-
## React Native Component
34-
35-
To use the devtool component in your React Native project, install the package:
10+
To use the devtool component in your React Native project, install the package using `npm` or `yarn`, You will also need to install `react-native-gesture-handlers` if you haven't already.
3611

3712
```bash
38-
npm install @jsmdeleon/react-native-query-devtool
13+
npm install react-native-gesture-handler @jsmdeleon/react-native-query-devtool
3914
# or
40-
yarn add @jsmdeleon/react-native-query-devtool
15+
yarn add react-native-gesture-handler @jsmdeleon/react-native-query-devtool
4116
```
4217

4318
## Usage
4419

45-
In your React Native application, import `QueryNativeDevtool` to send query data to the Electron app for debugging:
20+
In your React Native application, import `QueryNativeDevtool`
4621

4722
```javascript
4823
import { QueryNativeDevtool } from "@jsmdeleon/react-native-query-devtool";
@@ -53,7 +28,7 @@ export default function App() {
5328
<View style={styles.container}>
5429
<Main />
5530
</View>
56-
<QueryNativeDevtool queryClient={queryClient} />
31+
<QueryNativeDevtool queryClient={queryClient} useRemoteDebugger={false} />
5732
</QueryClientProvider>
5833
);
5934
}
@@ -63,27 +38,56 @@ export default function App() {
6338

6439
If your app runs `react-query v3` pass `version="v3"` prop to `QueryNativeDevtool`
6540

66-
```javascript
67-
import { QueryNativeDevtool } from "@jsmdeleon/react-native-query-devtool";
41+
## Available Props
42+
43+
| Prop Name | Type | Description | Default Value |
44+
| -------------------- | ----------- | ------------------------------------------ | ------------- |
45+
| `queryClient`\* | QueryClient | First name of the user | undefined |
46+
| `version` | string | Last name of the user | "v5" |
47+
| `hideFloatingButton` | boolean | Hides Floating button | false |
48+
| `useRemoteDebugger` | boolean | Enable remote debugging via standalone app | false |
49+
50+
## Standalone app (Optional)
51+
52+
If you want more room to debug your query data, you can download the standalone app from the following link. Currently, it's available only for **macOS M1** and **Windows x64**. Check [Standalone Repo](https://github.com/jossydeleon/react-native-query-devtool-monorepo/tree/main/packages/react-native-query-devtool-app)
6853

54+
```javascript
6955
export default function App() {
7056
return (
7157
<QueryClientProvider client={queryClient}>
72-
<View style={styles.container}>
73-
<Main />
74-
</View>
75-
<QueryNativeDevtool queryClient={queryClient} version="v3" />
58+
<QueryNativeDevtool queryClient={queryClient} useRemoteDebugger={true} />
7659
</QueryClientProvider>
7760
);
7861
}
7962
```
8063

81-
This will enable your React Native application to send query data to the server app for debugging purposes.
64+
[Download latest App](https://github.com/jossydeleon/react-native-query-devtool-monorepo/releases)
65+
66+
**Note:** The binaries provided are not signed. If you have concerns about security or trust, you can choose to build the app from the source code for your machine.
67+
68+
**Linux users:** You need to build the app from source as it's currently only available for **macOS M1** and **Windows x64**. Ensure to set up your environment accordingly before building the app.
69+
70+
```bash
71+
# Go to app folder
72+
cd react-native-query-devtool-app
73+
74+
# Install dependencies
75+
yarn
76+
77+
# Build
78+
yarn build-server
79+
```
80+
81+
After running the build command, you'll find the freshly built app in a new folder named **'out'**.
82+
83+
**Important:** The standalone app uses port `9017` by default. Ensure that this port is available and not blocked by any firewall settings or other applications on your system.
8284

8385
## Examples
8486

8587
In the example folder, you can find example projects demonstrating the usage of `@jsmdeleon/react-native-query-devtool` with different versions of React Query (v3, v4, and v5). To test the examples, navigate to the example folder, select the desired example, and run yarn ios or yarn android.
8688

89+
[Examples Repo](https://github.com/jossydeleon/react-native-query-devtool-monorepo/tree/main/example)
90+
8791
```bash
8892
cd example
8993

@@ -98,3 +102,7 @@ yarn ios
98102
# or
99103
yarn android
100104
```
105+
106+
## Contributions
107+
108+
Contributions to improve this project are welcome! If you have any ideas for new features, enhancements, bug fixes, or optimizations, feel free to submit a pull request. You can also report any bugs or issues you encounter by opening a new issue
423 Bytes
Loading
10 KB
Loading

packages/react-native-query-devtool/package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
"build": "tsup"
2424
},
2525
"type": "module",
26+
"dependencies": {
27+
"react-native-actions-sheet": "^0.9.3",
28+
"react-native-json-tree":"^1.3.0"
29+
},
2630
"devDependencies": {
2731
"@types/node": "^20.11.8",
2832
"@types/react": "^18.2.48",
@@ -37,6 +41,7 @@
3741
},
3842
"peerDependencies": {
3943
"react": "*",
40-
"react-native": "*"
44+
"react-native": "*",
45+
"react-native-gesture-handler": "*"
4146
}
4247
}
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import React from "react";
2+
import { Image, Pressable, StyleSheet } from "react-native";
3+
4+
const CopyButton: React.FC<{ onPress?: () => void }> = ({ onPress }) => {
5+
return (
6+
<Pressable onPress={onPress}>
7+
<Image
8+
source={require("../../../assets/copy.png")}
9+
style={styles.container}
10+
/>
11+
</Pressable>
12+
);
13+
};
14+
15+
const styles = StyleSheet.create({
16+
container: {
17+
width: 14,
18+
height: 14,
19+
marginRight: 5,
20+
},
21+
});
22+
23+
export default CopyButton;
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: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import React from "react";
2+
3+
import { ScrollView, Text, View, FlatList } from "react-native";
4+
5+
import { ScrollView as ActionsheetScrollview } from "react-native-actions-sheet";
6+
7+
import { QueryDevtoolProps } from "../../types";
8+
import CloseButton from "../CloseButton";
9+
import DataExplorer from "../DataExplorer";
10+
import QueryRow from "../QueryRow";
11+
import Searchbar from "../Searchbar";
12+
import useDevtoolData from "./useDevtoolData";
13+
14+
import { styles } from "./styles";
15+
16+
const Devtool: React.FC<QueryDevtoolProps> = (props) => {
17+
const {
18+
filteredQueries,
19+
selectedQuery,
20+
filter,
21+
flalistRef,
22+
setFilter,
23+
handleSelectedRow,
24+
} = useDevtoolData(props);
25+
26+
const renderHeader = () => (
27+
<View style={styles.searchbarContainer}>
28+
<Searchbar filter={filter} setFilter={setFilter} />
29+
</View>
30+
);
31+
32+
const renderDataExplorerHeader = () => {
33+
if (!selectedQuery) return null;
34+
35+
return (
36+
<>
37+
<View style={styles.headerContainer}>
38+
<Text style={styles.headerText}>Data Explorer</Text>
39+
<CloseButton onPress={() => handleSelectedRow()} />
40+
</View>
41+
</>
42+
);
43+
};
44+
45+
const renderDataExplorer = () => {
46+
if (!selectedQuery) return null;
47+
48+
return (
49+
<View style={styles.dataExplorerContainer}>
50+
<DataExplorer selectedQuery={selectedQuery?.data} />
51+
</View>
52+
);
53+
};
54+
55+
return (
56+
<ActionsheetScrollview
57+
nestedScrollEnabled
58+
stickyHeaderIndices={[0, 2]}
59+
style={styles.actionScrollviewContainer}
60+
>
61+
{renderHeader()}
62+
<ScrollView
63+
horizontal
64+
scrollEnabled={false}
65+
style={[
66+
selectedQuery ? styles.collapsedFlatlist : styles.expandedFlatlist,
67+
]}
68+
>
69+
<FlatList
70+
ref={flalistRef}
71+
data={filteredQueries}
72+
style={[styles.queriesFlatlist]}
73+
renderItem={({ item, index }) => (
74+
<QueryRow
75+
index={index}
76+
item={item}
77+
isSelected={item.queryKey === selectedQuery?.queryKey}
78+
handleSelectedRow={handleSelectedRow}
79+
/>
80+
)}
81+
ItemSeparatorComponent={() => <View style={styles.separator} />}
82+
ListEmptyComponent={
83+
<Text style={styles.flatlistEmptyMessage}>No queries found</Text>
84+
}
85+
/>
86+
</ScrollView>
87+
88+
{renderDataExplorerHeader()}
89+
{renderDataExplorer()}
90+
</ActionsheetScrollview>
91+
);
92+
};
93+
94+
export default Devtool;
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { Dimensions, StyleSheet } from "react-native";
2+
3+
export const styles = StyleSheet.create({
4+
actionScrollviewContainer: {
5+
minHeight: 250,
6+
maxHeight: 500,
7+
},
8+
searchbarContainer: {
9+
backgroundColor: "#0b1521",
10+
padding: 2,
11+
paddingBottom: 1,
12+
},
13+
headerContainer: {
14+
flexDirection: "row",
15+
justifyContent: "space-between",
16+
alignItems: "center",
17+
backgroundColor: "#132337",
18+
padding: 10,
19+
borderTopLeftRadius: 10,
20+
borderTopRightRadius: 10,
21+
},
22+
headerText: {
23+
color: "white",
24+
},
25+
queriesContainer: {
26+
padding: 10,
27+
},
28+
queriesFlatlist: {
29+
width: Dimensions.get("screen").width,
30+
paddingHorizontal: 2,
31+
},
32+
flatlistEmptyMessage: {
33+
color: "white",
34+
textAlign: "center",
35+
},
36+
expandedFlatlist: {
37+
height: 400,
38+
marginBottom: 20,
39+
},
40+
collapsedFlatlist: {
41+
height: 250,
42+
},
43+
separator: {
44+
borderBottomWidth: 0.3,
45+
borderColor: "silver",
46+
marginVertical: 5,
47+
},
48+
dataExplorerContainer: {
49+
marginBottom: 20,
50+
},
51+
});

0 commit comments

Comments
 (0)