datastake-daf 0.6.229 → 0.6.230
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/dist/components/index.js +466 -440
- package/dist/utils/index.js +441 -414
- package/package.json +1 -1
- package/src/@daf/core/components/Dashboard/Widget/ProjectWidget/ProjectWidget.stories.jsx +66 -85
- package/src/@daf/core/components/EditForm/components/DataLink/index.js +578 -631
- package/src/@daf/core/components/EditForm/storyConfig1.js +250 -69
- package/src/@daf/core/components/Icon/configs/Hedera01.js +16 -0
- package/src/@daf/core/components/Icon/configs/Records.js +15 -0
- package/src/@daf/core/components/Icon/configs/index.js +5 -1
- package/src/styles/components/_analysisView.scss +2 -31
- package/.env +0 -8
- package/.vscode/settings.json +0 -13
|
@@ -13,639 +13,586 @@ import { getLocales } from "../../../../../../helpers/Table";
|
|
|
13
13
|
import ModalHeader from "../../../Header/ModalHeader/index.jsx";
|
|
14
14
|
import { getToken } from "../../../../../../helpers/Token";
|
|
15
15
|
import DynamicForm from "../../../DynamicForm/index.jsx";
|
|
16
|
-
import { convertUndefinedToNull } from
|
|
16
|
+
import { convertUndefinedToNull } from '../../../../../utils/object';
|
|
17
17
|
|
|
18
|
-
const changeErrors = () => {};
|
|
18
|
+
const changeErrors = () => { };
|
|
19
19
|
|
|
20
20
|
export default function DataLink({
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
21
|
+
form = {},
|
|
22
|
+
values,
|
|
23
|
+
formsValue,
|
|
24
|
+
maxRepeat,
|
|
25
|
+
onUpdate = () => { },
|
|
26
|
+
remove,
|
|
27
|
+
name,
|
|
28
|
+
add,
|
|
29
|
+
flat,
|
|
30
|
+
k,
|
|
31
|
+
isHighlighted,
|
|
32
32
|
}) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
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
|
-
|
|
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
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
className="max-h-50"
|
|
599
|
-
destroyOnClose
|
|
600
|
-
onCancel={onCloseModal}
|
|
601
|
-
title={
|
|
602
|
-
<ModalHeader
|
|
603
|
-
title={getLabelFromScopeForDataLink(
|
|
604
|
-
form?.modalLabel || form?.label,
|
|
605
|
-
formScope,
|
|
606
|
-
)}
|
|
607
|
-
/>
|
|
608
|
-
}
|
|
609
|
-
>
|
|
610
|
-
<div className="repeatable-modal-form">
|
|
611
|
-
<DynamicForm
|
|
612
|
-
isModal
|
|
613
|
-
showSaveAndNext={false}
|
|
614
|
-
form={_form}
|
|
615
|
-
code={form?.meta?.code}
|
|
616
|
-
excludedKeys={[...(form?.meta?.excludedKeys || [])]}
|
|
617
|
-
data={{ ...(rowToEdit || addModalRow || {}) }}
|
|
618
|
-
disabledInputs={form?.meta?.disabledKeys || []}
|
|
619
|
-
onCancel={onCloseModal}
|
|
620
|
-
preSelected={preSelected}
|
|
621
|
-
changeErrors={changeErrors}
|
|
622
|
-
staticWidth="500px"
|
|
623
|
-
submit={(_payload) => {
|
|
624
|
-
const { form, ...payload } = _payload;
|
|
625
|
-
|
|
626
|
-
if (rowToEdit) {
|
|
627
|
-
const { key, ...rest } = payload;
|
|
628
|
-
onUpdate(rest, key);
|
|
629
|
-
onCloseModal();
|
|
630
|
-
} else {
|
|
631
|
-
add(convertUndefinedToNull(payload));
|
|
632
|
-
onCloseModal();
|
|
633
|
-
}
|
|
634
|
-
}}
|
|
635
|
-
{...{
|
|
636
|
-
t,
|
|
637
|
-
ajaxOptions,
|
|
638
|
-
user,
|
|
639
|
-
ajaxForms,
|
|
640
|
-
changeAjaxForms,
|
|
641
|
-
getApiBaseUrl,
|
|
642
|
-
getAppHeader,
|
|
643
|
-
app,
|
|
644
|
-
...rest,
|
|
645
|
-
}}
|
|
646
|
-
/>
|
|
647
|
-
</div>
|
|
648
|
-
</Modal>
|
|
649
|
-
</div>
|
|
650
|
-
);
|
|
33
|
+
const {
|
|
34
|
+
t,
|
|
35
|
+
ajaxOptions,
|
|
36
|
+
user,
|
|
37
|
+
ajaxForms,
|
|
38
|
+
changeAjaxForms,
|
|
39
|
+
getApiBaseUrl,
|
|
40
|
+
getAppHeader,
|
|
41
|
+
app,
|
|
42
|
+
...rest
|
|
43
|
+
} = useEditContext();
|
|
44
|
+
const [rowToEdit, setRowToEdit] = useState();
|
|
45
|
+
const [linkingData, setLinkingData] = useState({});
|
|
46
|
+
const [addModalRow, setAddModalRow] = useState(null);
|
|
47
|
+
const { automaticallyLink } = useMemo(() => form, [form]);
|
|
48
|
+
const entity = useMemo(() => automaticallyLink?.entity || form?.meta?.dataLinkEntity, [automaticallyLink, form]);
|
|
49
|
+
const isAjaxModal = useMemo(() => !!form?.meta?.namespace, [form]);
|
|
50
|
+
const isSingle = maxRepeat === 1;
|
|
51
|
+
const notAvailable = (values?.meta?.inputs || {})[k]?.notAvailable;
|
|
52
|
+
const notApplicable = (values?.meta?.inputs || {})[k]?.notApplicable;
|
|
53
|
+
|
|
54
|
+
// const formData = isSingle ? (values[name] ? [{ ...values[name] }] : []) : getArray(values[name] || []).map((v, i) => ({ ...v, key: i }));
|
|
55
|
+
|
|
56
|
+
const formData = isSingle
|
|
57
|
+
? Array.isArray(values[name])
|
|
58
|
+
? values[name].length === 0
|
|
59
|
+
? []
|
|
60
|
+
: [{ ...values[name] }]
|
|
61
|
+
: values[name] ? [{ ...values[name] }] : []
|
|
62
|
+
: getArray(values[name] || []).map((v, i) => ({ ...v, key: i }));
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
const noBody = notApplicable || notAvailable;
|
|
66
|
+
|
|
67
|
+
const tableKeys = useMemo(() => {
|
|
68
|
+
let val = form?.meta?.tableKeys;
|
|
69
|
+
let toReturn = val;
|
|
70
|
+
|
|
71
|
+
if (val && !Array.isArray(val)) {
|
|
72
|
+
if (typeof val === 'object') {
|
|
73
|
+
Object.keys(val).forEach((k) => {
|
|
74
|
+
const show = showHideInput(
|
|
75
|
+
{ showIf: k },
|
|
76
|
+
values,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
if (show) {
|
|
80
|
+
toReturn = val[k];
|
|
81
|
+
}
|
|
82
|
+
})
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return toReturn;
|
|
87
|
+
}, [form, values]);
|
|
88
|
+
|
|
89
|
+
const prefilledValues = useMemo(() => {
|
|
90
|
+
return Object.keys(form?.meta?.prefilledValues || {}).reduce((all, key) => {
|
|
91
|
+
const val = form.meta.prefilledValues[key];
|
|
92
|
+
|
|
93
|
+
if (typeof val === 'object') {
|
|
94
|
+
Object.keys(val).forEach((k) => {
|
|
95
|
+
const show = showHideInput(
|
|
96
|
+
{ showIf: k },
|
|
97
|
+
values,
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
if (show) {
|
|
101
|
+
all[key] = val[k];
|
|
102
|
+
}
|
|
103
|
+
})
|
|
104
|
+
} else {
|
|
105
|
+
all[key] = val;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
return all;
|
|
109
|
+
}, {});
|
|
110
|
+
}, [form, values]);
|
|
111
|
+
|
|
112
|
+
const formScope = useMemo(() => {
|
|
113
|
+
const val = form.meta.formScope;
|
|
114
|
+
let toReturn = val;
|
|
115
|
+
|
|
116
|
+
if (val) {
|
|
117
|
+
if (typeof val === 'object') {
|
|
118
|
+
Object.keys(val).forEach((k) => {
|
|
119
|
+
const show = showHideInput(
|
|
120
|
+
{ showIf: k },
|
|
121
|
+
values,
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
if (show) {
|
|
125
|
+
toReturn = val[k];
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return toReturn;
|
|
132
|
+
}, [form, values]);
|
|
133
|
+
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
if (values.linking && values.linking[entity]) {
|
|
136
|
+
setLinkingData(values.linking[entity]);
|
|
137
|
+
}
|
|
138
|
+
if (values?.parent?.linking && values?.parent?.linking[entity]) {
|
|
139
|
+
setLinkingData(values?.parent?.linking[entity]);
|
|
140
|
+
}
|
|
141
|
+
}, [entity, values.linking])
|
|
142
|
+
|
|
143
|
+
const ajaxModalValues = useAjaxModal({
|
|
144
|
+
name: k,
|
|
145
|
+
user,
|
|
146
|
+
namespace: form?.meta?.namespace,
|
|
147
|
+
skipFetch: form?.meta?.skipFetch,
|
|
148
|
+
isAjaxModal,
|
|
149
|
+
formScope,
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const data = (formData || []).map((f, i) => {
|
|
153
|
+
if (isAjaxModal && typeof f === 'string' && linkingData[f]) {
|
|
154
|
+
const value = linkingData[f];
|
|
155
|
+
return { ...value, key: i };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (form?.meta?.ajaxOptionsKey) {
|
|
159
|
+
if (linkingData[f[form?.meta?.ajaxOptionsKey]]) {
|
|
160
|
+
const value = linkingData[f[form?.meta?.ajaxOptionsKey]];
|
|
161
|
+
const resData = { ...f, ...value, key: i };
|
|
162
|
+
if (resData.id && !linkingData[resData.id]) {
|
|
163
|
+
setLinkingData({
|
|
164
|
+
...linkingData,
|
|
165
|
+
[resData.id]: resData,
|
|
166
|
+
})
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const options = ajaxOptions[form?.meta?.ajaxOptionsKey];
|
|
171
|
+
|
|
172
|
+
if (Array.isArray(options)) {
|
|
173
|
+
const value = options.find((v) => v.value === f[form?.meta?.ajaxOptionsKey])
|
|
174
|
+
if (value) {
|
|
175
|
+
const resData = { ...f, ...value, key: i };
|
|
176
|
+
if (resData.id && !linkingData[resData.id]) {
|
|
177
|
+
setLinkingData({
|
|
178
|
+
...linkingData,
|
|
179
|
+
[resData.id]: resData,
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
return resData;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const resData = { ...f, key: i };
|
|
188
|
+
if (resData.id && !linkingData[resData.id]) {
|
|
189
|
+
setLinkingData({
|
|
190
|
+
...linkingData,
|
|
191
|
+
[resData.id]: resData,
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
return resData;
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
const getDataSource = () => {
|
|
198
|
+
if (notApplicable || notAvailable) {
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (data.length > 3) {
|
|
203
|
+
return data;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const max = isSingle ? 1 : 3;
|
|
207
|
+
|
|
208
|
+
const emptyDataSource = [];
|
|
209
|
+
|
|
210
|
+
for (let i = 0; i < max; i++) {
|
|
211
|
+
emptyDataSource.push({ key: i, isEmpty: true });
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return data.length !== 0 ? emptyDataSource.map((empty, i) => data[i] || empty) : emptyDataSource;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
const dataSource = getDataSource();
|
|
218
|
+
|
|
219
|
+
const preSelected = data.map((d) => d.id).filter((d) => !!d).filter((d) => d !== rowToEdit?.id);
|
|
220
|
+
|
|
221
|
+
const onCloseModal = useCallback(() => {
|
|
222
|
+
setRowToEdit(null);
|
|
223
|
+
setAddModalRow(false);
|
|
224
|
+
}, []);
|
|
225
|
+
|
|
226
|
+
const inputs = useMemo(() =>
|
|
227
|
+
Object.values(ajaxModalValues.form)[0]
|
|
228
|
+
? Object.values(ajaxModalValues.form)[0]
|
|
229
|
+
: form?.inputs || {}
|
|
230
|
+
, [form, ajaxModalValues.form])
|
|
231
|
+
|
|
232
|
+
const mapKey = useCallback((val) => {
|
|
233
|
+
const key = Array.isArray(val.content) && val.content.length
|
|
234
|
+
? val.content[0].key
|
|
235
|
+
: val;
|
|
236
|
+
|
|
237
|
+
const input = (inputs[key] || {}).tableLabel || (inputs[key] || {});
|
|
238
|
+
const _input = (inputs[key] || {});
|
|
239
|
+
const title = typeof input === 'string'
|
|
240
|
+
? input
|
|
241
|
+
: getInputLabel((inputs[key] || {}).tableLabel || (inputs[key] || {}), values, true);
|
|
242
|
+
|
|
243
|
+
const getKey = (row) => {
|
|
244
|
+
if (Array.isArray(val.content) && val.content.length) {
|
|
245
|
+
for (let i = 0; i < val.content.length; i++) {
|
|
246
|
+
const config = val.content[i];
|
|
247
|
+
const show = showHideInput(config, row);
|
|
248
|
+
if (show) {
|
|
249
|
+
return config.key;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return key;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
title: <Tooltip title={title}>{title}</Tooltip>,
|
|
259
|
+
key: key,
|
|
260
|
+
dataIndex: key,
|
|
261
|
+
ellipsis: { showTitle: true },
|
|
262
|
+
render: (_, all) => {
|
|
263
|
+
if (all.isEmpty || ajaxModalValues.isFetching) {
|
|
264
|
+
return <div className="daf-default-cell" />;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const key = getKey(all);
|
|
268
|
+
const v = all[key] || all;
|
|
269
|
+
const type = inputs[key]?.type;
|
|
270
|
+
|
|
271
|
+
const render = (title) => {
|
|
272
|
+
if (tooltipInputs.includes(type)) {
|
|
273
|
+
return (
|
|
274
|
+
<Tooltip title={title}>
|
|
275
|
+
{title} {' '}
|
|
276
|
+
</Tooltip>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return title;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const inputMeta = (all?.meta?.inputs || {})[key] || {};
|
|
284
|
+
|
|
285
|
+
if (key === 'datastakeId' && (!all[key] || all[key] === 'new')) {
|
|
286
|
+
return '';
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
if (v || inputMeta?.notApplicable || inputMeta?.notAvailable || type === 'ajaxSelect') {
|
|
290
|
+
if (type === 'ajaxSelect') {
|
|
291
|
+
const data = all[key];
|
|
292
|
+
|
|
293
|
+
if (data === 'new') {
|
|
294
|
+
return render(
|
|
295
|
+
<BasicInput
|
|
296
|
+
name={key}
|
|
297
|
+
key={key}
|
|
298
|
+
isModal
|
|
299
|
+
config={{
|
|
300
|
+
...inputs[key],
|
|
301
|
+
type: 'text',
|
|
302
|
+
}}
|
|
303
|
+
valueOnlyString
|
|
304
|
+
data={{
|
|
305
|
+
...all,
|
|
306
|
+
[key]: (all?.meta?.inputs || {})[key]?.name || all[_input?.meta?.onNewSetValueKey],
|
|
307
|
+
scope: formScope,
|
|
308
|
+
}}
|
|
309
|
+
t={t}
|
|
310
|
+
ajaxForms={ajaxForms}
|
|
311
|
+
changeAjaxForms={changeAjaxForms}
|
|
312
|
+
getApiBaseUrl={getApiBaseUrl}
|
|
313
|
+
getAppHeader={getAppHeader}
|
|
314
|
+
user={user}
|
|
315
|
+
getToken={getToken}
|
|
316
|
+
app={app}
|
|
317
|
+
/>
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
const { meta } = inputs[key];
|
|
322
|
+
|
|
323
|
+
if (meta.onNewSetValueKey) {
|
|
324
|
+
if(!all[meta.onNewSetValueKey]) {
|
|
325
|
+
return render(
|
|
326
|
+
<BasicInput
|
|
327
|
+
t={t}
|
|
328
|
+
isModal
|
|
329
|
+
app={app}
|
|
330
|
+
ajaxForms={ajaxForms}
|
|
331
|
+
changeAjaxForms={changeAjaxForms}
|
|
332
|
+
getApiBaseUrl={getApiBaseUrl}
|
|
333
|
+
getAppHeader={getAppHeader}
|
|
334
|
+
user={user}
|
|
335
|
+
getToken={getToken}
|
|
336
|
+
name={key}
|
|
337
|
+
key={key}
|
|
338
|
+
config={{
|
|
339
|
+
...inputs[key],
|
|
340
|
+
type: 'ajaxSelect',
|
|
341
|
+
}}
|
|
342
|
+
valueOnlyString
|
|
343
|
+
data={{ ...all, scope: data?.scope }}
|
|
344
|
+
linkingData={all?.linking}
|
|
345
|
+
/>
|
|
346
|
+
)
|
|
347
|
+
}
|
|
348
|
+
return render(
|
|
349
|
+
<BasicInput
|
|
350
|
+
isModal
|
|
351
|
+
name={key}
|
|
352
|
+
key={key}
|
|
353
|
+
config={{
|
|
354
|
+
...inputs[key],
|
|
355
|
+
type: 'text',
|
|
356
|
+
}}
|
|
357
|
+
t={t}
|
|
358
|
+
ajaxForms={ajaxForms}
|
|
359
|
+
changeAjaxForms={changeAjaxForms}
|
|
360
|
+
getApiBaseUrl={getApiBaseUrl}
|
|
361
|
+
getAppHeader={getAppHeader}
|
|
362
|
+
user={user}
|
|
363
|
+
getToken={getToken}
|
|
364
|
+
app={app}
|
|
365
|
+
valueOnlyString
|
|
366
|
+
data={{ ...all, [key]: all[meta.onNewSetValueKey], scope: formScope, }}
|
|
367
|
+
/>
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
return render(
|
|
373
|
+
<BasicInput
|
|
374
|
+
isModal
|
|
375
|
+
name={key}
|
|
376
|
+
key={key}
|
|
377
|
+
t={t}
|
|
378
|
+
ajaxForms={ajaxForms}
|
|
379
|
+
changeAjaxForms={changeAjaxForms}
|
|
380
|
+
getApiBaseUrl={getApiBaseUrl}
|
|
381
|
+
getAppHeader={getAppHeader}
|
|
382
|
+
user={user}
|
|
383
|
+
getToken={getToken}
|
|
384
|
+
app={app}
|
|
385
|
+
config={inputs[key]}
|
|
386
|
+
valueOnlyString
|
|
387
|
+
data={{ ...all, scope: formScope, }}
|
|
388
|
+
/>
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
if ((inputs[key] || {}).noValue) {
|
|
393
|
+
return render(inputs[key] || {}).noValue[user?.language]
|
|
394
|
+
}
|
|
395
|
+
},
|
|
396
|
+
}
|
|
397
|
+
}, [inputs, ajaxModalValues, formScope]);
|
|
398
|
+
|
|
399
|
+
const onEditClick = useCallback((all) => {
|
|
400
|
+
if (form?.meta?.ajaxOptionsKey) {
|
|
401
|
+
const _all = Object.keys(all)
|
|
402
|
+
.reduce((val, key) => {
|
|
403
|
+
val[key] = all[key];
|
|
404
|
+
return val;
|
|
405
|
+
}, {});
|
|
406
|
+
|
|
407
|
+
setRowToEdit(form?.meta?.linkingKey ? {
|
|
408
|
+
..._all,
|
|
409
|
+
key: all.key,
|
|
410
|
+
meta: all.meta,
|
|
411
|
+
scope: formScope,
|
|
412
|
+
[form?.meta?.ajaxOptionsKey]: all.id || all.value || all[form?.meta?.ajaxOptionsKey],
|
|
413
|
+
[form?.meta?.linkingKey]: all._id || all.id || all.value || all[form?.meta?.ajaxOptionsKey] || all[form?.meta?.linkingKey],
|
|
414
|
+
} : {
|
|
415
|
+
..._all,
|
|
416
|
+
scope: formScope,
|
|
417
|
+
key: all.key,
|
|
418
|
+
meta: all.meta,
|
|
419
|
+
[form?.meta?.ajaxOptionsKey]: all.id || all.value || all[form?.meta?.ajaxOptionsKey],
|
|
420
|
+
})
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
setRowToEdit({ ...all, scope: formScope, })
|
|
425
|
+
}, [form, formScope]);
|
|
426
|
+
|
|
427
|
+
const canAdd = (maxRepeat ? formData.length < maxRepeat : true) && !noBody;
|
|
428
|
+
|
|
429
|
+
const columns = [
|
|
430
|
+
...(Array.isArray(tableKeys) ? tableKeys.map(mapKey) : Object.keys(inputs || {}).map(mapKey)),
|
|
431
|
+
{
|
|
432
|
+
key: 'actions',
|
|
433
|
+
dataIndex: 'actions',
|
|
434
|
+
title: (
|
|
435
|
+
<Button
|
|
436
|
+
size="small"
|
|
437
|
+
className="add-btn"
|
|
438
|
+
disabled={!canAdd || (isAjaxModal ? ajaxModalValues?.isFetching : false)}
|
|
439
|
+
onClick={() => {
|
|
440
|
+
const _values = (form?.meta?.subjectPrefilledValuesKeys || []).reduce((all, key) => {
|
|
441
|
+
if (values[key]) {
|
|
442
|
+
all[key] = values[key];
|
|
443
|
+
}
|
|
444
|
+
return all;
|
|
445
|
+
}, {});
|
|
446
|
+
|
|
447
|
+
const _prefilled = {};
|
|
448
|
+
|
|
449
|
+
Object.keys(_form?.inputs || {}).forEach((key) => {
|
|
450
|
+
if (_form?.inputs?.[key]?.meta?.defaultValue) {
|
|
451
|
+
_prefilled[key] = _form?.inputs?.[key]?.meta?.defaultValue;
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
setAddModalRow({ ...(_values || {}), ...(prefilledValues || {}), ..._prefilled, scope: formScope, });
|
|
456
|
+
}}
|
|
457
|
+
>
|
|
458
|
+
<CustomIcon name="Add" width={16} height={16} />
|
|
459
|
+
</Button>
|
|
460
|
+
),
|
|
461
|
+
width: 70,
|
|
462
|
+
render: (_, all) => {
|
|
463
|
+
if (all.isEmpty || ajaxModalValues.isFetching) {
|
|
464
|
+
return <div className="daf-default-cell" />;
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const items = [];
|
|
468
|
+
|
|
469
|
+
const canEdit = form?.meta?.allowedActions?.edit === false
|
|
470
|
+
? false
|
|
471
|
+
: form?.meta?.allowedActions?.edit || (isSingle && formData.length === 1);
|
|
472
|
+
|
|
473
|
+
if (canEdit) {
|
|
474
|
+
items.push({
|
|
475
|
+
label: t('Edit'),
|
|
476
|
+
key: "edit",
|
|
477
|
+
onClick: () => onEditClick(all),
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (form?.meta?.allowedActions?.remove) {
|
|
482
|
+
items.push({
|
|
483
|
+
label: t('Delete'),
|
|
484
|
+
key: "remove",
|
|
485
|
+
onClick: () => {
|
|
486
|
+
Modal.confirm({
|
|
487
|
+
title: t('Delete information'),
|
|
488
|
+
content: t('Are you sure you want to delete this information?'),
|
|
489
|
+
okText: t('Yes'),
|
|
490
|
+
cancelText: t('Cancel'),
|
|
491
|
+
onOk: () => {
|
|
492
|
+
remove(all);
|
|
493
|
+
},
|
|
494
|
+
})
|
|
495
|
+
},
|
|
496
|
+
});
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
if (items.length) {
|
|
500
|
+
return (
|
|
501
|
+
<MoreMenu items={items} />
|
|
502
|
+
)
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return null;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
];
|
|
509
|
+
|
|
510
|
+
const unsortedForm = { inputs };
|
|
511
|
+
|
|
512
|
+
const _form = Object.keys(unsortedForm).reduce((all, key) => {
|
|
513
|
+
const _this = Object.keys(unsortedForm[key])
|
|
514
|
+
.sort((a, b) => unsortedForm[key][a].position - unsortedForm[key][b].position)
|
|
515
|
+
.reduce((all, k) => {
|
|
516
|
+
if (k === 'scope') {
|
|
517
|
+
return all;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
all[k] = unsortedForm[key][k];
|
|
521
|
+
return all;
|
|
522
|
+
}, {});
|
|
523
|
+
|
|
524
|
+
all[key] = _this;
|
|
525
|
+
return all;
|
|
526
|
+
}, {});
|
|
527
|
+
|
|
528
|
+
|
|
529
|
+
return (
|
|
530
|
+
<div className={formatClassname(['data-link-cont mt-2', noBody && 'no-body', isHighlighted && 'highlighted'])} style={form?.meta?.style}>
|
|
531
|
+
<div className="daf-table-wrapper no-padding repeatable-form-table no-pagination">
|
|
532
|
+
<ConfigProvider renderEmpty={() => notApplicable ? t('Not applicable') : t('No information available')}>
|
|
533
|
+
<Table
|
|
534
|
+
locale={getLocales(t)}
|
|
535
|
+
loading={ajaxModalValues.isFetching}
|
|
536
|
+
pagination={false}
|
|
537
|
+
columns={columns}
|
|
538
|
+
dataSource={dataSource}
|
|
539
|
+
rowKey="key"
|
|
540
|
+
scroll={noBody ? undefined : { y: 170 }}
|
|
541
|
+
/>
|
|
542
|
+
</ConfigProvider>
|
|
543
|
+
</div>
|
|
544
|
+
|
|
545
|
+
<Modal
|
|
546
|
+
open={!!addModalRow || !!rowToEdit}
|
|
547
|
+
footer={null}
|
|
548
|
+
width={650}
|
|
549
|
+
className="max-h-50"
|
|
550
|
+
destroyOnClose
|
|
551
|
+
onCancel={onCloseModal}
|
|
552
|
+
title={(
|
|
553
|
+
<ModalHeader title={getLabelFromScopeForDataLink(form?.modalLabel || form?.label, formScope)} />
|
|
554
|
+
)}
|
|
555
|
+
>
|
|
556
|
+
<div className="repeatable-modal-form">
|
|
557
|
+
<DynamicForm
|
|
558
|
+
isModal
|
|
559
|
+
showSaveAndNext={false}
|
|
560
|
+
form={_form}
|
|
561
|
+
code={form?.meta?.code}
|
|
562
|
+
excludedKeys={[...(form?.meta?.excludedKeys || [])]}
|
|
563
|
+
data={{ ...(rowToEdit || addModalRow || {}) }}
|
|
564
|
+
disabledInputs={form?.meta?.disabledKeys || []}
|
|
565
|
+
onCancel={onCloseModal}
|
|
566
|
+
preSelected={preSelected}
|
|
567
|
+
changeErrors={changeErrors}
|
|
568
|
+
staticWidth = '500px'
|
|
569
|
+
submit={(_payload) => {
|
|
570
|
+
const { form, ...payload } = _payload;
|
|
571
|
+
|
|
572
|
+
if (rowToEdit) {
|
|
573
|
+
const { key, ...rest } = payload;
|
|
574
|
+
onUpdate(rest, key);
|
|
575
|
+
onCloseModal();
|
|
576
|
+
} else {
|
|
577
|
+
add(convertUndefinedToNull(payload));
|
|
578
|
+
onCloseModal();
|
|
579
|
+
}
|
|
580
|
+
}}
|
|
581
|
+
{...({
|
|
582
|
+
t,
|
|
583
|
+
ajaxOptions,
|
|
584
|
+
user,
|
|
585
|
+
ajaxForms,
|
|
586
|
+
changeAjaxForms,
|
|
587
|
+
getApiBaseUrl,
|
|
588
|
+
getAppHeader,
|
|
589
|
+
app,
|
|
590
|
+
...rest
|
|
591
|
+
})}
|
|
592
|
+
/>
|
|
593
|
+
</div>
|
|
594
|
+
|
|
595
|
+
</Modal>
|
|
596
|
+
</div>
|
|
597
|
+
)
|
|
651
598
|
}
|