@dhiraj0720/report1chart 2.2.3 → 2.2.4

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.
@@ -1,417 +0,0 @@
1
- import React, { useState } from 'react';
2
- import {
3
- View,
4
- Text,
5
- StyleSheet,
6
- TouchableOpacity,
7
- ScrollView,
8
- ActivityIndicator,
9
- } from 'react-native';
10
- import { ApiFetcher } from '../api/fetcher';
11
- import ReportList from '../components/ReportList';
12
- import {
13
- renderTable,
14
- renderCompactTable,
15
- renderFreezeTable
16
- } from '../components/TableRenderer';
17
- import {
18
- renderLineChart,
19
- renderBarChart,
20
- renderPieChart,
21
- getColor
22
- } from '../components/ChartRenderer';
23
-
24
- const ReportScreen = ({
25
- onReportSelect,
26
- onClose,
27
- reports = []
28
- }) => {
29
- const [selectedReport, setSelectedReport] = useState(null);
30
- const [reportData, setReportData] = useState(null);
31
- const [loading, setLoading] = useState(false);
32
- const [error, setError] = useState(null);
33
- const [viewType, setViewType] = useState('default');
34
-
35
- const handleReportClick = async (report) => {
36
- setLoading(true);
37
- setError(null);
38
- setReportData(null);
39
- setSelectedReport(report);
40
- setViewType('default');
41
-
42
- try {
43
- // Fetch data using ApiFetcher from npm package
44
- const data = await ApiFetcher.fetchReportData(report);
45
- setReportData(data);
46
-
47
- if (onReportSelect) {
48
- onReportSelect(report.name);
49
- }
50
- } catch (err) {
51
- setError(err.message || 'Failed to fetch report data');
52
- } finally {
53
- setLoading(false);
54
- }
55
- };
56
-
57
- const renderChart = () => {
58
- if (!reportData || !reportData.data) {
59
- return (
60
- <View style={styles.noDataContainer}>
61
- <Text style={styles.noDataText}>No data available for this report</Text>
62
- </View>
63
- );
64
- }
65
-
66
- const { type, data, title } = reportData;
67
-
68
- // For performance reports
69
- if (type === 'table' && selectedReport &&
70
- (selectedReport.id === 1 || selectedReport.id === 1.1 || selectedReport.id === 1.2)) {
71
- switch (viewType) {
72
- case 'compact':
73
- return renderCompactTable(data);
74
- case 'freeze':
75
- return renderFreezeTable(data);
76
- case 'default':
77
- default:
78
- return renderTable(data);
79
- }
80
- }
81
-
82
- // For other table reports
83
- if (type === 'table') {
84
- return renderTable(data);
85
- }
86
-
87
- // For chart reports
88
- switch (type) {
89
- case 'line':
90
- return renderLineChart(data, title);
91
- case 'bar':
92
- return renderBarChart(data, title);
93
- case 'pie':
94
- return renderPieChart(data, title);
95
- default:
96
- return renderBarChart(data, title);
97
- }
98
- };
99
-
100
- // ========== RENDER SELECTED REPORT VIEW ==========
101
- if (selectedReport) {
102
- return (
103
- <View style={styles.container}>
104
- <View style={styles.header}>
105
- <TouchableOpacity
106
- style={styles.backButton}
107
- onPress={() => {
108
- setSelectedReport(null);
109
- setReportData(null);
110
- setViewType('default');
111
- }}
112
- >
113
- <Text style={styles.backText}>‹</Text>
114
- <Text style={styles.backButtonText}>Back</Text>
115
- </TouchableOpacity>
116
- <Text style={styles.headerTitle} numberOfLines={1}>
117
- {selectedReport.title || selectedReport.name}
118
- </Text>
119
- <TouchableOpacity onPress={onClose} style={styles.closeButton}>
120
- <Text style={styles.closeText}>×</Text>
121
- </TouchableOpacity>
122
- </View>
123
-
124
- {loading ? (
125
- <View style={styles.loadingContainer}>
126
- <ActivityIndicator size="large" color="#4CAF50" />
127
- <Text style={styles.loadingText}>Loading report data...</Text>
128
- </View>
129
- ) : error ? (
130
- <View style={styles.errorContainer}>
131
- <Text style={styles.errorText}>Error: {error}</Text>
132
- <TouchableOpacity
133
- style={styles.retryButton}
134
- onPress={() => handleReportClick(selectedReport)}
135
- >
136
- <Text style={styles.retryText}>Retry</Text>
137
- </TouchableOpacity>
138
- </View>
139
- ) : (
140
- <ScrollView style={styles.chartView}>
141
- {/* View Type Selector for Performance Reports */}
142
- {selectedReport &&
143
- (selectedReport.id === 1 || selectedReport.id === 1.1 || selectedReport.id === 1.2) &&
144
- reportData && (
145
- <View style={styles.viewTypeSelector}>
146
- <TouchableOpacity
147
- style={[
148
- styles.viewTypeButton,
149
- viewType === 'default' && styles.activeViewType
150
- ]}
151
- onPress={() => setViewType('default')}
152
- >
153
- <Text style={[
154
- styles.viewTypeText,
155
- viewType === 'default' && styles.activeViewTypeText
156
- ]}>Varsayılan</Text>
157
- </TouchableOpacity>
158
-
159
- <TouchableOpacity
160
- style={[
161
- styles.viewTypeButton,
162
- viewType === 'compact' && styles.activeViewType
163
- ]}
164
- onPress={() => setViewType('compact')}
165
- >
166
- <Text style={[
167
- styles.viewTypeText,
168
- viewType === 'compact' && styles.activeViewTypeText
169
- ]}>Kompakt</Text>
170
- </TouchableOpacity>
171
-
172
- <TouchableOpacity
173
- style={[
174
- styles.viewTypeButton,
175
- viewType === 'freeze' && styles.activeViewType
176
- ]}
177
- onPress={() => setViewType('freeze')}
178
- >
179
- <Text style={[
180
- styles.viewTypeText,
181
- viewType === 'freeze' && styles.activeViewTypeText
182
- ]}>Sabit Kolon</Text>
183
- </TouchableOpacity>
184
- </View>
185
- )}
186
-
187
- <View style={styles.chartContainer}>
188
- <Text style={styles.chartTitle}>{reportData?.title || selectedReport.title}</Text>
189
- {selectedReport.id === 1 || selectedReport.id === 1.1 || selectedReport.id === 1.2 ? (
190
- <Text style={styles.reportSubtitle}>
191
- {viewType === 'default' ? 'Varsayılan Görünüm' :
192
- viewType === 'compact' ? 'Kompakt Görünüm' :
193
- 'Sabit Kolonlu Görünüm'}
194
- </Text>
195
- ) : null}
196
- {renderChart()}
197
- </View>
198
-
199
- {reportData && reportData.data && (
200
- <View style={styles.dataInfo}>
201
- <Text style={styles.infoTitle}>Report Information</Text>
202
- <Text style={styles.infoText}>
203
- {selectedReport.description || 'Detailed analysis report'}
204
- </Text>
205
- <Text style={styles.dataSource}>
206
- Data points: {Array.isArray(reportData.data) ? reportData.data.length :
207
- reportData.data.values?.length || reportData.data.labels?.length || 'N/A'}
208
- </Text>
209
- </View>
210
- )}
211
- </ScrollView>
212
- )}
213
- </View>
214
- );
215
- }
216
-
217
- // ========== RENDER REPORT LIST VIEW ==========
218
- return (
219
- <View style={styles.container}>
220
- <View style={styles.header}>
221
- <Text style={styles.headerTitle}>Reports Dashboard</Text>
222
- <TouchableOpacity onPress={onClose} style={styles.closeButton}>
223
- <Text style={styles.closeText}>×</Text>
224
- </TouchableOpacity>
225
- </View>
226
-
227
- <ReportList
228
- reports={reports}
229
- onReportClick={handleReportClick}
230
- getColor={getColor}
231
- />
232
- </View>
233
- );
234
- };
235
-
236
- const styles = StyleSheet.create({
237
- container: {
238
- flex: 1,
239
- backgroundColor: '#f8f9fa',
240
- },
241
- header: {
242
- flexDirection: 'row',
243
- alignItems: 'center',
244
- justifyContent: 'space-between',
245
- backgroundColor: '#fff',
246
- paddingHorizontal: 16,
247
- paddingVertical: 12,
248
- borderBottomWidth: 1,
249
- borderBottomColor: '#e0e0e0',
250
- },
251
- headerTitle: {
252
- fontSize: 18,
253
- fontWeight: '700',
254
- color: '#000',
255
- flex: 1,
256
- textAlign: 'center',
257
- },
258
- backButton: {
259
- flexDirection: 'row',
260
- alignItems: 'center',
261
- padding: 8,
262
- },
263
- backText: {
264
- fontSize: 24,
265
- color: '#4CAF50',
266
- marginRight: 4,
267
- },
268
- backButtonText: {
269
- fontSize: 16,
270
- color: '#4CAF50',
271
- fontWeight: '600',
272
- },
273
- closeButton: {
274
- width: 32,
275
- height: 32,
276
- borderRadius: 16,
277
- backgroundColor: '#f0f0f0',
278
- justifyContent: 'center',
279
- alignItems: 'center',
280
- },
281
- closeText: {
282
- fontSize: 20,
283
- color: '#666',
284
- fontWeight: '300',
285
- },
286
- chartView: {
287
- flex: 1,
288
- padding: 16,
289
- },
290
- chartContainer: {
291
- backgroundColor: '#fff',
292
- borderRadius: 12,
293
- padding: 16,
294
- marginBottom: 16,
295
- borderWidth: 1,
296
- borderColor: '#e8e8e8',
297
- shadowColor: '#000',
298
- shadowOffset: { width: 0, height: 1 },
299
- shadowOpacity: 0.05,
300
- shadowRadius: 2,
301
- elevation: 2,
302
- },
303
- chartTitle: {
304
- fontSize: 18,
305
- fontWeight: '700',
306
- color: '#000',
307
- marginBottom: 20,
308
- textAlign: 'center',
309
- },
310
- dataInfo: {
311
- backgroundColor: '#e8f5e9',
312
- borderRadius: 12,
313
- padding: 16,
314
- marginTop: 8,
315
- },
316
- infoTitle: {
317
- fontSize: 16,
318
- fontWeight: '700',
319
- color: '#2e7d32',
320
- marginBottom: 8,
321
- },
322
- infoText: {
323
- fontSize: 14,
324
- color: '#555',
325
- lineHeight: 20,
326
- marginBottom: 8,
327
- },
328
- dataSource: {
329
- fontSize: 13,
330
- color: '#777',
331
- fontStyle: 'italic',
332
- },
333
- loadingContainer: {
334
- flex: 1,
335
- justifyContent: 'center',
336
- alignItems: 'center',
337
- padding: 40,
338
- },
339
- loadingText: {
340
- marginTop: 16,
341
- fontSize: 16,
342
- color: '#666',
343
- },
344
- errorContainer: {
345
- flex: 1,
346
- justifyContent: 'center',
347
- alignItems: 'center',
348
- padding: 40,
349
- },
350
- errorText: {
351
- fontSize: 16,
352
- color: '#d32f2f',
353
- textAlign: 'center',
354
- marginBottom: 20,
355
- },
356
- retryButton: {
357
- backgroundColor: '#4CAF50',
358
- paddingHorizontal: 24,
359
- paddingVertical: 12,
360
- borderRadius: 8,
361
- },
362
- retryText: {
363
- color: '#fff',
364
- fontSize: 16,
365
- fontWeight: '600',
366
- },
367
- noDataContainer: {
368
- padding: 40,
369
- alignItems: 'center',
370
- },
371
- noDataText: {
372
- fontSize: 16,
373
- color: '#999',
374
- textAlign: 'center',
375
- },
376
- viewTypeSelector: {
377
- flexDirection: 'row',
378
- backgroundColor: '#f0f0f0',
379
- borderRadius: 8,
380
- padding: 4,
381
- marginBottom: 16,
382
- alignSelf: 'center',
383
- },
384
- viewTypeButton: {
385
- paddingHorizontal: 16,
386
- paddingVertical: 8,
387
- borderRadius: 6,
388
- marginHorizontal: 2,
389
- },
390
- activeViewType: {
391
- backgroundColor: '#fff',
392
- shadowColor: '#000',
393
- shadowOffset: { width: 0, height: 1 },
394
- shadowOpacity: 0.1,
395
- shadowRadius: 2,
396
- elevation: 2,
397
- },
398
- viewTypeText: {
399
- fontSize: 13,
400
- fontWeight: '500',
401
- color: '#666',
402
- },
403
- activeViewTypeText: {
404
- color: '#4CAF50',
405
- fontWeight: '600',
406
- },
407
- reportSubtitle: {
408
- fontSize: 14,
409
- fontWeight: '600',
410
- color: '#4CAF50',
411
- textAlign: 'center',
412
- marginBottom: 16,
413
- fontStyle: 'italic',
414
- },
415
- });
416
-
417
- export default ReportScreen;