@hed-hog/catalog 0.0.278 → 0.0.285
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/README.md +118 -8
- package/hedhog/frontend/app/[resource]/page.tsx.ejs +648 -684
- package/hedhog/frontend/app/_components/catalog-resource-form-sheet.tsx.ejs +964 -0
- package/hedhog/frontend/app/_lib/catalog-resources.tsx.ejs +1154 -569
- package/hedhog/frontend/app/dashboard/page.tsx.ejs +562 -566
- package/hedhog/frontend/app/page.tsx.ejs +5 -5
- package/hedhog/frontend/messages/en.json +296 -293
- package/hedhog/frontend/messages/pt.json +296 -293
- package/package.json +7 -7
- package/hedhog/frontend/app/_components/catalog-nav.tsx.ejs +0 -85
|
@@ -1,684 +1,648 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from '../
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
import { Button } from '@/components/ui/button';
|
|
30
|
-
import {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
} from '
|
|
45
|
-
import {
|
|
46
|
-
import {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
resource
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
const
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
?
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
.map((
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
};
|
|
361
|
-
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
toast.
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
:
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
</p>
|
|
650
|
-
</div>
|
|
651
|
-
<DialogFooter>
|
|
652
|
-
<Button variant="outline" onClick={() => setDialogOpen(false)}>
|
|
653
|
-
{t('cancel')}
|
|
654
|
-
</Button>
|
|
655
|
-
<Button onClick={submit} disabled={isSubmitting}>
|
|
656
|
-
{t('save')}
|
|
657
|
-
</Button>
|
|
658
|
-
</DialogFooter>
|
|
659
|
-
</DialogContent>
|
|
660
|
-
</Dialog>
|
|
661
|
-
|
|
662
|
-
<AlertDialog
|
|
663
|
-
open={deleteId !== null}
|
|
664
|
-
onOpenChange={(open) => !open && setDeleteId(null)}
|
|
665
|
-
>
|
|
666
|
-
<AlertDialogContent>
|
|
667
|
-
<AlertDialogHeader>
|
|
668
|
-
<AlertDialogTitle>{t('confirmDelete')}</AlertDialogTitle>
|
|
669
|
-
<AlertDialogDescription>
|
|
670
|
-
{t('confirmDeleteDescription')}
|
|
671
|
-
</AlertDialogDescription>
|
|
672
|
-
</AlertDialogHeader>
|
|
673
|
-
<AlertDialogFooter>
|
|
674
|
-
<AlertDialogCancel>{t('cancel')}</AlertDialogCancel>
|
|
675
|
-
<AlertDialogAction onClick={handleDelete}>
|
|
676
|
-
{t('delete')}
|
|
677
|
-
</AlertDialogAction>
|
|
678
|
-
</AlertDialogFooter>
|
|
679
|
-
</AlertDialogContent>
|
|
680
|
-
</AlertDialog>
|
|
681
|
-
</div>
|
|
682
|
-
</Page>
|
|
683
|
-
);
|
|
684
|
-
}
|
|
1
|
+
'use client';
|
|
2
|
+
import {
|
|
3
|
+
catalogResourceMap,
|
|
4
|
+
type CatalogFieldDefinition,
|
|
5
|
+
type CatalogFilterOptionDefinition,
|
|
6
|
+
getCatalogLocalizedText,
|
|
7
|
+
getCatalogRecordLabel,
|
|
8
|
+
} from '../_lib/catalog-resources';
|
|
9
|
+
import { CatalogResourceFormSheet } from '../_components/catalog-resource-form-sheet';
|
|
10
|
+
import {
|
|
11
|
+
EmptyState,
|
|
12
|
+
EntityCard,
|
|
13
|
+
Page,
|
|
14
|
+
PageHeader,
|
|
15
|
+
PaginationFooter,
|
|
16
|
+
SearchBar,
|
|
17
|
+
StatsCards,
|
|
18
|
+
} from '@/components/entity-list';
|
|
19
|
+
import {
|
|
20
|
+
AlertDialog,
|
|
21
|
+
AlertDialogAction,
|
|
22
|
+
AlertDialogCancel,
|
|
23
|
+
AlertDialogContent,
|
|
24
|
+
AlertDialogDescription,
|
|
25
|
+
AlertDialogFooter,
|
|
26
|
+
AlertDialogHeader,
|
|
27
|
+
AlertDialogTitle,
|
|
28
|
+
} from '@/components/ui/alert-dialog';
|
|
29
|
+
import { Button } from '@/components/ui/button';
|
|
30
|
+
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
|
31
|
+
import {
|
|
32
|
+
Table,
|
|
33
|
+
TableBody,
|
|
34
|
+
TableCell,
|
|
35
|
+
TableHead,
|
|
36
|
+
TableHeader,
|
|
37
|
+
TableRow,
|
|
38
|
+
} from '@/components/ui/table';
|
|
39
|
+
import { useDebounce } from '@/hooks/use-debounce';
|
|
40
|
+
import { useApp, useQuery } from '@hed-hog/next-app-provider';
|
|
41
|
+
import { Eye, Pencil, Plus, Search, Trash2 } from 'lucide-react';
|
|
42
|
+
import Link from 'next/link';
|
|
43
|
+
import { useParams } from 'next/navigation';
|
|
44
|
+
import { useTranslations } from 'next-intl';
|
|
45
|
+
import { useMemo, useState } from 'react';
|
|
46
|
+
import { toast } from 'sonner';
|
|
47
|
+
|
|
48
|
+
type PaginationResult<T> = {
|
|
49
|
+
data: T[];
|
|
50
|
+
total: number;
|
|
51
|
+
page: number;
|
|
52
|
+
pageSize: number;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type ResourceStats = {
|
|
56
|
+
total: number;
|
|
57
|
+
active?: number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type CatalogRecord = Record<string, unknown>;
|
|
61
|
+
|
|
62
|
+
function humanizeValue(value: string) {
|
|
63
|
+
return value
|
|
64
|
+
.replace(/[_-]+/g, ' ')
|
|
65
|
+
.replace(/\b\w/g, (char) => char.toUpperCase());
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export default function CatalogResourcePage() {
|
|
69
|
+
const params = useParams<{ resource: string }>();
|
|
70
|
+
const resource = params?.resource ?? '';
|
|
71
|
+
const config = catalogResourceMap.get(resource);
|
|
72
|
+
const t = useTranslations('catalog');
|
|
73
|
+
const { accessToken, request, currentLocaleCode } = useApp();
|
|
74
|
+
const [search, setSearch] = useState('');
|
|
75
|
+
const debouncedSearch = useDebounce(search, 400);
|
|
76
|
+
const [filterValue, setFilterValue] = useState('all');
|
|
77
|
+
const [page, setPage] = useState(1);
|
|
78
|
+
const [pageSize, setPageSize] = useState(12);
|
|
79
|
+
const [sheetOpen, setSheetOpen] = useState(false);
|
|
80
|
+
const [deleteId, setDeleteId] = useState<number | null>(null);
|
|
81
|
+
const [editingRecordId, setEditingRecordId] = useState<number | null>(null);
|
|
82
|
+
const resourceTitle = config
|
|
83
|
+
? t(`resources.${config.translationKey}.title`)
|
|
84
|
+
: t('unsupportedResource');
|
|
85
|
+
const resourceDescription = config
|
|
86
|
+
? t(`resources.${config.translationKey}.description`)
|
|
87
|
+
: t('resource.unsupportedDescription');
|
|
88
|
+
const ResourceIcon = config?.icon;
|
|
89
|
+
|
|
90
|
+
const currencyFormatter = useMemo(
|
|
91
|
+
() =>
|
|
92
|
+
new Intl.NumberFormat(currentLocaleCode === 'pt' ? 'pt-BR' : 'en-US', {
|
|
93
|
+
style: 'currency',
|
|
94
|
+
currency: 'BRL',
|
|
95
|
+
maximumFractionDigits: 0,
|
|
96
|
+
}),
|
|
97
|
+
[currentLocaleCode]
|
|
98
|
+
);
|
|
99
|
+
const isAppReady = accessToken.trim().length > 0;
|
|
100
|
+
const translatableValueFields = useMemo(
|
|
101
|
+
() =>
|
|
102
|
+
new Set([
|
|
103
|
+
'status',
|
|
104
|
+
'comparison_status',
|
|
105
|
+
'availability_status',
|
|
106
|
+
'site_type',
|
|
107
|
+
'merchant_type',
|
|
108
|
+
'network_type',
|
|
109
|
+
'commission_type',
|
|
110
|
+
'page_type',
|
|
111
|
+
'canonical_strategy',
|
|
112
|
+
'source_type',
|
|
113
|
+
'data_type',
|
|
114
|
+
'comparison_mode',
|
|
115
|
+
'facet_mode',
|
|
116
|
+
]),
|
|
117
|
+
[]
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const { data: stats } = useQuery<ResourceStats>({
|
|
121
|
+
queryKey: [
|
|
122
|
+
'catalog-resource-stats',
|
|
123
|
+
resource,
|
|
124
|
+
accessToken,
|
|
125
|
+
currentLocaleCode,
|
|
126
|
+
],
|
|
127
|
+
queryFn: async () => {
|
|
128
|
+
if (!resource || !config) {
|
|
129
|
+
return { total: 0 };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const response = await request({
|
|
133
|
+
url: `/catalog/${resource}/stats`,
|
|
134
|
+
});
|
|
135
|
+
const statsData = response.data as {
|
|
136
|
+
total?: number;
|
|
137
|
+
active?: number;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
total: Number(statsData.total ?? 0),
|
|
142
|
+
active:
|
|
143
|
+
statsData.active !== undefined ? Number(statsData.active) : undefined,
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
enabled: Boolean(resource && config && isAppReady),
|
|
147
|
+
});
|
|
148
|
+
const resourceStats = (stats ?? { total: 0 }) as ResourceStats;
|
|
149
|
+
|
|
150
|
+
const { data, refetch } = useQuery<PaginationResult<CatalogRecord>>({
|
|
151
|
+
queryKey: [
|
|
152
|
+
'catalog-resource',
|
|
153
|
+
resource,
|
|
154
|
+
accessToken,
|
|
155
|
+
currentLocaleCode,
|
|
156
|
+
debouncedSearch,
|
|
157
|
+
filterValue,
|
|
158
|
+
page,
|
|
159
|
+
pageSize,
|
|
160
|
+
],
|
|
161
|
+
queryFn: async () => {
|
|
162
|
+
if (!resource || !config) {
|
|
163
|
+
return { data: [], total: 0, page: 1, pageSize };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const params: Record<string, string | number> = {
|
|
167
|
+
page,
|
|
168
|
+
pageSize,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
if (debouncedSearch.trim()) {
|
|
172
|
+
params.search = debouncedSearch.trim();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
if (filterValue !== 'all') {
|
|
176
|
+
params[config.primaryFilterField] = filterValue;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const response = await request({
|
|
180
|
+
url: `/catalog/${resource}`,
|
|
181
|
+
params,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const responseData = response.data as Partial<
|
|
185
|
+
PaginationResult<CatalogRecord>
|
|
186
|
+
>;
|
|
187
|
+
|
|
188
|
+
return {
|
|
189
|
+
data: responseData.data ?? [],
|
|
190
|
+
total: Number(responseData.total ?? 0),
|
|
191
|
+
page: Number(responseData.page ?? page),
|
|
192
|
+
pageSize: Number(responseData.pageSize ?? pageSize),
|
|
193
|
+
};
|
|
194
|
+
},
|
|
195
|
+
enabled: Boolean(resource && config && isAppReady),
|
|
196
|
+
});
|
|
197
|
+
const resourceData = (data ?? {
|
|
198
|
+
data: [],
|
|
199
|
+
total: 0,
|
|
200
|
+
page: 1,
|
|
201
|
+
pageSize: 12,
|
|
202
|
+
}) as PaginationResult<CatalogRecord>;
|
|
203
|
+
|
|
204
|
+
const safeTranslate = (key: string, fallback: string) => {
|
|
205
|
+
const translated = t(key);
|
|
206
|
+
|
|
207
|
+
if (translated === key) {
|
|
208
|
+
return fallback;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return translated;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const resolveDynamicValueLabel = (fieldKey: string, value: string) => {
|
|
215
|
+
if (!translatableValueFields.has(fieldKey)) {
|
|
216
|
+
return value;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return safeTranslate(
|
|
220
|
+
`resource.valueLabels.${fieldKey}.${value}`,
|
|
221
|
+
humanizeValue(value)
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
const getFirstValue = (record: CatalogRecord, keys: string[]) => {
|
|
226
|
+
for (const key of keys) {
|
|
227
|
+
const value = record[key];
|
|
228
|
+
|
|
229
|
+
if (
|
|
230
|
+
value !== undefined &&
|
|
231
|
+
value !== null &&
|
|
232
|
+
String(value).trim() !== ''
|
|
233
|
+
) {
|
|
234
|
+
return value;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
return undefined;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
const formatFieldValue = (
|
|
242
|
+
value: unknown,
|
|
243
|
+
field?: CatalogFieldDefinition | { key: string; type?: string }
|
|
244
|
+
) => {
|
|
245
|
+
if (value === undefined || value === null || value === '') {
|
|
246
|
+
return '-';
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (field?.type === 'boolean') {
|
|
250
|
+
return value === true
|
|
251
|
+
? t('resource.booleans.true')
|
|
252
|
+
: t('resource.booleans.false');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
if (field?.type === 'currency' && typeof value === 'number') {
|
|
256
|
+
return currencyFormatter.format(value);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
if (typeof value === 'string') {
|
|
260
|
+
return field?.key ? resolveDynamicValueLabel(field.key, value) : value;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return String(value);
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const getCardDescription = (record: CatalogRecord) =>
|
|
267
|
+
config
|
|
268
|
+
? config.descriptionFields
|
|
269
|
+
.map((key) => record[key])
|
|
270
|
+
.filter(
|
|
271
|
+
(value): value is string | number =>
|
|
272
|
+
value !== undefined &&
|
|
273
|
+
value !== null &&
|
|
274
|
+
String(value).trim() !== ''
|
|
275
|
+
)
|
|
276
|
+
.slice(0, 2)
|
|
277
|
+
.map((value, index) =>
|
|
278
|
+
formatFieldValue(value, {
|
|
279
|
+
key: config.descriptionFields[index] ?? '',
|
|
280
|
+
})
|
|
281
|
+
)
|
|
282
|
+
.join(' • ')
|
|
283
|
+
: '';
|
|
284
|
+
|
|
285
|
+
const getBadges = (record: CatalogRecord) =>
|
|
286
|
+
config
|
|
287
|
+
? config.badgeFields
|
|
288
|
+
.map((key) => {
|
|
289
|
+
const value = record[key];
|
|
290
|
+
|
|
291
|
+
if (value === undefined || value === null || value === '') {
|
|
292
|
+
return null;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
return {
|
|
296
|
+
label: formatFieldValue(value, { key }),
|
|
297
|
+
variant:
|
|
298
|
+
value === true || value === 'active' || value === 'published'
|
|
299
|
+
? ('default' as const)
|
|
300
|
+
: ('secondary' as const),
|
|
301
|
+
};
|
|
302
|
+
})
|
|
303
|
+
.filter((badge): badge is NonNullable<typeof badge> => badge !== null)
|
|
304
|
+
: [];
|
|
305
|
+
|
|
306
|
+
const getCardMetadata = (record: CatalogRecord) =>
|
|
307
|
+
config
|
|
308
|
+
? config.cardMetadata
|
|
309
|
+
.map((field) => {
|
|
310
|
+
const rawValue = record[field.key];
|
|
311
|
+
|
|
312
|
+
if (
|
|
313
|
+
rawValue === undefined ||
|
|
314
|
+
rawValue === null ||
|
|
315
|
+
rawValue === ''
|
|
316
|
+
) {
|
|
317
|
+
return null;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return {
|
|
321
|
+
label: t(`resource.fields.${field.labelKey}`),
|
|
322
|
+
value: formatFieldValue(rawValue, field),
|
|
323
|
+
};
|
|
324
|
+
})
|
|
325
|
+
.filter((item): item is NonNullable<typeof item> => item !== null)
|
|
326
|
+
: [];
|
|
327
|
+
|
|
328
|
+
if (!config) {
|
|
329
|
+
return (
|
|
330
|
+
<Page>
|
|
331
|
+
<PageHeader
|
|
332
|
+
title={t('unsupportedResource')}
|
|
333
|
+
description={t('resource.unsupportedDescription')}
|
|
334
|
+
breadcrumbs={[
|
|
335
|
+
{ label: t('breadcrumbs.home'), href: '/' },
|
|
336
|
+
{ label: t('breadcrumbs.catalog'), href: '/catalog/dashboard' },
|
|
337
|
+
{ label: t('resource.notFound') },
|
|
338
|
+
]}
|
|
339
|
+
/>
|
|
340
|
+
<Card>
|
|
341
|
+
<CardHeader>
|
|
342
|
+
<CardTitle>{t('unsupportedResource')}</CardTitle>
|
|
343
|
+
<CardDescription>
|
|
344
|
+
{t('resource.unsupportedDescription')}
|
|
345
|
+
</CardDescription>
|
|
346
|
+
</CardHeader>
|
|
347
|
+
<CardContent>
|
|
348
|
+
<Button asChild variant="outline">
|
|
349
|
+
<Link href="/catalog/dashboard">{t('backToCatalog')}</Link>
|
|
350
|
+
</Button>
|
|
351
|
+
</CardContent>
|
|
352
|
+
</Card>
|
|
353
|
+
</Page>
|
|
354
|
+
);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
const openCreate = () => {
|
|
358
|
+
setEditingRecordId(null);
|
|
359
|
+
setSheetOpen(true);
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
const openEdit = (record: CatalogRecord) => {
|
|
363
|
+
setEditingRecordId(Number(record.id));
|
|
364
|
+
setSheetOpen(true);
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const handleDelete = async () => {
|
|
368
|
+
if (!deleteId) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
try {
|
|
373
|
+
await request({
|
|
374
|
+
url: `/catalog/${resource}/${deleteId}`,
|
|
375
|
+
method: 'DELETE',
|
|
376
|
+
});
|
|
377
|
+
toast.success(t('toasts.deleteSuccess'));
|
|
378
|
+
setDeleteId(null);
|
|
379
|
+
await refetch();
|
|
380
|
+
} catch (error) {
|
|
381
|
+
toast.error(
|
|
382
|
+
error instanceof Error ? error.message : t('toasts.deleteError')
|
|
383
|
+
);
|
|
384
|
+
}
|
|
385
|
+
};
|
|
386
|
+
|
|
387
|
+
const filterOptions = [
|
|
388
|
+
{
|
|
389
|
+
label: t('resource.filters.all'),
|
|
390
|
+
value: 'all',
|
|
391
|
+
},
|
|
392
|
+
...config.primaryFilterOptions.map(
|
|
393
|
+
(option: CatalogFilterOptionDefinition) => ({
|
|
394
|
+
label: t(
|
|
395
|
+
`resource.filterOptions.${config.primaryFilterField}.${option.labelKey}`
|
|
396
|
+
),
|
|
397
|
+
value: option.value,
|
|
398
|
+
})
|
|
399
|
+
),
|
|
400
|
+
];
|
|
401
|
+
|
|
402
|
+
const contextualCount = config.contextualKpi.count(resourceData.data);
|
|
403
|
+
|
|
404
|
+
const statsCards = [
|
|
405
|
+
{
|
|
406
|
+
title: t('resource.kpis.total'),
|
|
407
|
+
value: resourceStats.total,
|
|
408
|
+
icon: ResourceIcon ? (
|
|
409
|
+
<ResourceIcon className="size-5" />
|
|
410
|
+
) : (
|
|
411
|
+
<Search className="size-5" />
|
|
412
|
+
),
|
|
413
|
+
iconBgColor: 'bg-orange-50',
|
|
414
|
+
iconColor: 'text-orange-600',
|
|
415
|
+
},
|
|
416
|
+
{
|
|
417
|
+
title:
|
|
418
|
+
typeof resourceStats.active === 'number'
|
|
419
|
+
? t('resource.kpis.active')
|
|
420
|
+
: t('resource.kpis.visible'),
|
|
421
|
+
value:
|
|
422
|
+
typeof resourceStats.active === 'number'
|
|
423
|
+
? resourceStats.active
|
|
424
|
+
: resourceData.data.length,
|
|
425
|
+
icon: <Eye className="size-5" />,
|
|
426
|
+
iconBgColor: 'bg-blue-50',
|
|
427
|
+
iconColor: 'text-blue-600',
|
|
428
|
+
},
|
|
429
|
+
{
|
|
430
|
+
title: t(`resource.kpis.${config.contextualKpi.translationKey}`),
|
|
431
|
+
value: contextualCount,
|
|
432
|
+
icon: <config.contextualKpi.icon className="size-5" />,
|
|
433
|
+
iconBgColor: 'bg-emerald-50',
|
|
434
|
+
iconColor: 'text-emerald-600',
|
|
435
|
+
},
|
|
436
|
+
];
|
|
437
|
+
|
|
438
|
+
return (
|
|
439
|
+
<Page>
|
|
440
|
+
<PageHeader
|
|
441
|
+
title={resourceTitle}
|
|
442
|
+
description={resourceDescription}
|
|
443
|
+
breadcrumbs={[
|
|
444
|
+
{ label: t('breadcrumbs.home'), href: '/' },
|
|
445
|
+
{ label: t('breadcrumbs.catalog'), href: '/catalog/dashboard' },
|
|
446
|
+
{ label: resourceTitle },
|
|
447
|
+
]}
|
|
448
|
+
actions={[
|
|
449
|
+
{
|
|
450
|
+
label: getCatalogLocalizedText(
|
|
451
|
+
config.createActionLabel,
|
|
452
|
+
currentLocaleCode
|
|
453
|
+
),
|
|
454
|
+
onClick: () => {
|
|
455
|
+
openCreate();
|
|
456
|
+
},
|
|
457
|
+
icon: <Plus className="size-4" />,
|
|
458
|
+
},
|
|
459
|
+
]}
|
|
460
|
+
/>
|
|
461
|
+
|
|
462
|
+
<div className="min-w-0 space-y-4 overflow-x-hidden">
|
|
463
|
+
<StatsCards stats={statsCards} className="sm:grid-cols-3" />
|
|
464
|
+
|
|
465
|
+
<div className="min-w-0 space-y-4">
|
|
466
|
+
<SearchBar
|
|
467
|
+
searchQuery={search}
|
|
468
|
+
onSearchChange={(value) => {
|
|
469
|
+
setSearch(value);
|
|
470
|
+
setPage(1);
|
|
471
|
+
}}
|
|
472
|
+
onSearch={() => {
|
|
473
|
+
setPage(1);
|
|
474
|
+
void refetch();
|
|
475
|
+
}}
|
|
476
|
+
placeholder={t('searchPlaceholder')}
|
|
477
|
+
className="min-w-0"
|
|
478
|
+
filters={{
|
|
479
|
+
value: filterValue,
|
|
480
|
+
options: filterOptions,
|
|
481
|
+
onChange: (value) => {
|
|
482
|
+
setFilterValue(value);
|
|
483
|
+
setPage(1);
|
|
484
|
+
},
|
|
485
|
+
placeholder: t(`resource.filters.${config.primaryFilterField}`),
|
|
486
|
+
}}
|
|
487
|
+
/>
|
|
488
|
+
|
|
489
|
+
{resourceData.data.length === 0 ? (
|
|
490
|
+
<EmptyState
|
|
491
|
+
icon={
|
|
492
|
+
ResourceIcon ? (
|
|
493
|
+
<ResourceIcon className="h-12 w-12" />
|
|
494
|
+
) : (
|
|
495
|
+
<Search className="h-12 w-12" />
|
|
496
|
+
)
|
|
497
|
+
}
|
|
498
|
+
title={t('resource.emptyStateTitle')}
|
|
499
|
+
description={t('resource.emptyStateDescription')}
|
|
500
|
+
actionLabel={t('resource.emptyStateAction')}
|
|
501
|
+
actionIcon={<Plus className="mr-2 size-4" />}
|
|
502
|
+
onAction={openCreate}
|
|
503
|
+
/>
|
|
504
|
+
) : config.listVariant === 'table' ? (
|
|
505
|
+
<div className="min-w-0 space-y-4">
|
|
506
|
+
<div className="overflow-x-auto rounded-md border">
|
|
507
|
+
<Table>
|
|
508
|
+
<TableHeader>
|
|
509
|
+
<TableRow>
|
|
510
|
+
{config.tableColumns?.map((column) => (
|
|
511
|
+
<TableHead key={column.key}>
|
|
512
|
+
{t(`resource.fields.${column.labelKey}`)}
|
|
513
|
+
</TableHead>
|
|
514
|
+
))}
|
|
515
|
+
<TableHead className="w-[110px] text-right">
|
|
516
|
+
{t('resource.fields.actions')}
|
|
517
|
+
</TableHead>
|
|
518
|
+
</TableRow>
|
|
519
|
+
</TableHeader>
|
|
520
|
+
<TableBody>
|
|
521
|
+
{resourceData.data.map((record) => (
|
|
522
|
+
<TableRow key={String(record.id)}>
|
|
523
|
+
{config.tableColumns?.map((column) => (
|
|
524
|
+
<TableCell key={`${record.id}-${column.key}`}>
|
|
525
|
+
{formatFieldValue(record[column.key], column)}
|
|
526
|
+
</TableCell>
|
|
527
|
+
))}
|
|
528
|
+
<TableCell className="text-right">
|
|
529
|
+
<div className="flex justify-end gap-2">
|
|
530
|
+
<Button
|
|
531
|
+
variant="outline"
|
|
532
|
+
size="icon"
|
|
533
|
+
onClick={() => openEdit(record)}
|
|
534
|
+
>
|
|
535
|
+
<Pencil className="size-4" />
|
|
536
|
+
</Button>
|
|
537
|
+
<Button
|
|
538
|
+
variant="destructive"
|
|
539
|
+
size="icon"
|
|
540
|
+
onClick={() => setDeleteId(Number(record.id))}
|
|
541
|
+
>
|
|
542
|
+
<Trash2 className="size-4" />
|
|
543
|
+
</Button>
|
|
544
|
+
</div>
|
|
545
|
+
</TableCell>
|
|
546
|
+
</TableRow>
|
|
547
|
+
))}
|
|
548
|
+
</TableBody>
|
|
549
|
+
</Table>
|
|
550
|
+
</div>
|
|
551
|
+
|
|
552
|
+
<PaginationFooter
|
|
553
|
+
currentPage={page}
|
|
554
|
+
pageSize={pageSize}
|
|
555
|
+
totalItems={resourceData.total}
|
|
556
|
+
onPageChange={setPage}
|
|
557
|
+
onPageSizeChange={(nextPageSize) => {
|
|
558
|
+
setPageSize(nextPageSize);
|
|
559
|
+
setPage(1);
|
|
560
|
+
}}
|
|
561
|
+
/>
|
|
562
|
+
</div>
|
|
563
|
+
) : (
|
|
564
|
+
<div className="min-w-0 space-y-4">
|
|
565
|
+
<div className="grid min-w-0 gap-4 md:grid-cols-2 2xl:grid-cols-3">
|
|
566
|
+
{resourceData.data.map((record) => (
|
|
567
|
+
<EntityCard
|
|
568
|
+
key={String(record.id)}
|
|
569
|
+
title={String(
|
|
570
|
+
getFirstValue(record, config.titleFields) ??
|
|
571
|
+
getCatalogRecordLabel(record)
|
|
572
|
+
)}
|
|
573
|
+
description={getCardDescription(record)}
|
|
574
|
+
badges={getBadges(record)}
|
|
575
|
+
metadata={getCardMetadata(record)}
|
|
576
|
+
actions={[
|
|
577
|
+
{
|
|
578
|
+
label: t('edit'),
|
|
579
|
+
onClick: () => openEdit(record),
|
|
580
|
+
variant: 'outline',
|
|
581
|
+
icon: <Pencil className="size-4" />,
|
|
582
|
+
},
|
|
583
|
+
{
|
|
584
|
+
label: t('delete'),
|
|
585
|
+
onClick: () => setDeleteId(Number(record.id)),
|
|
586
|
+
variant: 'destructive',
|
|
587
|
+
icon: <Trash2 className="size-4" />,
|
|
588
|
+
},
|
|
589
|
+
]}
|
|
590
|
+
/>
|
|
591
|
+
))}
|
|
592
|
+
</div>
|
|
593
|
+
|
|
594
|
+
<PaginationFooter
|
|
595
|
+
currentPage={page}
|
|
596
|
+
pageSize={pageSize}
|
|
597
|
+
totalItems={resourceData.total}
|
|
598
|
+
onPageChange={setPage}
|
|
599
|
+
onPageSizeChange={(nextPageSize) => {
|
|
600
|
+
setPageSize(nextPageSize);
|
|
601
|
+
setPage(1);
|
|
602
|
+
}}
|
|
603
|
+
/>
|
|
604
|
+
</div>
|
|
605
|
+
)}
|
|
606
|
+
</div>
|
|
607
|
+
<CatalogResourceFormSheet
|
|
608
|
+
open={sheetOpen}
|
|
609
|
+
onOpenChange={(open) => {
|
|
610
|
+
setSheetOpen(open);
|
|
611
|
+
if (!open) {
|
|
612
|
+
setEditingRecordId(null);
|
|
613
|
+
}
|
|
614
|
+
}}
|
|
615
|
+
resource={resource}
|
|
616
|
+
resourceConfig={config}
|
|
617
|
+
resourceTitle={resourceTitle}
|
|
618
|
+
resourceDescription={resourceDescription}
|
|
619
|
+
recordId={editingRecordId}
|
|
620
|
+
onSuccess={async () => {
|
|
621
|
+
setEditingRecordId(null);
|
|
622
|
+
await refetch();
|
|
623
|
+
}}
|
|
624
|
+
/>
|
|
625
|
+
|
|
626
|
+
<AlertDialog
|
|
627
|
+
open={deleteId !== null}
|
|
628
|
+
onOpenChange={(open) => !open && setDeleteId(null)}
|
|
629
|
+
>
|
|
630
|
+
<AlertDialogContent>
|
|
631
|
+
<AlertDialogHeader>
|
|
632
|
+
<AlertDialogTitle>{t('confirmDelete')}</AlertDialogTitle>
|
|
633
|
+
<AlertDialogDescription>
|
|
634
|
+
{t('confirmDeleteDescription')}
|
|
635
|
+
</AlertDialogDescription>
|
|
636
|
+
</AlertDialogHeader>
|
|
637
|
+
<AlertDialogFooter>
|
|
638
|
+
<AlertDialogCancel>{t('cancel')}</AlertDialogCancel>
|
|
639
|
+
<AlertDialogAction onClick={handleDelete}>
|
|
640
|
+
{t('delete')}
|
|
641
|
+
</AlertDialogAction>
|
|
642
|
+
</AlertDialogFooter>
|
|
643
|
+
</AlertDialogContent>
|
|
644
|
+
</AlertDialog>
|
|
645
|
+
</div>
|
|
646
|
+
</Page>
|
|
647
|
+
);
|
|
648
|
+
}
|