@dhirajpatil2025/report1chart 1.0.1 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, Text, StyleSheet } from 'react-native';
|
|
3
|
+
|
|
4
|
+
const ChartView = ({ data, height }) => (
|
|
5
|
+
<View style={[styles.chart, { height }]}>
|
|
6
|
+
{data.map((item, i) => (
|
|
7
|
+
<View key={i} style={styles.barWrap}>
|
|
8
|
+
<View style={[styles.bar, { height: item.value / 1000 }]} />
|
|
9
|
+
<Text style={styles.label}>{item.name}</Text>
|
|
10
|
+
</View>
|
|
11
|
+
))}
|
|
12
|
+
</View>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export default ChartView;
|
|
16
|
+
|
|
17
|
+
const styles = StyleSheet.create({
|
|
18
|
+
chart: { flexDirection: 'row', alignItems: 'flex-end' },
|
|
19
|
+
barWrap: { flex: 1, alignItems: 'center' },
|
|
20
|
+
bar: { width: 22, backgroundColor: '#4CAF50', borderRadius: 6 },
|
|
21
|
+
label: { fontSize: 12, marginTop: 6 },
|
|
22
|
+
});
|
package/src/index.js
CHANGED
|
@@ -1,132 +1,27 @@
|
|
|
1
1
|
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
TouchableOpacity,
|
|
6
|
-
ActivityIndicator,
|
|
7
|
-
StyleSheet,
|
|
8
|
-
} from 'react-native';
|
|
2
|
+
import { View } from 'react-native';
|
|
3
|
+
import ReportHomeScreen from './screens/ReportHomeScreen';
|
|
4
|
+
import ReportChartScreen from './screens/ReportChartScreen';
|
|
9
5
|
|
|
10
|
-
const
|
|
11
|
-
const [
|
|
12
|
-
const [chartData, setChartData] = useState([]);
|
|
13
|
-
const [active, setActive] = useState(null);
|
|
14
|
-
const [error, setError] = useState(null);
|
|
15
|
-
|
|
16
|
-
const buttons = [
|
|
17
|
-
{ label: 'Revenue', endpoint: '/revenue-trend' },
|
|
18
|
-
{ label: 'Orders', endpoint: '/orders-trend' },
|
|
19
|
-
{ label: 'Shipments', endpoint: '/shipments-trend' },
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
const fetchData = async (btn) => {
|
|
23
|
-
try {
|
|
24
|
-
setActive(btn.label);
|
|
25
|
-
setLoading(true);
|
|
26
|
-
setError(null);
|
|
27
|
-
|
|
28
|
-
const res = await fetch(`${baseUrl}${btn.endpoint}`);
|
|
29
|
-
const json = await res.json();
|
|
30
|
-
|
|
31
|
-
// Expecting:
|
|
32
|
-
// { labels: [...], values: [...] }
|
|
33
|
-
const formatted = json.labels.map((label, i) => ({
|
|
34
|
-
name: label,
|
|
35
|
-
value: json.values[i],
|
|
36
|
-
}));
|
|
37
|
-
|
|
38
|
-
setChartData(formatted);
|
|
39
|
-
} catch (e) {
|
|
40
|
-
setError('Failed to load data');
|
|
41
|
-
} finally {
|
|
42
|
-
setLoading(false);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
6
|
+
const ReportModule = ({ baseUrl, height = 220 }) => {
|
|
7
|
+
const [activeReport, setActiveReport] = useState(null);
|
|
45
8
|
|
|
46
9
|
return (
|
|
47
10
|
<View>
|
|
48
|
-
{
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
<TouchableOpacity
|
|
52
|
-
key={btn.label}
|
|
53
|
-
style={[
|
|
54
|
-
styles.btn,
|
|
55
|
-
active === btn.label && styles.activeBtn,
|
|
56
|
-
]}
|
|
57
|
-
onPress={() => fetchData(btn)}
|
|
58
|
-
>
|
|
59
|
-
<Text style={styles.btnText}>{btn.label}</Text>
|
|
60
|
-
</TouchableOpacity>
|
|
61
|
-
))}
|
|
62
|
-
</View>
|
|
63
|
-
|
|
64
|
-
{loading && <ActivityIndicator size="large" />}
|
|
65
|
-
{error && <Text style={styles.error}>{error}</Text>}
|
|
11
|
+
{!activeReport && (
|
|
12
|
+
<ReportHomeScreen onSelect={setActiveReport} />
|
|
13
|
+
)}
|
|
66
14
|
|
|
67
|
-
{
|
|
68
|
-
<
|
|
69
|
-
{
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
{ height: Math.max(item.value / 1000, 10) },
|
|
75
|
-
]}
|
|
76
|
-
/>
|
|
77
|
-
<Text style={styles.label}>{item.name}</Text>
|
|
78
|
-
</View>
|
|
79
|
-
))}
|
|
80
|
-
</View>
|
|
15
|
+
{activeReport && (
|
|
16
|
+
<ReportChartScreen
|
|
17
|
+
baseUrl={baseUrl}
|
|
18
|
+
report={activeReport}
|
|
19
|
+
height={height}
|
|
20
|
+
onClose={() => setActiveReport(null)}
|
|
21
|
+
/>
|
|
81
22
|
)}
|
|
82
23
|
</View>
|
|
83
24
|
);
|
|
84
25
|
};
|
|
85
26
|
|
|
86
|
-
export default
|
|
87
|
-
|
|
88
|
-
const styles = StyleSheet.create({
|
|
89
|
-
btnRow: {
|
|
90
|
-
flexDirection: 'row',
|
|
91
|
-
justifyContent: 'space-between',
|
|
92
|
-
marginBottom: 12,
|
|
93
|
-
},
|
|
94
|
-
btn: {
|
|
95
|
-
flex: 1,
|
|
96
|
-
marginHorizontal: 4,
|
|
97
|
-
paddingVertical: 8,
|
|
98
|
-
borderRadius: 6,
|
|
99
|
-
backgroundColor: '#e0e0e0',
|
|
100
|
-
alignItems: 'center',
|
|
101
|
-
},
|
|
102
|
-
activeBtn: {
|
|
103
|
-
backgroundColor: '#4CAF50',
|
|
104
|
-
},
|
|
105
|
-
btnText: {
|
|
106
|
-
fontWeight: '600',
|
|
107
|
-
color: '#000',
|
|
108
|
-
},
|
|
109
|
-
chart: {
|
|
110
|
-
flexDirection: 'row',
|
|
111
|
-
alignItems: 'flex-end',
|
|
112
|
-
marginTop: 12,
|
|
113
|
-
},
|
|
114
|
-
barWrap: {
|
|
115
|
-
flex: 1,
|
|
116
|
-
alignItems: 'center',
|
|
117
|
-
},
|
|
118
|
-
bar: {
|
|
119
|
-
width: 22,
|
|
120
|
-
backgroundColor: '#4CAF50',
|
|
121
|
-
borderRadius: 6,
|
|
122
|
-
},
|
|
123
|
-
label: {
|
|
124
|
-
fontSize: 12,
|
|
125
|
-
marginTop: 6,
|
|
126
|
-
},
|
|
127
|
-
error: {
|
|
128
|
-
color: 'red',
|
|
129
|
-
textAlign: 'center',
|
|
130
|
-
marginTop: 10,
|
|
131
|
-
},
|
|
132
|
-
});
|
|
27
|
+
export default ReportModule;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { Modal, View, Text, TouchableOpacity, StyleSheet } from 'react-native';
|
|
3
|
+
import { fetchReportData } from '../services/reportService';
|
|
4
|
+
import ChartView from '../components/ChartView';
|
|
5
|
+
import LoadingView from '../components/LoadingView';
|
|
6
|
+
|
|
7
|
+
const ReportChartScreen = ({ baseUrl, report, height, onClose }) => {
|
|
8
|
+
const [data, setData] = useState([]);
|
|
9
|
+
const [loading, setLoading] = useState(true);
|
|
10
|
+
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
load();
|
|
13
|
+
}, []);
|
|
14
|
+
|
|
15
|
+
const load = async () => {
|
|
16
|
+
const res = await fetchReportData(baseUrl, report.endpoint);
|
|
17
|
+
setData(res);
|
|
18
|
+
setLoading(false);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<Modal visible transparent animationType="slide">
|
|
23
|
+
<View style={styles.overlay}>
|
|
24
|
+
<View style={styles.container}>
|
|
25
|
+
<Text style={styles.title}>{report.label}</Text>
|
|
26
|
+
|
|
27
|
+
{loading ? <LoadingView /> : <ChartView data={data} height={height} />}
|
|
28
|
+
|
|
29
|
+
<TouchableOpacity onPress={onClose} style={styles.backBtn}>
|
|
30
|
+
<Text>Back</Text>
|
|
31
|
+
</TouchableOpacity>
|
|
32
|
+
</View>
|
|
33
|
+
</View>
|
|
34
|
+
</Modal>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export default ReportChartScreen;
|
|
39
|
+
|
|
40
|
+
const styles = StyleSheet.create({
|
|
41
|
+
overlay: { flex: 1, backgroundColor: 'rgba(0,0,0,0.4)', justifyContent: 'center', alignItems: 'center' },
|
|
42
|
+
container: { width: '90%', backgroundColor: '#fff', padding: 16, borderRadius: 12 },
|
|
43
|
+
title: { fontSize: 18, fontWeight: '700', marginBottom: 12, textAlign: 'center' },
|
|
44
|
+
backBtn: { marginTop: 16, padding: 10, borderWidth: 1, borderRadius: 6, alignItems: 'center' },
|
|
45
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
|
|
3
|
+
import REPORT_OPTIONS from '../constants/reportOptions';
|
|
4
|
+
|
|
5
|
+
const ReportHomeScreen = ({ onSelect }) => {
|
|
6
|
+
return (
|
|
7
|
+
<View style={styles.container}>
|
|
8
|
+
<Text style={styles.title}>Select Report</Text>
|
|
9
|
+
|
|
10
|
+
{REPORT_OPTIONS.map((item) => (
|
|
11
|
+
<TouchableOpacity
|
|
12
|
+
key={item.label}
|
|
13
|
+
style={styles.btn}
|
|
14
|
+
onPress={() => onSelect(item)}
|
|
15
|
+
>
|
|
16
|
+
<Text style={styles.btnText}>{item.label}</Text>
|
|
17
|
+
</TouchableOpacity>
|
|
18
|
+
))}
|
|
19
|
+
</View>
|
|
20
|
+
);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default ReportHomeScreen;
|
|
24
|
+
|
|
25
|
+
const styles = StyleSheet.create({
|
|
26
|
+
container: { padding: 16 },
|
|
27
|
+
title: { fontSize: 18, fontWeight: '700', marginBottom: 16, textAlign: 'center' },
|
|
28
|
+
btn: { padding: 12, marginVertical: 8, backgroundColor: '#4CAF50', borderRadius: 8 },
|
|
29
|
+
btnText: { color: '#fff', fontWeight: '600', textAlign: 'center' },
|
|
30
|
+
});
|