slice-machine-ui 2.16.2-beta.9 → 2.17.1-alpha.jp-cr-ui-nested-ct-remove-section.1

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.
Files changed (67) hide show
  1. package/out/404.html +1 -1
  2. package/out/_next/static/0SPBnBOIdcPusg2ceVdAq/_buildManifest.js +1 -0
  3. package/out/_next/static/chunks/248-03446cd9e9f13730.js +1 -0
  4. package/out/_next/static/chunks/268-6a9214b97195af9c.js +1 -0
  5. package/out/_next/static/chunks/33641354.3864aefb6106ae71.js +28 -0
  6. package/out/_next/static/chunks/34-e684c5fd75cc9dd0.js +1 -0
  7. package/out/_next/static/chunks/630-4a8f19a6a113700f.js +1 -0
  8. package/out/_next/static/chunks/647-7b9b5aa9468f9e4b.js +1 -0
  9. package/out/_next/static/chunks/882-151468121d542ed6.js +1 -0
  10. package/out/_next/static/chunks/pages/_app-15912b10c760cd68.js +708 -0
  11. package/out/_next/static/chunks/pages/changelog-063c5e11dfc8fd55.js +1 -0
  12. package/out/_next/static/chunks/pages/changes-564336edb0ed18b0.js +1 -0
  13. package/out/_next/static/chunks/pages/custom-types/{[customTypeId]-389d1b7a492fb3e7.js → [customTypeId]-a408f5a660e096a6.js} +1 -1
  14. package/out/_next/static/chunks/pages/{custom-types-2a5fd94ee42ba593.js → custom-types-5acd56959b60346f.js} +1 -1
  15. package/out/_next/static/chunks/pages/{index-02dd147957c8b40f.js → index-0d8cb369de720a35.js} +1 -1
  16. package/out/_next/static/chunks/pages/labs-9630bfb1005be02b.js +1 -0
  17. package/out/_next/static/chunks/pages/page-types/{[pageTypeId]-3589bd1f9138a97b.js → [pageTypeId]-f5e851ebe35049a8.js} +1 -1
  18. package/out/_next/static/chunks/pages/settings-01f4aeb9112a1f87.js +1 -0
  19. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-5008e29008aa04f4.js +1 -0
  20. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-bd5e45632c419567.js +1 -0
  21. package/out/_next/static/chunks/pages/slices-4a60cd5f2c71327e.js +1 -0
  22. package/out/_next/static/chunks/webpack-b3522fdebabf510a.js +1 -0
  23. package/out/_next/static/css/cc9b10286400c2b9.css +1 -0
  24. package/out/changelog.html +1 -1
  25. package/out/changes.html +1 -1
  26. package/out/custom-types/[customTypeId].html +1 -1
  27. package/out/custom-types.html +1 -1
  28. package/out/index.html +1 -1
  29. package/out/labs.html +1 -1
  30. package/out/page-types/[pageTypeId].html +1 -1
  31. package/out/settings.html +1 -1
  32. package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
  33. package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
  34. package/out/slices.html +1 -1
  35. package/package.json +8 -8
  36. package/src/features/builder/fields/contentRelationship/ContentRelationshipFieldPicker.tsx +1498 -0
  37. package/src/features/builder/fields/contentRelationship/Hint.tsx +28 -0
  38. package/src/features/builder/fields/contentRelationship/__tests__/ContentRelationshipFieldPicker.test.ts +1323 -0
  39. package/src/features/customTypes/customTypesTable/CustomTypesTable.tsx +2 -4
  40. package/src/features/customTypes/customTypesTable/{useCustomTypes.ts → useCustomTypesAutoRevalidation.tsx} +1 -34
  41. package/src/features/customTypes/useCustomTypes.ts +48 -0
  42. package/src/legacy/lib/builders/common/Zone/Card/components/Hints/index.tsx +12 -1
  43. package/src/legacy/lib/models/common/widgets/ContentRelationship/Form.tsx +35 -77
  44. package/src/legacy/lib/models/common/widgets/ContentRelationship/index.ts +46 -15
  45. package/src/legacy/lib/models/common/widgets/Link/index.ts +1 -1
  46. package/src/utils/isValidObject.ts +32 -0
  47. package/src/utils/tracking/getLinkTrackingProperties.ts +28 -0
  48. package/src/utils/tracking/trackFieldAdded.ts +2 -5
  49. package/src/utils/tracking/trackFieldUpdated.ts +2 -5
  50. package/out/_next/static/atP3j_itxjBtvIysQoCxK/_buildManifest.js +0 -1
  51. package/out/_next/static/chunks/268-6d5fc7642a1b87c8.js +0 -1
  52. package/out/_next/static/chunks/34-2911c905c8a6e9d9.js +0 -1
  53. package/out/_next/static/chunks/630-93339694ef30b82d.js +0 -1
  54. package/out/_next/static/chunks/867-8164160c810122c6.js +0 -1
  55. package/out/_next/static/chunks/882-28837678beff7e51.js +0 -1
  56. package/out/_next/static/chunks/895-8c214ba470a4e23c.js +0 -1
  57. package/out/_next/static/chunks/pages/_app-2400eb8f7c5ef3cb.js +0 -657
  58. package/out/_next/static/chunks/pages/changelog-80a618708f44f25f.js +0 -1
  59. package/out/_next/static/chunks/pages/changes-d40c17939854b984.js +0 -1
  60. package/out/_next/static/chunks/pages/labs-c6df252ea5d8fb6f.js +0 -1
  61. package/out/_next/static/chunks/pages/settings-170379902605f38a.js +0 -1
  62. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]/simulator-063fa88ba75f483e.js +0 -1
  63. package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/[variation]-6de02b8ed13b680d.js +0 -1
  64. package/out/_next/static/chunks/pages/slices-071bb494907adf0f.js +0 -1
  65. package/out/_next/static/chunks/webpack-2f903acb0cccbf9e.js +0 -1
  66. package/out/_next/static/css/9c9a7de81f9ac811.css +0 -1
  67. /package/out/_next/static/{atP3j_itxjBtvIysQoCxK → 0SPBnBOIdcPusg2ceVdAq}/_ssgManifest.js +0 -0
