datastake-daf 0.6.773 → 0.6.774

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,554 +0,0 @@
1
- import { Tooltip } from "antd";
2
- import { MoreMenu , CustomIcon} from "../../../../../../../index";
3
- import { renderDateFormatted } from "../../../../../../../helpers/Forms";
4
- import { Avatar, Tag } from "antd";
5
- import { convertDMS } from "../../../../../../../helpers/Map";
6
-
7
- const ACTIVITIES_TAB = 'activities';
8
- const PARTNERS_TAB = 'partners';
9
- const INCIDENTS_TAB = 'incidents';
10
-
11
- export const getColumns = ({
12
- projectId,
13
- t,
14
- show = 'show',
15
- navigate,
16
- selectOptions,
17
- view,
18
- getRedirectLink,
19
- activeTab = ACTIVITIES_TAB,
20
- }) => {
21
- const renderActions = (record, viewType = 'activities') => {
22
- if (record.empty) {
23
- return <div className="daf-default-cell" />;
24
- }
25
-
26
- if (!navigate || !getRedirectLink) {
27
- return null;
28
- }
29
-
30
- const onClick = () => {
31
- const link = `/app/view/${viewType}/${record.datastakeId}`;
32
- navigate(getRedirectLink(link));
33
- };
34
-
35
- const menuItems = [
36
- {
37
- label: t("Details"),
38
- key: "details",
39
- onClick: onClick
40
- }
41
- ];
42
-
43
- if (viewType === 'activities') {
44
- menuItems.push({
45
- label: t("Summary"),
46
- key: "summary",
47
- onClick: () => {
48
- const link = `/app/projects/${record.projectId}/planting-cycles/summary/${record.datastakeId}`;
49
- navigate(getRedirectLink(link));
50
- }
51
- });
52
- }
53
-
54
- return <MoreMenu items={menuItems} />;
55
- };
56
-
57
- if (activeTab === ACTIVITIES_TAB) {
58
- return [
59
- {
60
- title: "",
61
- dataIndex: 'image',
62
- key: 'image',
63
- active: true,
64
- width: 80,
65
- pending: true,
66
- suspended: true,
67
- ellipsis: true,
68
- render: (v, all) => {
69
- if (all.empty) {
70
- return <div className="daf-default-cell" />;
71
- }
72
-
73
- const firstGroupPhoto = all?.groupPhotos?.[0];
74
- const pictures = firstGroupPhoto?.pictures;
75
- const firstPicture = Array.isArray(pictures) && pictures.length > 0 ? pictures[0] : null;
76
- let imageUrl = firstPicture?.url;
77
-
78
- const normalizeUrl = (url) => url?.endsWith(':') ? url.slice(0, -1) : url;
79
- let normalizedUrl = imageUrl ? normalizeUrl(imageUrl.trim()) : null;
80
-
81
- if (normalizedUrl && !normalizedUrl.startsWith('http://') && !normalizedUrl.startsWith('https://') && !normalizedUrl.startsWith('//')) {
82
- if (normalizedUrl.startsWith('cdn.') || (normalizedUrl.includes('.') && !normalizedUrl.startsWith('/'))) {
83
- normalizedUrl = `https://${normalizedUrl}`;
84
- }
85
- }
86
-
87
- return (
88
- <div className="daf-default-cell" style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
89
- <div
90
- style={{
91
- width: 32,
92
- height: 32,
93
- borderWidth: '1px',
94
- borderStyle: 'solid',
95
- borderColor: '#E5E7EB',
96
- borderRadius: '6px',
97
- background: '#F9FAFB',
98
- display: 'flex',
99
- alignItems: 'center',
100
- justifyContent: 'center',
101
- overflow: 'hidden',
102
- position: 'relative',
103
- }}
104
- >
105
- {normalizedUrl && (
106
- <img
107
- src={normalizedUrl}
108
- alt={all.name || 'Activity image'}
109
- style={{
110
- width: '100%',
111
- height: '100%',
112
- objectFit: 'cover',
113
- borderRadius: '6px',
114
- }}
115
- onError={(e) => {
116
- e.target.style.display = 'none';
117
- }}
118
- />
119
- )}
120
- </div>
121
- </div>
122
- );
123
- }
124
- },
125
- {
126
- title: t('ID'),
127
- dataIndex: 'datastakeId',
128
- key: 'datastakeId',
129
- active: true,
130
- pending: true,
131
- suspended: true,
132
- ellipsis: true,
133
- render: (v, all) => {
134
- if (all.empty) {
135
- return <div className="daf-default-cell" />;
136
- }
137
- return (
138
- <div className="daf-default-cell">
139
- {all.datastakeId}
140
- </div>
141
- );
142
- }
143
- },
144
- {
145
- title: t("Title"),
146
- dataIndex: "name",
147
- key: "name",
148
- ellipsis: true,
149
- active: true,
150
- pending: true,
151
- suspended: true,
152
- render: (value) => <Tooltip title={value}>{value}</Tooltip>,
153
- },
154
- {
155
- title: t("Type"),
156
- dataIndex: "type",
157
- key: "type",
158
- ellipsis: true,
159
- active: true,
160
- pending: true,
161
- suspended: true,
162
- render: (value, all) => {
163
- if (all.empty) {
164
- return <div className="daf-default-cell" />;
165
- }
166
- return <Tooltip title={value}>{value?.toUpperCase().charAt(0) + value?.slice(1) || '-'}</Tooltip>;
167
- },
168
- },
169
- {
170
- title: t("Location"),
171
- dataIndex: "location",
172
- key: "location",
173
- ellipsis: true,
174
- active: true,
175
- pending: true,
176
- width: 220,
177
- suspended: true,
178
- show: true,
179
- render: (value, all) => {
180
- if (all.empty) {
181
- return <div className="daf-default-cell" />;
182
- }
183
-
184
- const location = all.location || value;
185
- if (location && typeof location === 'object' && typeof location.latitude === 'number' && typeof location.longitude === 'number') {
186
- const coordinates = convertDMS(location.latitude, location.longitude);
187
- const iconColor = "#016C6E";
188
-
189
- return (
190
- <div style={{ display: 'flex', alignItems: 'center', gap: '8px', flexWrap: 'nowrap' }}>
191
- <div style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
192
- <CustomIcon
193
- name="SpacingHeight"
194
- width={14}
195
- height={14}
196
- fill={iconColor}
197
- />
198
- <span>{coordinates[0]}</span>
199
- </div>
200
-
201
- <div style={{ display: 'flex', alignItems: 'center', gap: '4px' }}>
202
- <CustomIcon
203
- name="SpacingWidth"
204
- width={14}
205
- height={14}
206
- fill={iconColor}
207
- />
208
- <span>{coordinates[1]}</span>
209
- </div>
210
- </div>
211
- );
212
- }
213
-
214
- let locationDisplay = '-';
215
- if (all.project?.name || all.project?.title) {
216
- locationDisplay = all.project?.name || all.project?.title;
217
- } else if (location?.name) {
218
- locationDisplay = location.name;
219
- } else if (value && typeof value === 'string') {
220
- locationDisplay = value;
221
- }
222
- return <Tooltip title={locationDisplay}>{locationDisplay}</Tooltip>
223
- },
224
- },
225
- {
226
- title: t("Implementer"),
227
- dataIndex: "technicalPartner",
228
- key: "implementer",
229
- ellipsis: true,
230
- show: true,
231
- render: (value, all) => {
232
- if (all.empty) {
233
- return <div className="daf-default-cell" />;
234
- }
235
- const implementerName = all.technicalPartner || all.implementer?.name || all.implementer?.title || value || '-';
236
- return <Tooltip title={implementerName}>{implementerName}</Tooltip>;
237
- }
238
- },
239
- {
240
- title: t("Status"),
241
- dataIndex: "published",
242
- key: "published",
243
- ellipsis: false,
244
- show: true,
245
- render: (value, all) => {
246
- if (all.empty) {
247
- return <div className="daf-default-cell" />;
248
- }
249
- let statusDisplay = '-';
250
- let color = 'default';
251
- if (value !== undefined) {
252
- statusDisplay = value ? t('Published') : t('Unpublished');
253
- color = value ? 'green' : 'default';
254
- }
255
- return <Tag color={color} style={{ width: 100 }} className="text-center">
256
- {t(statusDisplay)}
257
- </Tag>
258
- }
259
- },
260
- {
261
- title: t("Date"),
262
- dataIndex: "lastUpdated",
263
- key: "lastUpdated",
264
- ellipsis: true,
265
- active: true,
266
- pending: false,
267
- suspended: true,
268
- show: true,
269
- render: (val, all) => {
270
- if (all.empty) {
271
- return <div className="daf-default-cell" />;
272
- }
273
- const title = renderDateFormatted(all.updatedAt || all.date, "DD MMM YYYY");
274
- return <Tooltip title={title}>{title}</Tooltip>;
275
- },
276
- },
277
- {
278
- title: "",
279
- dataIndex: "actions",
280
- key: "actions",
281
- width: 60,
282
- render: (_, val) => {
283
- if (val.empty) {
284
- return <div className="daf-default-cell" />;
285
- }
286
-
287
- const items = [
288
- {
289
- key: "viewSummary",
290
- label: t("Summary"),
291
- onClick: () => {
292
- const link = `/app/projects/${projectId}/restoration/summary/${val.datastakeId}`;
293
- navigate(getRedirectLink(link));
294
- }
295
- },
296
- {
297
- key: "viewDetails",
298
- label: t("Details"),
299
- onClick: () => {
300
- const link = `/app/projects/${projectId}/restoration/view/general/${val.datastakeId}/identification`;
301
- navigate(getRedirectLink(link));
302
- }
303
- },
304
- ];
305
-
306
- return <MoreMenu items={items} />;
307
- },
308
- ellipsis: true,
309
- },
310
- ];
311
- }
312
-
313
- if (activeTab === PARTNERS_TAB) {
314
- return [
315
- {
316
- title: t('ID'),
317
- dataIndex: 'datastakeId',
318
- key: 'datastakeId',
319
- ellipsis: true,
320
- width: 160,
321
- render: (v, all) => {
322
- if (all.empty) {
323
- return <div className="daf-default-cell" />;
324
- }
325
- return <Tooltip title={v}>{v || '-'}</Tooltip>;
326
- }
327
- },
328
- {
329
- title: t("Name"),
330
- dataIndex: "name",
331
- key: "name",
332
- ellipsis: true,
333
- render: (value, all) => {
334
- if (all.empty) {
335
- return <div className="daf-default-cell" />;
336
- }
337
- const name = value || all.nickName || '-';
338
- return <Tooltip title={name}>{name}</Tooltip>;
339
- },
340
- },
341
- {
342
- title: t("Category"),
343
- dataIndex: "category",
344
- key: "category",
345
- ellipsis: true,
346
- render: (value, all) => {
347
- if (all.empty) {
348
- return <div className="daf-default-cell" />;
349
- }
350
- return <Tooltip title={value}>{value || '-'}</Tooltip>;
351
- },
352
- },
353
- {
354
- title: t("Subcategory"),
355
- dataIndex: "subcategory",
356
- key: "subcategory",
357
- ellipsis: true,
358
- render: (value, all) => {
359
- if (all.empty) {
360
- return <div className="daf-default-cell" />;
361
- }
362
- return <Tooltip title={value}>{value || '-'}</Tooltip>;
363
- },
364
- },
365
- {
366
- title: t("Country"),
367
- dataIndex: "country",
368
- key: "country",
369
- ellipsis: true,
370
- render: (value, all) => {
371
- if (all.empty) {
372
- return <div className="daf-default-cell" />;
373
- }
374
- let country = '-';
375
- if (value) {
376
- country = value;
377
- } else if (all.country?.name) {
378
- country = all.country.name;
379
- } else if (all.location && typeof all.location === 'object' && all.location.country) {
380
- country = all.location.country;
381
- } else if (all.location && typeof all.location === 'object' && all.location.name) {
382
- country = all.location.name;
383
- }
384
- return <Tooltip title={country}>{country}</Tooltip>;
385
- },
386
- },
387
- {
388
- title: t("Last Update"),
389
- dataIndex: "lastUpdated",
390
- key: "lastUpdated",
391
- ellipsis: true,
392
- render: (val, all) => {
393
- if (all.empty) {
394
- return <div className="daf-default-cell" />;
395
- }
396
- const title = renderDateFormatted(all.updatedAt || all.lastUpdated, "DD MMM YYYY");
397
- return <Tooltip title={title}>{title}</Tooltip>;
398
- },
399
- },
400
- {
401
- title: t(''),
402
- dataIndex: 'actions',
403
- key: 'actions',
404
- width: 60,
405
- render: (_, record) => {
406
- const onClick = () => {
407
- const id = record.id;
408
- const link = `/app/projects/${projectId}/implementation-partners/view/general/${record?.datastakeId}/identification`;
409
- navigate(getRedirectLink(link));
410
- }
411
- return !record.empty ? (
412
- <div className="cursor-pointer" onClick={onClick}>
413
- <CustomIcon name="Link" width={16} height={16} color="#6C737F" />
414
- </div>
415
- ) : null;
416
- },
417
- active: true,
418
- pending: true,
419
- suspended: true,
420
- },
421
- ];
422
- }
423
-
424
- if (activeTab === INCIDENTS_TAB) {
425
- return [
426
- {
427
- title: t('ID'),
428
- dataIndex: 'datastakeId',
429
- key: 'datastakeId',
430
- ellipsis: true,
431
- width: 160,
432
- render: (v, all) => {
433
- if (all.empty) {
434
- return <div className="daf-default-cell" />;
435
- }
436
- return <Tooltip title={v}>{v}</Tooltip>;
437
- }
438
- },
439
- {
440
- title: t("Title"),
441
- dataIndex: "name",
442
- key: "name",
443
- ellipsis: true,
444
- render: (value) => <Tooltip title={value}>{value}</Tooltip>,
445
- },
446
- {
447
- title: t("Date"),
448
- dataIndex: "date",
449
- key: "date",
450
- ellipsis: true,
451
- render: (val, all) => {
452
- if (all.empty) {
453
- return <div className="daf-default-cell" />;
454
- }
455
- const title = renderDateFormatted(all.date || all.updatedAt, "DD MMM YYYY");
456
- return <Tooltip title={title}>{title}</Tooltip>;
457
- },
458
- },
459
- {
460
- title: t("Location"),
461
- dataIndex: "location",
462
- key: "location",
463
- ellipsis: true,
464
- render: (value, all) => {
465
- if (all.empty) {
466
- return <div className="daf-default-cell" />;
467
- }
468
- let locationDisplay = '-';
469
- if (all.location?.name) {
470
- locationDisplay = all.location.name;
471
- } else if (all.mineSite?.name) {
472
- locationDisplay = all.mineSite.name;
473
- } else if (all.location && typeof all.location === 'object' && all.location.latitude && all.location.longitude) {
474
- locationDisplay = `${all.location.latitude.toFixed(6)}, ${all.location.longitude.toFixed(6)}`;
475
- } else if (value && typeof value === 'string') {
476
- locationDisplay = value;
477
- }
478
- return <Tooltip title={locationDisplay}>{locationDisplay}</Tooltip>;
479
- },
480
- },
481
- {
482
- title: t("Province"),
483
- dataIndex: "province",
484
- key: "province",
485
- ellipsis: true,
486
- render: (value, all) => {
487
- if (all.empty) {
488
- return <div className="daf-default-cell" />;
489
- }
490
- let province = '-';
491
- if (all.province) {
492
- province = all.province;
493
- } else if (all.location && typeof all.location === 'object' && all.location.administrativeLevel1) {
494
- province = all.location.administrativeLevel1;
495
- }
496
- return <Tooltip title={province}>{province}</Tooltip>;
497
- },
498
- },
499
- {
500
- title: t("Territory"),
501
- dataIndex: "territory",
502
- key: "territory",
503
- ellipsis: true,
504
- render: (value, all) => {
505
- if (all.empty) {
506
- return <div className="daf-default-cell" />;
507
- }
508
- let territory = '-';
509
- if (all.territory) {
510
- territory = all.territory;
511
- } else if (all.location && typeof all.location === 'object' && all.location.administrativeLevel2) {
512
- territory = all.location.administrativeLevel2;
513
- }
514
- return <Tooltip title={territory}>{territory}</Tooltip>;
515
- },
516
- },
517
- {
518
- title: t("Category"),
519
- dataIndex: "category",
520
- key: "category",
521
- ellipsis: true,
522
- render: (value, all) => {
523
- if (all.empty) {
524
- return <div className="daf-default-cell" />;
525
- }
526
- const category = all.eventCategory || all.category || value || '-';
527
- return <Tooltip title={category}>{category}</Tooltip>;
528
- },
529
- },
530
- {
531
- title: t(''),
532
- dataIndex: 'actions',
533
- key: 'actions',
534
- width: 60,
535
- render: (_, record) => {
536
- const onClick = () => {
537
- const link = `/app/projects/${projectId}/implementation-partners/view/general/${record.datastakeId}/identification`;
538
- getRedirectLink(link);
539
- }
540
- return !record.empty ? (
541
- <div className="cursor-pointer" onClick={onClick}>
542
- <CustomIcon name="Link" width={16} height={16} color="#6C737F" />
543
- </div>
544
- ) : null;
545
- },
546
- active: true,
547
- pending: true,
548
- suspended: true,
549
- },
550
- ];
551
- }
552
-
553
- return [];
554
- }