@dhiraj0720/report1chart 2.2.1 → 2.2.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 +5 -4
- package/src/api/fetcher.jsx +70 -0
- package/src/components/ChartRenderer.jsx +388 -0
- package/src/components/ReportList.jsx +135 -0
- package/src/components/ReportView.jsx +93 -0
- package/src/components/TableRenderer.jsx +647 -0
- package/src/index.jsx +4 -4
- package/src/screens/ReportScreen.jsx +417 -0
- package/src/api/ApiService.jsx +0 -162
- package/src/components/charts/BarChart.jsx +0 -116
- package/src/components/charts/LineChart.jsx +0 -134
- package/src/components/charts/PieChart.jsx +0 -120
- package/src/components/common/ErrorDisplay.jsx +0 -51
- package/src/components/common/LoadingSpinner.jsx +0 -32
- package/src/components/common/ReportCard.jsx +0 -84
- package/src/components/tables/CompactTable.jsx +0 -194
- package/src/components/tables/DefaultTable.jsx +0 -221
- package/src/components/tables/FreezeTable.jsx +0 -250
- package/src/screens/ReportDashboard.jsx +0 -121
- package/src/screens/ReportDetail.jsx +0 -222
- package/src/utils/Constants.jsx +0 -38
- package/src/utils/Formatters.jsx +0 -24
- package/src/utils/Validators.jsx +0 -60
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
import React, { useState } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
View,
|
|
4
|
-
Text,
|
|
5
|
-
StyleSheet,
|
|
6
|
-
TouchableOpacity,
|
|
7
|
-
ScrollView,
|
|
8
|
-
} from 'react-native';
|
|
9
|
-
import DefaultTable from '../components/tables/DefaultTable';
|
|
10
|
-
import CompactTable from '../components/tables/CompactTable';
|
|
11
|
-
import FreezeTable from '../components/tables/FreezeTable';
|
|
12
|
-
import BarChart from '../components/charts/BarChart';
|
|
13
|
-
import PieChart from '../components/charts/PieChart';
|
|
14
|
-
import LineChart from '../components/charts/LineChart';
|
|
15
|
-
import LoadingSpinner from '../components/common/LoadingSpinner';
|
|
16
|
-
import ErrorDisplay from '../components/common/ErrorDisplay';
|
|
17
|
-
|
|
18
|
-
const ReportDetail = ({ report, loading, error, onBack, onClose }) => {
|
|
19
|
-
const [viewType, setViewType] = useState(report.subType || 'default');
|
|
20
|
-
|
|
21
|
-
const renderContent = () => {
|
|
22
|
-
if (loading) {
|
|
23
|
-
return <LoadingSpinner message="Loading report data..." />;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (error) {
|
|
27
|
-
return <ErrorDisplay error={error} onRetry={() => onBack()} />;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (!report.data || (Array.isArray(report.data) && report.data.length === 0)) {
|
|
31
|
-
return (
|
|
32
|
-
<View style={styles.noDataContainer}>
|
|
33
|
-
<Text style={styles.noDataText}>No data available for this report</Text>
|
|
34
|
-
</View>
|
|
35
|
-
);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
switch (report.type) {
|
|
39
|
-
case 'table':
|
|
40
|
-
return renderTable();
|
|
41
|
-
case 'bar':
|
|
42
|
-
return <BarChart data={report.data} title={report.title} />;
|
|
43
|
-
case 'pie':
|
|
44
|
-
return <PieChart data={report.data} title={report.title} />;
|
|
45
|
-
case 'line':
|
|
46
|
-
return <LineChart data={report.data} title={report.title} />;
|
|
47
|
-
default:
|
|
48
|
-
return <BarChart data={report.data} title={report.title} />;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const renderTable = () => {
|
|
53
|
-
switch (viewType) {
|
|
54
|
-
case 'compact':
|
|
55
|
-
return <CompactTable data={report.data} />;
|
|
56
|
-
case 'freeze':
|
|
57
|
-
return <FreezeTable data={report.data} />;
|
|
58
|
-
default:
|
|
59
|
-
return <DefaultTable data={report.data} />;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<View style={styles.container}>
|
|
65
|
-
<View style={styles.header}>
|
|
66
|
-
<TouchableOpacity
|
|
67
|
-
style={styles.backButton}
|
|
68
|
-
onPress={onBack}
|
|
69
|
-
>
|
|
70
|
-
<Text style={styles.backText}>‹</Text>
|
|
71
|
-
<Text style={styles.backButtonText}>Back</Text>
|
|
72
|
-
</TouchableOpacity>
|
|
73
|
-
<Text style={styles.headerTitle} numberOfLines={1}>
|
|
74
|
-
{report.title || report.name}
|
|
75
|
-
</Text>
|
|
76
|
-
<TouchableOpacity onPress={onClose} style={styles.closeButton}>
|
|
77
|
-
<Text style={styles.closeText}>×</Text>
|
|
78
|
-
</TouchableOpacity>
|
|
79
|
-
</View>
|
|
80
|
-
|
|
81
|
-
{report.type === 'table' && (
|
|
82
|
-
<View style={styles.viewTypeSelector}>
|
|
83
|
-
<TouchableOpacity
|
|
84
|
-
style={[
|
|
85
|
-
styles.viewTypeButton,
|
|
86
|
-
viewType === 'default' && styles.activeViewType
|
|
87
|
-
]}
|
|
88
|
-
onPress={() => setViewType('default')}
|
|
89
|
-
>
|
|
90
|
-
<Text style={[
|
|
91
|
-
styles.viewTypeText,
|
|
92
|
-
viewType === 'default' && styles.activeViewTypeText
|
|
93
|
-
]}>Default</Text>
|
|
94
|
-
</TouchableOpacity>
|
|
95
|
-
|
|
96
|
-
<TouchableOpacity
|
|
97
|
-
style={[
|
|
98
|
-
styles.viewTypeButton,
|
|
99
|
-
viewType === 'compact' && styles.activeViewType
|
|
100
|
-
]}
|
|
101
|
-
onPress={() => setViewType('compact')}
|
|
102
|
-
>
|
|
103
|
-
<Text style={[
|
|
104
|
-
styles.viewTypeText,
|
|
105
|
-
viewType === 'compact' && styles.activeViewTypeText
|
|
106
|
-
]}>Compact</Text>
|
|
107
|
-
</TouchableOpacity>
|
|
108
|
-
|
|
109
|
-
<TouchableOpacity
|
|
110
|
-
style={[
|
|
111
|
-
styles.viewTypeButton,
|
|
112
|
-
viewType === 'freeze' && styles.activeViewType
|
|
113
|
-
]}
|
|
114
|
-
onPress={() => setViewType('freeze')}
|
|
115
|
-
>
|
|
116
|
-
<Text style={[
|
|
117
|
-
styles.viewTypeText,
|
|
118
|
-
viewType === 'freeze' && styles.activeViewTypeText
|
|
119
|
-
]}>Freeze</Text>
|
|
120
|
-
</TouchableOpacity>
|
|
121
|
-
</View>
|
|
122
|
-
)}
|
|
123
|
-
|
|
124
|
-
<ScrollView style={styles.content}>
|
|
125
|
-
{renderContent()}
|
|
126
|
-
</ScrollView>
|
|
127
|
-
</View>
|
|
128
|
-
);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const styles = StyleSheet.create({
|
|
132
|
-
container: {
|
|
133
|
-
flex: 1,
|
|
134
|
-
backgroundColor: '#f8f9fa',
|
|
135
|
-
},
|
|
136
|
-
header: {
|
|
137
|
-
flexDirection: 'row',
|
|
138
|
-
alignItems: 'center',
|
|
139
|
-
justifyContent: 'space-between',
|
|
140
|
-
backgroundColor: '#fff',
|
|
141
|
-
paddingHorizontal: 16,
|
|
142
|
-
paddingVertical: 12,
|
|
143
|
-
borderBottomWidth: 1,
|
|
144
|
-
borderBottomColor: '#e0e0e0',
|
|
145
|
-
},
|
|
146
|
-
headerTitle: {
|
|
147
|
-
fontSize: 18,
|
|
148
|
-
fontWeight: '700',
|
|
149
|
-
color: '#000',
|
|
150
|
-
flex: 1,
|
|
151
|
-
textAlign: 'center',
|
|
152
|
-
},
|
|
153
|
-
backButton: {
|
|
154
|
-
flexDirection: 'row',
|
|
155
|
-
alignItems: 'center',
|
|
156
|
-
padding: 8,
|
|
157
|
-
},
|
|
158
|
-
backText: {
|
|
159
|
-
fontSize: 24,
|
|
160
|
-
color: '#4CAF50',
|
|
161
|
-
marginRight: 4,
|
|
162
|
-
},
|
|
163
|
-
backButtonText: {
|
|
164
|
-
fontSize: 16,
|
|
165
|
-
color: '#4CAF50',
|
|
166
|
-
fontWeight: '600',
|
|
167
|
-
},
|
|
168
|
-
closeButton: {
|
|
169
|
-
width: 32,
|
|
170
|
-
height: 32,
|
|
171
|
-
borderRadius: 16,
|
|
172
|
-
backgroundColor: '#f0f0f0',
|
|
173
|
-
justifyContent: 'center',
|
|
174
|
-
alignItems: 'center',
|
|
175
|
-
},
|
|
176
|
-
closeText: {
|
|
177
|
-
fontSize: 20,
|
|
178
|
-
color: '#666',
|
|
179
|
-
fontWeight: '300',
|
|
180
|
-
},
|
|
181
|
-
content: {
|
|
182
|
-
flex: 1,
|
|
183
|
-
padding: 16,
|
|
184
|
-
},
|
|
185
|
-
viewTypeSelector: {
|
|
186
|
-
flexDirection: 'row',
|
|
187
|
-
backgroundColor: '#f0f0f0',
|
|
188
|
-
borderRadius: 8,
|
|
189
|
-
padding: 4,
|
|
190
|
-
margin: 16,
|
|
191
|
-
alignSelf: 'center',
|
|
192
|
-
},
|
|
193
|
-
viewTypeButton: {
|
|
194
|
-
paddingHorizontal: 16,
|
|
195
|
-
paddingVertical: 8,
|
|
196
|
-
borderRadius: 6,
|
|
197
|
-
marginHorizontal: 2,
|
|
198
|
-
},
|
|
199
|
-
activeViewType: {
|
|
200
|
-
backgroundColor: '#fff',
|
|
201
|
-
},
|
|
202
|
-
viewTypeText: {
|
|
203
|
-
fontSize: 13,
|
|
204
|
-
fontWeight: '500',
|
|
205
|
-
color: '#666',
|
|
206
|
-
},
|
|
207
|
-
activeViewTypeText: {
|
|
208
|
-
color: '#4CAF50',
|
|
209
|
-
fontWeight: '600',
|
|
210
|
-
},
|
|
211
|
-
noDataContainer: {
|
|
212
|
-
padding: 40,
|
|
213
|
-
alignItems: 'center',
|
|
214
|
-
},
|
|
215
|
-
noDataText: {
|
|
216
|
-
fontSize: 16,
|
|
217
|
-
color: '#999',
|
|
218
|
-
textAlign: 'center',
|
|
219
|
-
},
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
export default ReportDetail;
|
package/src/utils/Constants.jsx
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
export const COLORS = {
|
|
2
|
-
primary: '#4CAF50',
|
|
3
|
-
primaryDark: '#388E3C',
|
|
4
|
-
primaryLight: '#C8E6C9',
|
|
5
|
-
secondary: '#2196F3',
|
|
6
|
-
accent: '#FF9800',
|
|
7
|
-
success: '#27ae60',
|
|
8
|
-
warning: '#f39c12',
|
|
9
|
-
danger: '#e74c3c',
|
|
10
|
-
info: '#3498db',
|
|
11
|
-
dark: '#2c3e50',
|
|
12
|
-
light: '#ecf0f1',
|
|
13
|
-
white: '#ffffff',
|
|
14
|
-
black: '#000000',
|
|
15
|
-
gray: '#95a5a6',
|
|
16
|
-
grayDark: '#7f8c8d',
|
|
17
|
-
grayLight: '#bdc3c7'
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const API_STATUS = {
|
|
21
|
-
IDLE: 'idle',
|
|
22
|
-
LOADING: 'loading',
|
|
23
|
-
SUCCESS: 'success',
|
|
24
|
-
ERROR: 'error'
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export const CHART_TYPES = {
|
|
28
|
-
BAR: 'bar',
|
|
29
|
-
LINE: 'line',
|
|
30
|
-
PIE: 'pie',
|
|
31
|
-
TABLE: 'table'
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const TABLE_VIEW_TYPES = {
|
|
35
|
-
DEFAULT: 'default',
|
|
36
|
-
COMPACT: 'compact',
|
|
37
|
-
FREEZE: 'freeze'
|
|
38
|
-
};
|
package/src/utils/Formatters.jsx
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
export const formatCurrency = (value) => {
|
|
2
|
-
const num = Number(value);
|
|
3
|
-
if (isNaN(num)) return '0';
|
|
4
|
-
|
|
5
|
-
if (num >= 1000000) {
|
|
6
|
-
return `${(num / 1000000).toFixed(1)}M`;
|
|
7
|
-
} else if (num >= 1000) {
|
|
8
|
-
return `${(num / 1000).toFixed(1)}K`;
|
|
9
|
-
}
|
|
10
|
-
return num.toLocaleString();
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const formatNumber = (num) => {
|
|
14
|
-
return num.toLocaleString();
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const formatPercentage = (value, decimals = 1) => {
|
|
18
|
-
return `${value >= 0 ? '+' : ''}${value.toFixed(decimals)}%`;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const getColor = (index) => {
|
|
22
|
-
const colors = ['#4CAF50', '#2196F3', '#FF9800', '#E91E63', '#9C27B0', '#00BCD4'];
|
|
23
|
-
return colors[index % colors.length];
|
|
24
|
-
};
|
package/src/utils/Validators.jsx
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
export const isValidUrl = (url) => {
|
|
2
|
-
try {
|
|
3
|
-
new URL(url);
|
|
4
|
-
return true;
|
|
5
|
-
} catch (error) {
|
|
6
|
-
return false;
|
|
7
|
-
}
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const isValidApiResponse = (data) => {
|
|
11
|
-
if (!data) return false;
|
|
12
|
-
|
|
13
|
-
// Check if data is array or has data property
|
|
14
|
-
if (Array.isArray(data)) {
|
|
15
|
-
return data.length > 0;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
if (data.data && Array.isArray(data.data)) {
|
|
19
|
-
return data.data.length > 0;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (data.values && Array.isArray(data.values)) {
|
|
23
|
-
return data.values.length > 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
return false;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export const validateApiConfig = (apiConfig) => {
|
|
30
|
-
const errors = [];
|
|
31
|
-
|
|
32
|
-
if (!apiConfig || typeof apiConfig !== 'object') {
|
|
33
|
-
errors.push('API configuration is required');
|
|
34
|
-
return errors;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!apiConfig.url || typeof apiConfig.url !== 'string') {
|
|
38
|
-
errors.push('API URL is required and must be a string');
|
|
39
|
-
} else if (!isValidUrl(apiConfig.url)) {
|
|
40
|
-
errors.push('Invalid API URL format');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (apiConfig.method && typeof apiConfig.method !== 'string') {
|
|
44
|
-
errors.push('API method must be a string');
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
if (apiConfig.token && typeof apiConfig.token !== 'string') {
|
|
48
|
-
errors.push('API token must be a string');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return errors;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const formatErrorMessage = (error) => {
|
|
55
|
-
if (typeof error === 'string') return error;
|
|
56
|
-
if (error.message) return error.message;
|
|
57
|
-
if (error.response?.data?.message) return error.response.data.message;
|
|
58
|
-
if (error.response?.statusText) return `${error.response.status}: ${error.response.statusText}`;
|
|
59
|
-
return 'An unknown error occurred';
|
|
60
|
-
};
|