@@ -0,0 +1,1323 @@
1
+ import { CustomType } from "@prismicio/types-internal/lib/customtypes";
2
+ import { describe, expect, it } from "vitest";
3
+
4
+ import {
5
+ convertLinkCustomtypesToFieldCheckMap,
6
+ countPickedFields,
7
+ } from "../ContentRelationshipFieldPicker";
8
+
9
+ describe("ContentRelationshipFieldPicker", () => {
10
+ describe("countPickedFields", () => {
11
+ const allCustomTypes: CustomType[] = [
12
+ {
13
+ id: "ct1",
14
+ label: "CT 1",
15
+ repeatable: false,
16
+ status: true,
17
+ json: {
18
+ Main: {
19
+ f1: {
20
+ type: "Link",
21
+ config: {
22
+ select: "document",
23
+ customtypes: ["ct2"],
24
+ },
25
+ },
26
+ f2: {
27
+ type: "Link",
28
+ config: {
29
+ select: "document",
30
+ customtypes: ["ct2"],
31
+ },
32
+ },
33
+ g1: {
34
+ type: "Group",
35
+ config: {
36
+ fields: {
37
+ f1: {
38
+ type: "Boolean",
39
+ },
40
+ f2: {
41
+ type: "Link",
42
+ config: {
43
+ select: "document",
44
+ customtypes: ["ct2"],
45
+ },
46
+ },
47
+ },
48
+ },
49
+ },
50
+ },
51
+ },
52
+ },
53
+ {
54
+ id: "ct2",
55
+ label: "CT 2",
56
+ repeatable: false,
57
+ status: true,
58
+ json: {
59
+ Main: {
60
+ f1: {
61
+ type: "Boolean",
62
+ },
63
+ g2: {
64
+ type: "Group",
65
+ config: {
66
+ fields: {
67
+ f1: {
68
+ type: "Boolean",
69
+ },
70
+ f2: {
71
+ type: "Boolean",
72
+ },
73
+ },
74
+ },
75
+ },
76
+ },
77
+ },
78
+ },
79
+ ];
80
+
81
+ it("should count picked fields with a custom type as string", () => {
82
+ const customtypes = ["ct1"];
83
+
84
+ const result = countPickedFields(
85
+ convertLinkCustomtypesToFieldCheckMap({
86
+ linkCustomtypes: customtypes,
87
+ allCustomTypes,
88
+ }),
89
+ );
90
+
91
+ expect(result).toEqual({
92
+ pickedFields: 0,
93
+ nestedPickedFields: 0,
94
+ });
95
+ });
96
+
97
+ it("should count picked fields with multiple custom types as string", () => {
98
+ const customtypes = ["ct1", "ct2"];
99
+
100
+ const result = countPickedFields(
101
+ convertLinkCustomtypesToFieldCheckMap({
102
+ linkCustomtypes: customtypes,
103
+ allCustomTypes,
104
+ }),
105
+ );
106
+
107
+ expect(result).toEqual({
108
+ pickedFields: 0,
109
+ nestedPickedFields: 0,
110
+ });
111
+ });
112
+
113
+ it("should count picked fields with custom type as object and one field", () => {
114
+ const customtypes = [
115
+ {
116
+ id: "ct1",
117
+ fields: ["f1"],
118
+ },
119
+ ];
120
+
121
+ const result = countPickedFields(
122
+ convertLinkCustomtypesToFieldCheckMap({
123
+ linkCustomtypes: customtypes,
124
+ allCustomTypes,
125
+ }),
126
+ );
127
+
128
+ expect(result).toEqual({
129
+ pickedFields: 1,
130
+ nestedPickedFields: 0,
131
+ });
132
+ });
133
+
134
+ it("should count picked fields with custom type as object and one nested field", () => {
135
+ const customtypes = [
136
+ {
137
+ id: "ct1",
138
+ fields: [
139
+ {
140
+ id: "f1",
141
+ customtypes: [
142
+ {
143
+ id: "ct2",
144
+ fields: ["f1"],
145
+ },
146
+ ],
147
+ },
148
+ ],
149
+ },
150
+ ];
151
+
152
+ const result = countPickedFields(
153
+ convertLinkCustomtypesToFieldCheckMap({
154
+ linkCustomtypes: customtypes,
155
+ allCustomTypes,
156
+ }),
157
+ );
158
+
159
+ expect(result).toEqual({
160
+ pickedFields: 1,
161
+ nestedPickedFields: 1,
162
+ });
163
+ });
164
+
165
+ it("should count picked fields with custom type as object with group field", () => {
166
+ const customtypes = [
167
+ {
168
+ id: "ct1",
169
+ fields: [
170
+ {
171
+ id: "g1",
172
+ fields: ["f1", "f2"],
173
+ },
174
+ ],
175
+ },
176
+ ];
177
+
178
+ const test = convertLinkCustomtypesToFieldCheckMap({
179
+ linkCustomtypes: customtypes,
180
+ allCustomTypes,
181
+ });
182
+ const result = countPickedFields(test);
183
+
184
+ expect(result).toEqual({
185
+ pickedFields: 2,
186
+ nestedPickedFields: 0,
187
+ });
188
+ });
189
+
190
+ it("should count picked fields with custom type as object with group field and nested custom type", () => {
191
+ const customtypes = [
192
+ {
193
+ id: "ct1",
194
+ fields: [
195
+ {
196
+ id: "g1",
197
+ fields: [
198
+ "f1",
199
+ {
200
+ id: "f2",
201
+ customtypes: [
202
+ {
203
+ id: "ct2",
204
+ fields: ["f1"],
205
+ },
206
+ ],
207
+ },
208
+ ],
209
+ },
210
+ ],
211
+ },
212
+ ];
213
+
214
+ const result = countPickedFields(
215
+ convertLinkCustomtypesToFieldCheckMap({
216
+ linkCustomtypes: customtypes,
217
+ allCustomTypes,
218
+ }),
219
+ );
220
+
221
+ expect(result).toEqual({
222
+ pickedFields: 2,
223
+ nestedPickedFields: 1,
224
+ });
225
+ });
226
+
227
+ it("should count picked fields with custom type as object with group field, nested custom type and nested group field", () => {
228
+ const customtypes = [
229
+ {
230
+ id: "ct1",
231
+ fields: [
232
+ {
233
+ id: "g1",
234
+ fields: [
235
+ "f1",
236
+ {
237
+ id: "f2",
238
+ customtypes: [
239
+ {
240
+ id: "ct2",
241
+ fields: [
242
+ "f1",
243
+ {
244
+ id: "g2",
245
+ fields: ["f1", "f2"],
246
+ },
247
+ ],
248
+ },
249
+ ],
250
+ },
251
+ ],
252
+ },
253
+ ],
254
+ },
255
+ ];
256
+
257
+ const result = countPickedFields(
258
+ convertLinkCustomtypesToFieldCheckMap({
259
+ linkCustomtypes: customtypes,
260
+ allCustomTypes,
261
+ }),
262
+ );
263
+
264
+ expect(result).toEqual({
265
+ pickedFields: 4,
266
+ nestedPickedFields: 3,
267
+ });
268
+ });
269
+
270
+ it("should count picked fields with custom type as object with nested custom type and nested group field", () => {
271
+ const customtypes = [
272
+ {
273
+ id: "ct1",
274
+ fields: [
275
+ "f1",
276
+ {
277
+ id: "f2",
278
+ customtypes: [
279
+ {
280
+ id: "ct2",
281
+ fields: [
282
+ "f1",
283
+ {
284
+ id: "g2",
285
+ fields: ["f1", "f2"],
286
+ },
287
+ ],
288
+ },
289
+ ],
290
+ },
291
+ ],
292
+ },
293
+ ];
294
+
295
+ const result = countPickedFields(
296
+ convertLinkCustomtypesToFieldCheckMap({
297
+ linkCustomtypes: customtypes,
298
+ allCustomTypes,
299
+ }),
300
+ );
301
+
302
+ expect(result).toEqual({
303
+ pickedFields: 4,
304
+ nestedPickedFields: 3,
305
+ });
306
+ });
307
+
308
+ it("should count picked fields with custom type as object with nested custom type without fields", () => {
309
+ const customtypes = [
310
+ {
311
+ id: "ct1",
312
+ fields: [
313
+ "f1",
314
+ {
315
+ id: "f2",
316
+ customtypes: [
317
+ {
318
+ id: "ct2",
319
+ fields: [],
320
+ },
321
+ ],
322
+ },
323
+ ],
324
+ },
325
+ ];
326
+
327
+ const result = countPickedFields(
328
+ convertLinkCustomtypesToFieldCheckMap({
329
+ linkCustomtypes: customtypes,
330
+ allCustomTypes,
331
+ }),
332
+ );
333
+
334
+ expect(result).toEqual({
335
+ pickedFields: 1,
336
+ nestedPickedFields: 0,
337
+ });
338
+ });
339
+
340
+ it("should count picked fields with custom type as object with group field without fields", () => {
341
+ const customtypes = [
342
+ {
343
+ id: "ct1",
344
+ fields: [
345
+ "f1",
346
+ {
347
+ id: "g1",
348
+ fields: [],
349
+ },
350
+ ],
351
+ },
352
+ ];
353
+
354
+ const result = countPickedFields(
355
+ convertLinkCustomtypesToFieldCheckMap({
356
+ linkCustomtypes: customtypes,
357
+ allCustomTypes,
358
+ }),
359
+ );
360
+
361
+ expect(result).toEqual({
362
+ pickedFields: 1,
363
+ nestedPickedFields: 0,
364
+ });
365
+ });
366
+ });
367
+
368
+ describe("createContentRelationshipFieldCheckMap", () => {
369
+ it("should include existing/valid referenced regular root fields", () => {
370
+ const customType: CustomType = {
371
+ id: "customType",
372
+ label: "Custom Type",
373
+ repeatable: false,
374
+ status: true,
375
+ json: {
376
+ Main: {
377
+ textField: {
378
+ type: "Text",
379
+ },
380
+ booleanField: {
381
+ type: "Boolean",
382
+ },
383
+ structuredTextField: {
384
+ type: "StructuredText",
385
+ },
386
+ imageField: {
387
+ type: "Image",
388
+ },
389
+ linkField: {
390
+ type: "Link",
391
+ },
392
+ colorField: {
393
+ type: "Color",
394
+ },
395
+ dateField: {
396
+ type: "Date",
397
+ },
398
+ geoPointField: {
399
+ type: "GeoPoint",
400
+ },
401
+ numberField: {
402
+ type: "Number",
403
+ },
404
+ rangeField: {
405
+ type: "Range",
406
+ },
407
+ selectField: {
408
+ type: "Select",
409
+ },
410
+ timestampField: {
411
+ type: "Timestamp",
412
+ },
413
+ separatorField: {
414
+ type: "Separator",
415
+ },
416
+ tableField: {
417
+ type: "Table",
418
+ },
419
+ integrationFieldsField: {
420
+ type: "IntegrationFields",
421
+ },
422
+ },
423
+ },
424
+ };
425
+
426
+ const result = convertLinkCustomtypesToFieldCheckMap({
427
+ linkCustomtypes: [
428
+ {
429
+ id: "customType",
430
+ fields: [
431
+ "textField",
432
+ "booleanField",
433
+ "structuredTextField",
434
+ "imageField",
435
+ "linkField",
436
+ "colorField",
437
+ "dateField",
438
+ "geoPointField",
439
+ "numberField",
440
+ "rangeField",
441
+ "selectField",
442
+ "timestampField",
443
+ "separatorField",
444
+ "tableField",
445
+ "integrationFieldsField",
446
+ ],
447
+ },
448
+ ],
449
+ allCustomTypes: [customType],
450
+ });
451
+
452
+ expect(result).toEqual({
453
+ customType: {
454
+ textField: {
455
+ type: "checkbox",
456
+ value: true,
457
+ },
458
+ booleanField: {
459
+ type: "checkbox",
460
+ value: true,
461
+ },
462
+ structuredTextField: {
463
+ type: "checkbox",
464
+ value: true,
465
+ },
466
+ imageField: {
467
+ type: "checkbox",
468
+ value: true,
469
+ },
470
+ linkField: {
471
+ type: "checkbox",
472
+ value: true,
473
+ },
474
+ colorField: {
475
+ type: "checkbox",
476
+ value: true,
477
+ },
478
+ dateField: {
479
+ type: "checkbox",
480
+ value: true,
481
+ },
482
+ geoPointField: {
483
+ type: "checkbox",
484
+ value: true,
485
+ },
486
+ numberField: {
487
+ type: "checkbox",
488
+ value: true,
489
+ },
490
+ rangeField: {
491
+ type: "checkbox",
492
+ value: true,
493
+ },
494
+ selectField: {
495
+ type: "checkbox",
496
+ value: true,
497
+ },
498
+ timestampField: {
499
+ type: "checkbox",
500
+ value: true,
501
+ },
502
+ separatorField: {
503
+ type: "checkbox",
504
+ value: true,
505
+ },
506
+ tableField: {
507
+ type: "checkbox",
508
+ value: true,
509
+ },
510
+ integrationFieldsField: {
511
+ type: "checkbox",
512
+ value: true,
513
+ },
514
+ },
515
+ });
516
+ });
517
+
518
+ it("should include a correctly referenced group field", () => {
519
+ const customType: CustomType = {
520
+ id: "customType",
521
+ label: "Custom Type",
522
+ repeatable: false,
523
+ status: true,
524
+ json: {
525
+ Main: {
526
+ groupField: {
527
+ type: "Group",
528
+ config: {
529
+ label: "Group Field",
530
+ fields: {
531
+ booleanField: {
532
+ type: "Boolean",
533
+ config: {
534
+ label: "Boolean Field",
535
+ },
536
+ },
537
+ },
538
+ },
539
+ },
540
+ },
541
+ },
542
+ };
543
+
544
+ const result = convertLinkCustomtypesToFieldCheckMap({
545
+ linkCustomtypes: [
546
+ {
547
+ id: "customType",
548
+ fields: [
549
+ {
550
+ id: "groupField",
551
+ fields: ["booleanField"],
552
+ },
553
+ ],
554
+ },
555
+ ],
556
+ allCustomTypes: [customType],
557
+ });
558
+
559
+ expect(result).toEqual({
560
+ customType: {
561
+ groupField: {
562
+ type: "group",
563
+ value: {
564
+ booleanField: {
565
+ type: "checkbox",
566
+ value: true,
567
+ },
568
+ },
569
+ },
570
+ },
571
+ });
572
+ });
573
+
574
+ it("should include a correctly referenced content relationship field", () => {
575
+ const customType: CustomType = {
576
+ id: "customType",
577
+ label: "Custom Type",
578
+ repeatable: false,
579
+ status: true,
580
+ json: {
581
+ Main: {
582
+ booleanField: {
583
+ type: "Boolean",
584
+ },
585
+ },
586
+ },
587
+ };
588
+ const customTypeWithContentRelationship: CustomType = {
589
+ id: "customTypeWithContentRelationship",
590
+ label: "Custom Type With Content Relationship",
591
+ repeatable: false,
592
+ status: true,
593
+ json: {
594
+ Main: {
595
+ contentRelationshipField: {
596
+ type: "Link",
597
+ config: {
598
+ select: "document",
599
+ customtypes: ["customType"],
600
+ },
601
+ },
602
+ },
603
+ },
604
+ };
605
+
606
+ const result = convertLinkCustomtypesToFieldCheckMap({
607
+ linkCustomtypes: [
608
+ {
609
+ id: "customTypeWithContentRelationship",
610
+ fields: [
611
+ {
612
+ id: "contentRelationshipField",
613
+ customtypes: [
614
+ {
615
+ id: "customType",
616
+ fields: ["booleanField"],
617
+ },
618
+ ],
619
+ },
620
+ ],
621
+ },
622
+ ],
623
+ allCustomTypes: [customType, customTypeWithContentRelationship],
624
+ });
625
+
626
+ expect(result).toEqual({
627
+ customTypeWithContentRelationship: {
628
+ contentRelationshipField: {
629
+ type: "contentRelationship",
630
+ value: {
631
+ customType: {
632
+ booleanField: {
633
+ type: "checkbox",
634
+ value: true,
635
+ },
636
+ },
637
+ },
638
+ },
639
+ },
640
+ });
641
+ });
642
+
643
+ it("should include a field correctly referenced as a group inside a nested custom type", () => {
644
+ const customType: CustomType = {
645
+ id: "customType",
646
+ label: "Custom Type",
647
+ repeatable: false,
648
+ status: true,
649
+ json: {
650
+ Main: {
651
+ groupField: {
652
+ type: "Group",
653
+ config: {
654
+ label: "Group Field",
655
+ fields: {
656
+ booleanField: {
657
+ type: "Boolean",
658
+ config: {
659
+ label: "Boolean Field",
660
+ },
661
+ },
662
+ },
663
+ },
664
+ },
665
+ },
666
+ },
667
+ };
668
+
669
+ const customTypeWithContentRelationship: CustomType = {
670
+ id: "customTypeWithContentRelationship",
671
+ label: "Custom Type With Content Relationship",
672
+ repeatable: false,
673
+ status: true,
674
+ json: {
675
+ Main: {
676
+ contentRelationshipField: {
677
+ type: "Link",
678
+ config: {
679
+ select: "document",
680
+ customtypes: ["customType"],
681
+ },
682
+ },
683
+ },
684
+ },
685
+ };
686
+
687
+ const result = convertLinkCustomtypesToFieldCheckMap({
688
+ linkCustomtypes: [
689
+ {
690
+ id: "customTypeWithContentRelationship",
691
+ fields: [
692
+ {
693
+ id: "contentRelationshipField",
694
+ customtypes: [
695
+ {
696
+ id: "customType",
697
+ fields: [
698
+ {
699
+ id: "groupField",
700
+ fields: ["booleanField"],
701
+ },
702
+ ],
703
+ },
704
+ ],
705
+ },
706
+ ],
707
+ },
708
+ ],
709
+ allCustomTypes: [customType, customTypeWithContentRelationship],
710
+ });
711
+
712
+ expect(result).toEqual({
713
+ customTypeWithContentRelationship: {
714
+ contentRelationshipField: {
715
+ type: "contentRelationship",
716
+ value: {
717
+ customType: {
718
+ groupField: {
719
+ type: "group",
720
+ value: {
721
+ booleanField: {
722
+ type: "checkbox",
723
+ value: true,
724
+ },
725
+ },
726
+ },
727
+ },
728
+ },
729
+ },
730
+ },
731
+ });
732
+ });
733
+
734
+ it("should discard non-existing/invalid referenced fields", () => {
735
+ const customType2: CustomType = {
736
+ id: "customType2",
737
+ label: "Custom Type 2",
738
+ repeatable: false,
739
+ status: true,
740
+ json: {
741
+ Main: {
742
+ booleanField: {
743
+ type: "Boolean",
744
+ },
745
+ },
746
+ },
747
+ };
748
+
749
+ const customType: CustomType = {
750
+ id: "customType",
751
+ label: "Custom Type",
752
+ repeatable: false,
753
+ status: true,
754
+ json: {
755
+ Main: {
756
+ mdField: {
757
+ type: "StructuredText",
758
+ },
759
+ crField: {
760
+ type: "Link",
761
+ config: {
762
+ select: "document",
763
+ customtypes: ["customType2"],
764
+ },
765
+ },
766
+ groupField: {
767
+ type: "Group",
768
+ config: {
769
+ fields: {
770
+ groupFieldA: {
771
+ type: "Boolean",
772
+ },
773
+ },
774
+ },
775
+ },
776
+ },
777
+ },
778
+ };
779
+
780
+ const result = convertLinkCustomtypesToFieldCheckMap({
781
+ linkCustomtypes: [
782
+ {
783
+ id: "customType",
784
+ fields: [
785
+ "mdField",
786
+ "nonExistingField",
787
+ {
788
+ id: "nonExistingGroup",
789
+ fields: ["groupFieldA"],
790
+ },
791
+ {
792
+ id: "crField",
793
+ customtypes: [
794
+ {
795
+ id: "customType2",
796
+ fields: ["nonExistingNestedField"],
797
+ },
798
+ ],
799
+ },
800
+ {
801
+ id: "groupField",
802
+ fields: ["nonExistingGroupField"],
803
+ },
804
+ ],
805
+ },
806
+ ],
807
+ allCustomTypes: [customType, customType2],
808
+ });
809
+
810
+ expect(result).toEqual({
811
+ customType: {
812
+ mdField: {
813
+ type: "checkbox",
814
+ value: true,
815
+ },
816
+ },
817
+ });
818
+ });
819
+
820
+ it("should discard invalid fields (uid, slices & choice)", () => {
821
+ const customType: CustomType = {
822
+ id: "customType",
823
+ label: "Custom Type",
824
+ repeatable: false,
825
+ status: true,
826
+ json: {
827
+ Main: {
828
+ booleanField: {
829
+ type: "Boolean",
830
+ },
831
+ typeUid: {
832
+ type: "UID",
833
+ },
834
+ uid: {
835
+ type: "Boolean",
836
+ },
837
+ choice: {
838
+ type: "Choice",
839
+ config: {
840
+ choices: {
841
+ choice1: {
842
+ type: "Boolean",
843
+ },
844
+ },
845
+ },
846
+ },
847
+ slices: {
848
+ type: "Slices",
849
+ config: {
850
+ choices: {
851
+ slice1: {
852
+ type: "SharedSlice",
853
+ },
854
+ },
855
+ },
856
+ },
857
+ },
858
+ },
859
+ };
860
+
861
+ const result = convertLinkCustomtypesToFieldCheckMap({
862
+ linkCustomtypes: [
863
+ {
864
+ id: "customType",
865
+ fields: ["booleanField", "typeUid", "uid", "choice", "slices"],
866
+ },
867
+ ],
868
+ allCustomTypes: [customType],
869
+ });
870
+
871
+ expect(result).toEqual({
872
+ customType: {
873
+ booleanField: {
874
+ type: "checkbox",
875
+ value: true,
876
+ },
877
+ },
878
+ });
879
+ });
880
+
881
+ it("should discard a regular field referenced as a group field", () => {
882
+ const customType: CustomType = {
883
+ id: "customType",
884
+ label: "Custom Type",
885
+ repeatable: false,
886
+ status: true,
887
+ json: {
888
+ Main: {
889
+ booleanField: {
890
+ type: "Boolean",
891
+ },
892
+ },
893
+ },
894
+ };
895
+
896
+ const result = convertLinkCustomtypesToFieldCheckMap({
897
+ linkCustomtypes: [
898
+ {
899
+ id: "customType",
900
+ fields: [
901
+ {
902
+ id: "booleanField",
903
+ fields: ["something"],
904
+ },
905
+ ],
906
+ },
907
+ ],
908
+ allCustomTypes: [customType],
909
+ });
910
+
911
+ expect(result).toEqual({});
912
+ });
913
+
914
+ it("should discard a regular field referenced as a content relationship field", () => {
915
+ const customType: CustomType = {
916
+ id: "customType",
917
+ label: "Custom Type",
918
+ repeatable: false,
919
+ status: true,
920
+ json: {
921
+ Main: {
922
+ booleanField: {
923
+ type: "Boolean",
924
+ },
925
+ },
926
+ },
927
+ };
928
+
929
+ const result = convertLinkCustomtypesToFieldCheckMap({
930
+ linkCustomtypes: [
931
+ {
932
+ id: "customType",
933
+ fields: [
934
+ {
935
+ id: "booleanField",
936
+ customtypes: [],
937
+ },
938
+ ],
939
+ },
940
+ ],
941
+ allCustomTypes: [customType],
942
+ });
943
+
944
+ expect(result).toEqual({});
945
+ });
946
+
947
+ it("should discard a group field referenced as a regular field (string/no picked fields)", () => {
948
+ const customType: CustomType = {
949
+ id: "customType",
950
+ label: "Custom Type",
951
+ repeatable: false,
952
+ status: true,
953
+ json: {
954
+ Main: {
955
+ groupField: {
956
+ type: "Group",
957
+ config: {
958
+ fields: {
959
+ booleanField: {
960
+ type: "Boolean",
961
+ },
962
+ },
963
+ },
964
+ },
965
+ },
966
+ },
967
+ };
968
+ const customTypeWithContentRelationship: CustomType = {
969
+ id: "customTypeWithContentRelationship",
970
+ label: "Custom Type With Content Relationship",
971
+ repeatable: false,
972
+ status: true,
973
+ json: {
974
+ Main: {
975
+ groupField: {
976
+ type: "Group",
977
+ config: {
978
+ fields: {
979
+ booleanField: {
980
+ type: "Boolean",
981
+ },
982
+ },
983
+ },
984
+ },
985
+ contentRelationshipField: {
986
+ type: "Link",
987
+ config: {
988
+ select: "document",
989
+ customtypes: ["customType"],
990
+ },
991
+ },
992
+ },
993
+ },
994
+ };
995
+
996
+ const result = convertLinkCustomtypesToFieldCheckMap({
997
+ linkCustomtypes: [
998
+ {
999
+ id: "customTypeWithContentRelationship",
1000
+ fields: [
1001
+ "groupField",
1002
+ {
1003
+ id: "contentRelationshipField",
1004
+ customtypes: [
1005
+ {
1006
+ id: "customType",
1007
+ fields: ["groupField"],
1008
+ },
1009
+ ],
1010
+ },
1011
+ ],
1012
+ },
1013
+ ],
1014
+ allCustomTypes: [customType, customTypeWithContentRelationship],
1015
+ });
1016
+
1017
+ expect(result).toEqual({});
1018
+ });
1019
+
1020
+ it("should discard a content relationship field reference to a regular field", () => {
1021
+ const customTypeA: CustomType = {
1022
+ id: "customTypeA",
1023
+ label: "Custom Type A",
1024
+ repeatable: false,
1025
+ status: true,
1026
+ json: {
1027
+ Main: {
1028
+ booleanField: {
1029
+ type: "Boolean",
1030
+ },
1031
+ },
1032
+ },
1033
+ };
1034
+ const customTypeB: CustomType = {
1035
+ id: "customTypeB",
1036
+ label: "Custom Type B",
1037
+ repeatable: false,
1038
+ status: true,
1039
+ json: {
1040
+ Main: {
1041
+ colorField: {
1042
+ type: "Color",
1043
+ },
1044
+ },
1045
+ },
1046
+ };
1047
+
1048
+ const result = convertLinkCustomtypesToFieldCheckMap({
1049
+ linkCustomtypes: [
1050
+ {
1051
+ id: "customTypeA",
1052
+ fields: [
1053
+ {
1054
+ id: "booleanField",
1055
+ customtypes: [
1056
+ {
1057
+ id: "customTypeB",
1058
+ fields: ["colorField"],
1059
+ },
1060
+ ],
1061
+ },
1062
+ ],
1063
+ },
1064
+ ],
1065
+ allCustomTypes: [customTypeB, customTypeA],
1066
+ });
1067
+
1068
+ expect(result).toEqual({});
1069
+ });
1070
+
1071
+ it("should discard a content relationship field if it references a non existing custom type", () => {
1072
+ const customTypeWithField: CustomType = {
1073
+ id: "customTypeWithField",
1074
+ label: "Custom Type With Field",
1075
+ repeatable: false,
1076
+ status: true,
1077
+ json: {
1078
+ Main: {
1079
+ colorField: {
1080
+ type: "Color",
1081
+ config: {
1082
+ label: "Color Field",
1083
+ },
1084
+ },
1085
+ },
1086
+ },
1087
+ };
1088
+ const customType: CustomType = {
1089
+ id: "customType",
1090
+ label: "Custom Type",
1091
+ repeatable: false,
1092
+ status: true,
1093
+ json: {
1094
+ Main: {
1095
+ contentRelationshipField: {
1096
+ type: "Link",
1097
+ config: {
1098
+ select: "document",
1099
+ customtypes: ["customTypeWithField"],
1100
+ },
1101
+ },
1102
+ groupField: {
1103
+ type: "Group",
1104
+ config: {
1105
+ fields: {
1106
+ contentRelationshipFieldInsideGroup: {
1107
+ type: "Link",
1108
+ config: {
1109
+ select: "document",
1110
+ customtypes: ["customTypeWithField"],
1111
+ },
1112
+ },
1113
+ },
1114
+ },
1115
+ },
1116
+ },
1117
+ },
1118
+ };
1119
+
1120
+ const result = convertLinkCustomtypesToFieldCheckMap({
1121
+ linkCustomtypes: [
1122
+ {
1123
+ id: "customType",
1124
+ fields: [
1125
+ {
1126
+ id: "contentRelationshipField",
1127
+ customtypes: [
1128
+ {
1129
+ id: "nonExistingCustomType",
1130
+ fields: ["colorField"],
1131
+ },
1132
+ ],
1133
+ },
1134
+ {
1135
+ id: "groupField",
1136
+ fields: [
1137
+ {
1138
+ id: "contentRelationshipFieldInsideGroup",
1139
+ customtypes: [
1140
+ {
1141
+ id: "nonExistingCustomType",
1142
+ fields: ["colorField"],
1143
+ },
1144
+ ],
1145
+ },
1146
+ ],
1147
+ },
1148
+ ],
1149
+ },
1150
+ ],
1151
+ allCustomTypes: [customType, customTypeWithField],
1152
+ });
1153
+
1154
+ expect(result).toEqual({});
1155
+ });
1156
+
1157
+ it("should discard content relationship fields referenced at a depth above 2", () => {
1158
+ const thirdCustomType: CustomType = {
1159
+ id: "thirdCustomType",
1160
+ label: "Third Custom Type",
1161
+ repeatable: false,
1162
+ status: true,
1163
+ json: {
1164
+ Main: {
1165
+ booleanField: {
1166
+ type: "Boolean",
1167
+ },
1168
+ },
1169
+ },
1170
+ };
1171
+ const secondCustomType: CustomType = {
1172
+ id: "secondCustomType",
1173
+ label: "Second Custom Type",
1174
+ repeatable: false,
1175
+ status: true,
1176
+ json: {
1177
+ Main: {
1178
+ secondCr: {
1179
+ type: "Link",
1180
+ config: {
1181
+ select: "document",
1182
+ customtypes: ["customType2"],
1183
+ },
1184
+ },
1185
+ },
1186
+ },
1187
+ };
1188
+ const firstCustomType: CustomType = {
1189
+ id: "firstCustomType",
1190
+ label: "First Custom Type",
1191
+ repeatable: false,
1192
+ status: true,
1193
+ json: {
1194
+ Main: {
1195
+ firstCr: {
1196
+ type: "Link",
1197
+ config: {
1198
+ select: "document",
1199
+ customtypes: ["customType"],
1200
+ },
1201
+ },
1202
+ },
1203
+ },
1204
+ };
1205
+
1206
+ const result = convertLinkCustomtypesToFieldCheckMap({
1207
+ linkCustomtypes: [
1208
+ {
1209
+ id: "firstCustomType",
1210
+ fields: [
1211
+ {
1212
+ id: "firstCr",
1213
+ customtypes: [
1214
+ {
1215
+ id: "secondCustomType",
1216
+ fields: [
1217
+ {
1218
+ id: "secondCr",
1219
+ // @ts-expect-error - this is a test
1220
+ customtypes: [
1221
+ {
1222
+ id: "thirdCustomType",
1223
+ },
1224
+ ],
1225
+ },
1226
+ ],
1227
+ },
1228
+ ],
1229
+ },
1230
+ ],
1231
+ },
1232
+ ],
1233
+ allCustomTypes: [secondCustomType, thirdCustomType, firstCustomType],
1234
+ });
1235
+
1236
+ expect(result).toEqual({});
1237
+ });
1238
+
1239
+ it("should not check for valid fields if allCustomTypes prop is not provided", () => {
1240
+ const result = convertLinkCustomtypesToFieldCheckMap({
1241
+ linkCustomtypes: [
1242
+ {
1243
+ id: "customTypeA",
1244
+ fields: [
1245
+ "fieldA",
1246
+ {
1247
+ id: "groupA",
1248
+ fields: ["groupFieldA"],
1249
+ },
1250
+ {
1251
+ id: "contentRelationshipA",
1252
+ customtypes: [
1253
+ {
1254
+ id: "customTypeB",
1255
+ fields: ["fieldB"],
1256
+ },
1257
+ ],
1258
+ },
1259
+ ],
1260
+ },
1261
+ ],
1262
+ });
1263
+
1264
+ expect(result).toEqual({
1265
+ customTypeA: {
1266
+ fieldA: {
1267
+ type: "checkbox",
1268
+ value: true,
1269
+ },
1270
+ groupA: {
1271
+ type: "group",
1272
+ value: {
1273
+ groupFieldA: {
1274
+ type: "checkbox",
1275
+ value: true,
1276
+ },
1277
+ },
1278
+ },
1279
+ contentRelationshipA: {
1280
+ type: "contentRelationship",
1281
+ value: {
1282
+ customTypeB: {
1283
+ fieldB: {
1284
+ type: "checkbox",
1285
+ value: true,
1286
+ },
1287
+ },
1288
+ },
1289
+ },
1290
+ },
1291
+ });
1292
+ });
1293
+
1294
+ it("should check for valid fields if allCustomTypes is empty", () => {
1295
+ const result = convertLinkCustomtypesToFieldCheckMap({
1296
+ linkCustomtypes: [
1297
+ {
1298
+ id: "customTypeA",
1299
+ fields: [
1300
+ "fieldA",
1301
+ {
1302
+ id: "groupA",
1303
+ fields: ["groupFieldA"],
1304
+ },
1305
+ {
1306
+ id: "contentRelationshipA",
1307
+ customtypes: [
1308
+ {
1309
+ id: "customTypeB",
1310
+ fields: ["fieldB"],
1311
+ },
1312
+ ],
1313
+ },
1314
+ ],
1315
+ },
1316
+ ],
1317
+ allCustomTypes: [],
1318
+ });
1319
+
1320
+ expect(result).toEqual({});
1321
+ });
1322
+ });
1323
+ });