slice-machine-ui 2.16.2-beta.14 → 2.16.2-beta.16
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/out/404.html +1 -1
- package/out/_next/static/{BtSHt7fAY5nNLm4Ukf41C → -0bsRJZWk8rQOiwtaIoUw}/_buildManifest.js +1 -1
- package/out/_next/static/chunks/630-394ddfa25279a303.js +1 -0
- package/out/_next/static/chunks/{882-ecbe3055c3de957c.js → 882-151468121d542ed6.js} +1 -1
- package/out/_next/static/chunks/pages/{_app-bca596721d88a762.js → _app-84fe296367a253fa.js} +1 -1
- package/out/_next/static/chunks/pages/slices/[lib]/[sliceName]/{[variation]-c499affc01dda718.js → [variation]-bd5e45632c419567.js} +1 -1
- package/out/changelog.html +1 -1
- package/out/changes.html +1 -1
- package/out/custom-types/[customTypeId].html +1 -1
- package/out/custom-types.html +1 -1
- package/out/index.html +1 -1
- package/out/labs.html +1 -1
- package/out/page-types/[pageTypeId].html +1 -1
- package/out/settings.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation]/simulator.html +1 -1
- package/out/slices/[lib]/[sliceName]/[variation].html +1 -1
- package/out/slices.html +1 -1
- package/package.json +3 -3
- package/src/features/builder/fields/contentRelationship/ContentRelationshipFieldPicker.tsx +149 -102
- package/src/features/builder/fields/contentRelationship/__tests__/ContentRelationshipFieldPicker.test.ts +265 -0
- package/src/utils/tracking/getLinkTrackingProperties.ts +26 -0
- package/src/utils/tracking/trackFieldAdded.ts +2 -5
- package/src/utils/tracking/trackFieldUpdated.ts +2 -5
- package/out/_next/static/chunks/630-48546ce1785de212.js +0 -1
- /package/out/_next/static/{BtSHt7fAY5nNLm4Ukf41C → -0bsRJZWk8rQOiwtaIoUw}/_ssgManifest.js +0 -0
|
@@ -532,7 +532,7 @@ function TreeViewCustomType(props: TreeViewCustomTypeProps) {
|
|
|
532
532
|
({ fieldId, field }) => {
|
|
533
533
|
// Group field
|
|
534
534
|
|
|
535
|
-
if (
|
|
535
|
+
if (field.type === "Group") {
|
|
536
536
|
const onGroupFieldChange = (
|
|
537
537
|
newGroupFields: PickerFirstLevelGroupFieldValue,
|
|
538
538
|
) => {
|
|
@@ -560,9 +560,9 @@ function TreeViewCustomType(props: TreeViewCustomTypeProps) {
|
|
|
560
560
|
);
|
|
561
561
|
}
|
|
562
562
|
|
|
563
|
-
// Content relationship field
|
|
563
|
+
// Content relationship field with custom types
|
|
564
564
|
|
|
565
|
-
if (
|
|
565
|
+
if (isContentRelationshipFieldWithSingleCustomtype(field)) {
|
|
566
566
|
const onContentRelationshipFieldChange = (
|
|
567
567
|
newCrFields: PickerContentRelationshipFieldValue,
|
|
568
568
|
) => {
|
|
@@ -614,23 +614,23 @@ function TreeViewCustomType(props: TreeViewCustomTypeProps) {
|
|
|
614
614
|
);
|
|
615
615
|
|
|
616
616
|
const exposedFieldsCount = countPickedFields(customTypeFieldsCheckMap);
|
|
617
|
+
|
|
617
618
|
return (
|
|
618
619
|
<TreeViewSection
|
|
619
620
|
key={customType.id}
|
|
620
621
|
title={customType.id}
|
|
621
622
|
subtitle={
|
|
622
|
-
exposedFieldsCount > 0
|
|
623
|
-
?
|
|
623
|
+
exposedFieldsCount.pickedFields > 0
|
|
624
|
+
? getPickedFieldsLabel(
|
|
625
|
+
exposedFieldsCount.pickedFields,
|
|
626
|
+
"returned in the API",
|
|
627
|
+
)
|
|
624
628
|
: "(No fields returned in the API)"
|
|
625
629
|
}
|
|
626
630
|
badge={getTypeFormatLabel(customType.format)}
|
|
627
631
|
defaultOpen
|
|
628
632
|
>
|
|
629
|
-
{renderedFields.length > 0 ?
|
|
630
|
-
renderedFields
|
|
631
|
-
) : (
|
|
632
|
-
<Text color="grey11">No available fields to select</Text>
|
|
633
|
-
)}
|
|
633
|
+
{renderedFields.length > 0 ? renderedFields : <NoFieldsAvailable />}
|
|
634
634
|
</TreeViewSection>
|
|
635
635
|
);
|
|
636
636
|
}
|
|
@@ -666,7 +666,9 @@ function TreeViewContentRelationshipField(
|
|
|
666
666
|
return (
|
|
667
667
|
<TreeViewSection
|
|
668
668
|
title={fieldId}
|
|
669
|
-
subtitle={
|
|
669
|
+
subtitle={getPickedFieldsLabel(
|
|
670
|
+
countPickedFields(crFieldsCheckMap).pickedFields,
|
|
671
|
+
)}
|
|
670
672
|
>
|
|
671
673
|
{resolvedCustomTypes.map((customType) => {
|
|
672
674
|
if (typeof customType === "string") return null;
|
|
@@ -686,7 +688,7 @@ function TreeViewContentRelationshipField(
|
|
|
686
688
|
({ fieldId, field }) => {
|
|
687
689
|
// Group field
|
|
688
690
|
|
|
689
|
-
if (
|
|
691
|
+
if (field.type === "Group") {
|
|
690
692
|
const onGroupFieldsChange = (
|
|
691
693
|
newGroupFields: PickerLeafGroupFieldValue,
|
|
692
694
|
) => {
|
|
@@ -733,18 +735,16 @@ function TreeViewContentRelationshipField(
|
|
|
733
735
|
},
|
|
734
736
|
);
|
|
735
737
|
|
|
736
|
-
if (renderedFields.length === 0) return null;
|
|
737
|
-
|
|
738
738
|
return (
|
|
739
739
|
<TreeViewSection
|
|
740
740
|
key={customType.id}
|
|
741
741
|
title={customType.id}
|
|
742
|
-
subtitle={
|
|
743
|
-
countPickedFields(nestedCtFieldsCheckMap),
|
|
742
|
+
subtitle={getPickedFieldsLabel(
|
|
743
|
+
countPickedFields(nestedCtFieldsCheckMap).pickedFields,
|
|
744
744
|
)}
|
|
745
745
|
badge={getTypeFormatLabel(customType.format)}
|
|
746
746
|
>
|
|
747
|
-
{renderedFields}
|
|
747
|
+
{renderedFields.length > 0 ? renderedFields : <NoFieldsAvailable />}
|
|
748
748
|
</TreeViewSection>
|
|
749
749
|
);
|
|
750
750
|
})}
|
|
@@ -752,6 +752,10 @@ function TreeViewContentRelationshipField(
|
|
|
752
752
|
);
|
|
753
753
|
}
|
|
754
754
|
|
|
755
|
+
function NoFieldsAvailable() {
|
|
756
|
+
return <Text color="grey11">No available fields to select</Text>;
|
|
757
|
+
}
|
|
758
|
+
|
|
755
759
|
interface TreeViewLeafGroupFieldProps {
|
|
756
760
|
group: Group;
|
|
757
761
|
groupId: string;
|
|
@@ -787,16 +791,16 @@ function TreeViewLeafGroupField(props: TreeViewLeafGroupFieldProps) {
|
|
|
787
791
|
);
|
|
788
792
|
});
|
|
789
793
|
|
|
790
|
-
if (renderedFields.length === 0) return null;
|
|
791
|
-
|
|
792
794
|
return (
|
|
793
795
|
<TreeViewSection
|
|
794
796
|
key={groupId}
|
|
795
797
|
title={groupId}
|
|
796
|
-
subtitle={
|
|
798
|
+
subtitle={getPickedFieldsLabel(
|
|
799
|
+
countPickedFields(groupFieldsCheckMap).pickedFields,
|
|
800
|
+
)}
|
|
797
801
|
badge="Group"
|
|
798
802
|
>
|
|
799
|
-
{renderedFields}
|
|
803
|
+
{renderedFields.length > 0 ? renderedFields : <NoFieldsAvailable />}
|
|
800
804
|
</TreeViewSection>
|
|
801
805
|
);
|
|
802
806
|
}
|
|
@@ -820,74 +824,76 @@ function TreeViewFirstLevelGroupField(
|
|
|
820
824
|
allCustomTypes,
|
|
821
825
|
} = props;
|
|
822
826
|
|
|
823
|
-
|
|
827
|
+
const renderedFields = getGroupFields(group).map(({ fieldId, field }) => {
|
|
828
|
+
// Content relationship field with custom types
|
|
829
|
+
|
|
830
|
+
if (isContentRelationshipFieldWithSingleCustomtype(field)) {
|
|
831
|
+
const onContentRelationshipFieldChange = (
|
|
832
|
+
newCrFields: PickerContentRelationshipFieldValue,
|
|
833
|
+
) => {
|
|
834
|
+
onGroupFieldChange({
|
|
835
|
+
...groupFieldsCheckMap,
|
|
836
|
+
[fieldId]: {
|
|
837
|
+
type: "contentRelationship",
|
|
838
|
+
value: newCrFields,
|
|
839
|
+
},
|
|
840
|
+
});
|
|
841
|
+
};
|
|
842
|
+
|
|
843
|
+
const crFieldCheckMap = groupFieldsCheckMap[fieldId] ?? {};
|
|
844
|
+
|
|
845
|
+
return (
|
|
846
|
+
<TreeViewContentRelationshipField
|
|
847
|
+
key={fieldId}
|
|
848
|
+
field={field}
|
|
849
|
+
fieldId={fieldId}
|
|
850
|
+
fieldCheckMap={
|
|
851
|
+
crFieldCheckMap.type === "contentRelationship"
|
|
852
|
+
? crFieldCheckMap.value
|
|
853
|
+
: {}
|
|
854
|
+
}
|
|
855
|
+
onChange={onContentRelationshipFieldChange}
|
|
856
|
+
allCustomTypes={allCustomTypes}
|
|
857
|
+
/>
|
|
858
|
+
);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// Regular field
|
|
862
|
+
|
|
863
|
+
const onCheckedChange = (newChecked: boolean) => {
|
|
864
|
+
onGroupFieldChange({
|
|
865
|
+
...groupFieldsCheckMap,
|
|
866
|
+
[fieldId]: { type: "checkbox", value: newChecked },
|
|
867
|
+
});
|
|
868
|
+
};
|
|
869
|
+
|
|
870
|
+
return (
|
|
871
|
+
<TreeViewCheckbox
|
|
872
|
+
key={fieldId}
|
|
873
|
+
title={fieldId}
|
|
874
|
+
checked={groupFieldsCheckMap[fieldId]?.value === true}
|
|
875
|
+
onCheckedChange={onCheckedChange}
|
|
876
|
+
/>
|
|
877
|
+
);
|
|
878
|
+
});
|
|
824
879
|
|
|
825
880
|
return (
|
|
826
881
|
<TreeViewSection
|
|
827
882
|
key={groupId}
|
|
828
883
|
title={groupId}
|
|
829
|
-
subtitle={
|
|
884
|
+
subtitle={getPickedFieldsLabel(
|
|
885
|
+
countPickedFields(groupFieldsCheckMap).pickedFields,
|
|
886
|
+
)}
|
|
830
887
|
badge="Group"
|
|
831
888
|
>
|
|
832
|
-
{
|
|
833
|
-
if (isContentRelationshipField(field)) {
|
|
834
|
-
const onContentRelationshipFieldChange = (
|
|
835
|
-
newCrFields: PickerContentRelationshipFieldValue,
|
|
836
|
-
) => {
|
|
837
|
-
onGroupFieldChange({
|
|
838
|
-
...groupFieldsCheckMap,
|
|
839
|
-
[fieldId]: {
|
|
840
|
-
type: "contentRelationship",
|
|
841
|
-
value: newCrFields,
|
|
842
|
-
},
|
|
843
|
-
});
|
|
844
|
-
};
|
|
845
|
-
|
|
846
|
-
const crFieldCheckMap = groupFieldsCheckMap[fieldId] ?? {};
|
|
847
|
-
|
|
848
|
-
return (
|
|
849
|
-
<TreeViewContentRelationshipField
|
|
850
|
-
key={fieldId}
|
|
851
|
-
field={field}
|
|
852
|
-
fieldId={fieldId}
|
|
853
|
-
fieldCheckMap={
|
|
854
|
-
crFieldCheckMap.type === "contentRelationship"
|
|
855
|
-
? crFieldCheckMap.value
|
|
856
|
-
: {}
|
|
857
|
-
}
|
|
858
|
-
onChange={onContentRelationshipFieldChange}
|
|
859
|
-
allCustomTypes={allCustomTypes}
|
|
860
|
-
/>
|
|
861
|
-
);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
const onCheckedChange = (newChecked: boolean) => {
|
|
865
|
-
onGroupFieldChange({
|
|
866
|
-
...groupFieldsCheckMap,
|
|
867
|
-
[fieldId]: { type: "checkbox", value: newChecked },
|
|
868
|
-
});
|
|
869
|
-
};
|
|
870
|
-
|
|
871
|
-
return (
|
|
872
|
-
<TreeViewCheckbox
|
|
873
|
-
key={fieldId}
|
|
874
|
-
title={fieldId}
|
|
875
|
-
checked={groupFieldsCheckMap[fieldId]?.value === true}
|
|
876
|
-
onCheckedChange={onCheckedChange}
|
|
877
|
-
/>
|
|
878
|
-
);
|
|
879
|
-
})}
|
|
889
|
+
{renderedFields.length > 0 ? renderedFields : <NoFieldsAvailable />}
|
|
880
890
|
</TreeViewSection>
|
|
881
891
|
);
|
|
882
892
|
}
|
|
883
893
|
|
|
884
|
-
function
|
|
894
|
+
function getPickedFieldsLabel(count: number, suffix = "selected") {
|
|
885
895
|
if (count === 0) return undefined;
|
|
886
|
-
return `(${count} ${pluralize(
|
|
887
|
-
count,
|
|
888
|
-
"field",
|
|
889
|
-
"fields",
|
|
890
|
-
)} returned in the API)`;
|
|
896
|
+
return `(${count} ${pluralize(count, "field", "fields")} ${suffix})`;
|
|
891
897
|
}
|
|
892
898
|
|
|
893
899
|
function getTypeFormatLabel(format: CustomType["format"]) {
|
|
@@ -925,22 +931,19 @@ function useCustomTypes(value: LinkCustomtypes | undefined): {
|
|
|
925
931
|
}
|
|
926
932
|
|
|
927
933
|
function resolveContentRelationshipCustomTypes(
|
|
928
|
-
|
|
934
|
+
linkCustomtypes: LinkCustomtypes,
|
|
929
935
|
localCustomTypes: CustomType[],
|
|
930
936
|
): CustomType[] {
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
return localCustomTypes.find((ct) => ct.id === customType.id) ?? [];
|
|
937
|
+
return linkCustomtypes.flatMap((linkCustomtype) => {
|
|
938
|
+
return localCustomTypes.find((ct) => ct.id === getId(linkCustomtype)) ?? [];
|
|
934
939
|
});
|
|
935
|
-
|
|
936
|
-
return fields;
|
|
937
940
|
}
|
|
938
941
|
|
|
939
942
|
/**
|
|
940
943
|
* Converts a Link config `customtypes` ({@link LinkCustomtypes}) structure into
|
|
941
944
|
* picker fields check map ({@link PickerCustomTypes}).
|
|
942
945
|
*/
|
|
943
|
-
function convertLinkCustomtypesToFieldCheckMap(
|
|
946
|
+
export function convertLinkCustomtypesToFieldCheckMap(
|
|
944
947
|
customTypes: LinkCustomtypes,
|
|
945
948
|
): PickerCustomTypes {
|
|
946
949
|
return customTypes.reduce<PickerCustomTypes>((customTypes, customType) => {
|
|
@@ -1162,39 +1165,82 @@ function createContentRelationshipLinkCustomtypes(
|
|
|
1162
1165
|
);
|
|
1163
1166
|
}
|
|
1164
1167
|
|
|
1168
|
+
type CountPickedFieldsResult = {
|
|
1169
|
+
pickedFields: number;
|
|
1170
|
+
nestedPickedFields: number;
|
|
1171
|
+
};
|
|
1172
|
+
|
|
1165
1173
|
/**
|
|
1166
1174
|
* Generic recursive function that goes down the fields check map and counts all
|
|
1167
1175
|
* the properties that are set to true, which correspond to selected fields.
|
|
1168
1176
|
*
|
|
1177
|
+
* Distinguishes between all picked fields and nested picked fields within a
|
|
1178
|
+
* content relationship field.
|
|
1179
|
+
*
|
|
1169
1180
|
* It's not type safe, but checks the type of the values at runtime so that
|
|
1170
1181
|
* it only recurses into valid objects, and only counts checkbox fields.
|
|
1171
1182
|
*/
|
|
1172
|
-
function countPickedFields(
|
|
1183
|
+
export function countPickedFields(
|
|
1173
1184
|
fields: Record<string, unknown> | undefined,
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
if (!isValidObject(value)) return count;
|
|
1178
|
-
if (isCheckboxValue(value)) return count + (value.value ? 1 : 0);
|
|
1179
|
-
return count + countPickedFields(value);
|
|
1180
|
-
}, 0);
|
|
1181
|
-
}
|
|
1182
|
-
function isCheckboxValue(value: unknown): value is PickerCheckboxField {
|
|
1183
|
-
if (!isValidObject(value)) return false;
|
|
1184
|
-
return "type" in value && value.type === "checkbox";
|
|
1185
|
-
}
|
|
1185
|
+
isNested = false,
|
|
1186
|
+
): CountPickedFieldsResult {
|
|
1187
|
+
if (!fields) return { pickedFields: 0, nestedPickedFields: 0 };
|
|
1186
1188
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
+
return Object.values(fields).reduce<CountPickedFieldsResult>(
|
|
1190
|
+
(result, value) => {
|
|
1191
|
+
if (!isValidObject(value)) return result;
|
|
1192
|
+
|
|
1193
|
+
if ("type" in value && value.type === "checkbox") {
|
|
1194
|
+
const isChecked = Boolean(value.value);
|
|
1195
|
+
if (!isChecked) return result;
|
|
1196
|
+
|
|
1197
|
+
return {
|
|
1198
|
+
pickedFields: result.pickedFields + 1,
|
|
1199
|
+
nestedPickedFields: result.nestedPickedFields + (isNested ? 1 : 0),
|
|
1200
|
+
};
|
|
1201
|
+
}
|
|
1202
|
+
|
|
1203
|
+
if ("type" in value && value.type === "contentRelationship") {
|
|
1204
|
+
const { pickedFields, nestedPickedFields } = countPickedFields(
|
|
1205
|
+
value,
|
|
1206
|
+
true,
|
|
1207
|
+
);
|
|
1208
|
+
|
|
1209
|
+
return {
|
|
1210
|
+
pickedFields: result.pickedFields + pickedFields,
|
|
1211
|
+
nestedPickedFields: result.nestedPickedFields + nestedPickedFields,
|
|
1212
|
+
};
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
const { pickedFields, nestedPickedFields } = countPickedFields(
|
|
1216
|
+
value,
|
|
1217
|
+
isNested,
|
|
1218
|
+
);
|
|
1219
|
+
|
|
1220
|
+
return {
|
|
1221
|
+
pickedFields: result.pickedFields + pickedFields,
|
|
1222
|
+
nestedPickedFields: result.nestedPickedFields + nestedPickedFields,
|
|
1223
|
+
};
|
|
1224
|
+
},
|
|
1225
|
+
{
|
|
1226
|
+
pickedFields: 0,
|
|
1227
|
+
nestedPickedFields: 0,
|
|
1228
|
+
},
|
|
1229
|
+
);
|
|
1189
1230
|
}
|
|
1190
1231
|
|
|
1191
|
-
|
|
1232
|
+
/**
|
|
1233
|
+
* Check if the field is a Content Relationship Link with a **single** custom
|
|
1234
|
+
* type. CRs with multiple custom types are not currently supported (legacy).
|
|
1235
|
+
*/
|
|
1236
|
+
function isContentRelationshipFieldWithSingleCustomtype(
|
|
1192
1237
|
field: NestableWidget | Group,
|
|
1193
1238
|
): field is Link {
|
|
1194
|
-
return (
|
|
1239
|
+
return !!(
|
|
1195
1240
|
field.type === "Link" &&
|
|
1196
1241
|
field.config?.select === "document" &&
|
|
1197
|
-
field.config?.customtypes
|
|
1242
|
+
field.config?.customtypes &&
|
|
1243
|
+
field.config.customtypes.length === 1
|
|
1198
1244
|
);
|
|
1199
1245
|
}
|
|
1200
1246
|
|
|
@@ -1225,6 +1271,7 @@ function getGroupFields(group: Group) {
|
|
|
1225
1271
|
return { fieldId, field: field as NestableWidget };
|
|
1226
1272
|
});
|
|
1227
1273
|
}
|
|
1274
|
+
|
|
1228
1275
|
/** If it's a string, return it, otherwise return the `id` property. */
|
|
1229
1276
|
function getId<T extends string | { id: string }>(customType: T): string {
|
|
1230
1277
|
if (typeof customType === "string") return customType;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
convertLinkCustomtypesToFieldCheckMap,
|
|
5
|
+
countPickedFields,
|
|
6
|
+
} from "../ContentRelationshipFieldPicker";
|
|
7
|
+
|
|
8
|
+
describe("ContentRelationshipFieldPicker", () => {
|
|
9
|
+
it("should count picked fields with a custom type as string", () => {
|
|
10
|
+
const customtypes = ["ct1"];
|
|
11
|
+
|
|
12
|
+
const result = countPickedFields(
|
|
13
|
+
convertLinkCustomtypesToFieldCheckMap(customtypes),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
expect(result).toEqual({
|
|
17
|
+
pickedFields: 0,
|
|
18
|
+
nestedPickedFields: 0,
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("should count picked fields with multiple custom types as string", () => {
|
|
23
|
+
const customtypes = ["ct1", "ct2"];
|
|
24
|
+
|
|
25
|
+
const result = countPickedFields(
|
|
26
|
+
convertLinkCustomtypesToFieldCheckMap(customtypes),
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect(result).toEqual({
|
|
30
|
+
pickedFields: 0,
|
|
31
|
+
nestedPickedFields: 0,
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("should count picked fields with custom type as object and one field", () => {
|
|
36
|
+
const customtypes = [
|
|
37
|
+
{
|
|
38
|
+
id: "ct1",
|
|
39
|
+
fields: ["f1"],
|
|
40
|
+
},
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const result = countPickedFields(
|
|
44
|
+
convertLinkCustomtypesToFieldCheckMap(customtypes),
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
expect(result).toEqual({
|
|
48
|
+
pickedFields: 1,
|
|
49
|
+
nestedPickedFields: 0,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("should count picked fields with custom type as object and one nested field", () => {
|
|
54
|
+
const customtypes = [
|
|
55
|
+
{
|
|
56
|
+
id: "ct1",
|
|
57
|
+
fields: [
|
|
58
|
+
{
|
|
59
|
+
id: "f1",
|
|
60
|
+
customtypes: [
|
|
61
|
+
{
|
|
62
|
+
id: "ct2",
|
|
63
|
+
fields: ["f1"],
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
},
|
|
69
|
+
];
|
|
70
|
+
|
|
71
|
+
const result = countPickedFields(
|
|
72
|
+
convertLinkCustomtypesToFieldCheckMap(customtypes),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
expect(result).toEqual({
|
|
76
|
+
pickedFields: 1,
|
|
77
|
+
nestedPickedFields: 1,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("should count picked fields with custom type as object with group field", () => {
|
|
82
|
+
const customtypes = [
|
|
83
|
+
{
|
|
84
|
+
id: "ct1",
|
|
85
|
+
fields: [
|
|
86
|
+
{
|
|
87
|
+
id: "g1",
|
|
88
|
+
fields: ["f1", "f2"],
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
];
|
|
93
|
+
|
|
94
|
+
const result = countPickedFields(
|
|
95
|
+
convertLinkCustomtypesToFieldCheckMap(customtypes),
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
expect(result).toEqual({
|
|
99
|
+
pickedFields: 2,
|
|
100
|
+
nestedPickedFields: 0,
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("should count picked fields with custom type as object with group field and nested custom type", () => {
|
|
105
|
+
const customtypes = [
|
|
106
|
+
{
|
|
107
|
+
id: "ct1",
|
|
108
|
+
fields: [
|
|
109
|
+
{
|
|
110
|
+
id: "g1",
|
|
111
|
+
fields: [
|
|
112
|
+
"f1",
|
|
113
|
+
{
|
|
114
|
+
id: "f2",
|
|
115
|
+
customtypes: [
|
|
116
|
+
{
|
|
117
|
+
id: "ct2",
|
|
118
|
+
fields: ["f1"],
|
|
119
|
+
},
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
},
|
|
124
|
+
],
|
|
125
|
+
},
|
|
126
|
+
];
|
|
127
|
+
|
|
128
|
+
const result = countPickedFields(
|
|
129
|
+
convertLinkCustomtypesToFieldCheckMap(customtypes),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
expect(result).toEqual({
|
|
133
|
+
pickedFields: 2,
|
|
134
|
+
nestedPickedFields: 1,
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("should count picked fields with custom type as object with group field, nested custom type and nested group field", () => {
|
|
139
|
+
const customtypes = [
|
|
140
|
+
{
|
|
141
|
+
id: "ct1",
|
|
142
|
+
fields: [
|
|
143
|
+
{
|
|
144
|
+
id: "g1",
|
|
145
|
+
fields: [
|
|
146
|
+
"f1",
|
|
147
|
+
{
|
|
148
|
+
id: "f2",
|
|
149
|
+
customtypes: [
|
|
150
|
+
{
|
|
151
|
+
id: "ct2",
|
|
152
|
+
fields: [
|
|
153
|
+
"f1",
|
|
154
|
+
{
|
|
155
|
+
id: "g2",
|
|
156
|
+
fields: ["f1", "f2"],
|
|
157
|
+
},
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
const result = countPickedFields(
|
|
169
|
+
convertLinkCustomtypesToFieldCheckMap(customtypes),
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
expect(result).toEqual({
|
|
173
|
+
pickedFields: 4,
|
|
174
|
+
nestedPickedFields: 3,
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("should count picked fields with custom type as object with nested custom type and nested group field", () => {
|
|
179
|
+
const customtypes = [
|
|
180
|
+
{
|
|
181
|
+
id: "ct1",
|
|
182
|
+
fields: [
|
|
183
|
+
"f1",
|
|
184
|
+
{
|
|
185
|
+
id: "f2",
|
|
186
|
+
customtypes: [
|
|
187
|
+
{
|
|
188
|
+
id: "ct2",
|
|
189
|
+
fields: [
|
|
190
|
+
"f1",
|
|
191
|
+
{
|
|
192
|
+
id: "g2",
|
|
193
|
+
fields: ["f1", "f2"],
|
|
194
|
+
},
|
|
195
|
+
],
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
];
|
|
202
|
+
|
|
203
|
+
const result = countPickedFields(
|
|
204
|
+
convertLinkCustomtypesToFieldCheckMap(customtypes),
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
expect(result).toEqual({
|
|
208
|
+
pickedFields: 4,
|
|
209
|
+
nestedPickedFields: 3,
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("should count picked fields with custom type as object with nested custom type without fields", () => {
|
|
214
|
+
const customtypes = [
|
|
215
|
+
{
|
|
216
|
+
id: "ct1",
|
|
217
|
+
fields: [
|
|
218
|
+
"f1",
|
|
219
|
+
{
|
|
220
|
+
id: "f2",
|
|
221
|
+
customtypes: [
|
|
222
|
+
{
|
|
223
|
+
id: "ct2",
|
|
224
|
+
fields: [],
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
],
|
|
229
|
+
},
|
|
230
|
+
];
|
|
231
|
+
|
|
232
|
+
const result = countPickedFields(
|
|
233
|
+
convertLinkCustomtypesToFieldCheckMap(customtypes),
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
expect(result).toEqual({
|
|
237
|
+
pickedFields: 1,
|
|
238
|
+
nestedPickedFields: 0,
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("should count picked fields with custom type as object with group field without fields", () => {
|
|
243
|
+
const customtypes = [
|
|
244
|
+
{
|
|
245
|
+
id: "ct1",
|
|
246
|
+
fields: [
|
|
247
|
+
"f1",
|
|
248
|
+
{
|
|
249
|
+
id: "g1",
|
|
250
|
+
fields: [],
|
|
251
|
+
},
|
|
252
|
+
],
|
|
253
|
+
},
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
const result = countPickedFields(
|
|
257
|
+
convertLinkCustomtypesToFieldCheckMap(customtypes),
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
expect(result).toEqual({
|
|
261
|
+
pickedFields: 1,
|
|
262
|
+
nestedPickedFields: 0,
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Link } from "@prismicio/types-internal/lib/customtypes/widgets";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
convertLinkCustomtypesToFieldCheckMap,
|
|
5
|
+
countPickedFields,
|
|
6
|
+
} from "@/features/builder/fields/contentRelationship/ContentRelationshipFieldPicker";
|
|
7
|
+
|
|
8
|
+
export function getLinkTrackingProperties(field: Link) {
|
|
9
|
+
return {
|
|
10
|
+
allowText: field.config?.allowText,
|
|
11
|
+
repeat: field.config?.repeat,
|
|
12
|
+
variants: field.config?.variants,
|
|
13
|
+
linkSelect: field.config?.select,
|
|
14
|
+
...(field.config?.select === "document" &&
|
|
15
|
+
field.config?.customtypes &&
|
|
16
|
+
(() => {
|
|
17
|
+
const { pickedFields, nestedPickedFields } = countPickedFields(
|
|
18
|
+
convertLinkCustomtypesToFieldCheckMap(field.config?.customtypes),
|
|
19
|
+
);
|
|
20
|
+
return {
|
|
21
|
+
linkPickedFields: pickedFields,
|
|
22
|
+
linkNestedPickedFields: nestedPickedFields,
|
|
23
|
+
};
|
|
24
|
+
})()),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -8,6 +8,7 @@ import { telemetry } from "@/apiClient";
|
|
|
8
8
|
import { SlicePrimaryFieldSM } from "@/legacy/lib/models/common/Slice";
|
|
9
9
|
|
|
10
10
|
import { getContentTypeForTracking } from "./getContentTypeForTracking";
|
|
11
|
+
import { getLinkTrackingProperties } from "./getLinkTrackingProperties";
|
|
11
12
|
|
|
12
13
|
type TrackFieldAddedArgs = {
|
|
13
14
|
id: string;
|
|
@@ -25,10 +26,6 @@ export function trackFieldAdded(args: TrackFieldAddedArgs) {
|
|
|
25
26
|
type: field.type,
|
|
26
27
|
isInAGroup,
|
|
27
28
|
contentType: getContentTypeForTracking(window.location.pathname),
|
|
28
|
-
...(field.type === "Link" &&
|
|
29
|
-
allowText: field.config?.allowText,
|
|
30
|
-
repeat: field.config?.repeat,
|
|
31
|
-
variants: field.config?.variants,
|
|
32
|
-
}),
|
|
29
|
+
...(field.type === "Link" && getLinkTrackingProperties(field)),
|
|
33
30
|
});
|
|
34
31
|
}
|