slice-machine-ui 2.16.2-beta.9 → 2.17.0

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/9gEJI2zCChbd-ZM5eAZcP/_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-a8b2c2d022cc9450.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-e3fa2a0a57c571ce.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 -9
  36. package/src/features/builder/fields/contentRelationship/ContentRelationshipFieldPicker.tsx +1279 -0
  37. package/src/features/builder/fields/contentRelationship/Hint.tsx +28 -0
  38. package/src/features/builder/fields/contentRelationship/__tests__/ContentRelationshipFieldPicker.test.ts +265 -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 +26 -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 → 9gEJI2zCChbd-ZM5eAZcP}/_ssgManifest.js +0 -0
@@ -0,0 +1,28 @@
1
+ import { Box, Text } from "@prismicio/editor-ui";
2
+
3
+ export function Hint(args: { show: boolean }) {
4
+ if (!args.show) return null;
5
+
6
+ return (
7
+ <Box
8
+ padding={{ block: 8, inline: 16 }}
9
+ border={{ top: true }}
10
+ borderColor="grey6"
11
+ >
12
+ <Text variant="normal" color="grey11">
13
+ No code snippet for this field.{" "}
14
+ <Text
15
+ component="a"
16
+ href="https://prismic.io/docs/fields/content-relationship"
17
+ rel="noopener noreferrer"
18
+ target="_blank"
19
+ color="grey11"
20
+ underline
21
+ >
22
+ Check the docs
23
+ </Text>{" "}
24
+ for an example.
25
+ </Text>
26
+ </Box>
27
+ );
28
+ }
@@ -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
+ });
@@ -29,10 +29,8 @@ import { SingleIcon } from "@/icons/SingleIcon";
29
29
 
30
30
  import { CUSTOM_TYPES_CONFIG } from "../customTypesConfig";
31
31
  import { EditDropdown } from "../EditDropdown";
32
- import {
33
- useCustomTypes,
34
- useCustomTypesAutoRevalidation,
35
- } from "./useCustomTypes";
32
+ import { useCustomTypes } from "../useCustomTypes";
33
+ import { useCustomTypesAutoRevalidation } from "./useCustomTypesAutoRevalidation";
36
34
 
37
35
  type CustomTypesTableProps = {
38
36
  format: CustomTypeFormat;
@@ -1,46 +1,13 @@
1
- import { updateData, useRequest } from "@prismicio/editor-support/Suspense";
2
1
  import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
3
2
  import type { CustomTypeFormat } from "@slicemachine/manager";
4
- import { useCallback, useEffect } from "react";
3
+ import { useEffect } from "react";
5
4
  import { useSelector } from "react-redux";
6
5
 
7
6
  import { CustomTypes } from "@/legacy/lib/models/common/CustomType";
8
7
  import { hasLocal } from "@/legacy/lib/models/common/ModelData";
9
- import { managerClient } from "@/managerClient";
10
8
  import { selectAllCustomTypes } from "@/modules/availableCustomTypes";
11
9
  import type { SliceMachineStoreType } from "@/redux/type";
12
10
 
13
- type UseCustomTypesReturnType = {
14
- customTypes: CustomType[];
15
- updateCustomTypes: (customTypes: CustomType[]) => void;
16
- };
17
-
18
- export function useCustomTypes(
19
- format: CustomTypeFormat,
20
- ): UseCustomTypesReturnType {
21
- const updateCustomTypes = useCallback(
22
- (data: CustomType[]) => updateData(getCustomTypes, [format], data),
23
- [format],
24
- );
25
-
26
- return {
27
- customTypes: useRequest(getCustomTypes, [format]),
28
- updateCustomTypes,
29
- };
30
- }
31
-
32
- async function getCustomTypes(format: CustomTypeFormat): Promise<CustomType[]> {
33
- const { errors, models } = await managerClient.customTypes.readAllCustomTypes(
34
- { format },
35
- );
36
-
37
- if (errors.length > 0) {
38
- throw errors;
39
- }
40
-
41
- return models.map(({ model }) => model);
42
- }
43
-
44
11
  /**
45
12
  * TODO: DT-1363 - Update the way to have new data without Redux by revalidating
46
13
  * Suspense
@@ -0,0 +1,48 @@
1
+ import {
2
+ revalidateData,
3
+ updateData,
4
+ useRequest,
5
+ } from "@prismicio/editor-support/Suspense";
6
+ import type { CustomType } from "@prismicio/types-internal/lib/customtypes";
7
+ import type { CustomTypeFormat } from "@slicemachine/manager";
8
+ import { useCallback } from "react";
9
+
10
+ import { managerClient } from "@/managerClient";
11
+
12
+ type UseCustomTypesReturnType = {
13
+ customTypes: CustomType[];
14
+ updateCustomTypes: (customTypes: CustomType[]) => void;
15
+ };
16
+
17
+ export function useCustomTypes(
18
+ format?: CustomTypeFormat,
19
+ ): UseCustomTypesReturnType {
20
+ const updateCustomTypes = useCallback(
21
+ (data: CustomType[]) => updateData(getCustomTypes, [format], data),
22
+ [format],
23
+ );
24
+
25
+ return {
26
+ customTypes: useRequest(getCustomTypes, [format]),
27
+ updateCustomTypes,
28
+ };
29
+ }
30
+
31
+ export async function getCustomTypes(
32
+ format?: CustomTypeFormat,
33
+ ): Promise<CustomType[]> {
34
+ const { errors, models } = await managerClient.customTypes.readAllCustomTypes(
35
+ format ? { format } : undefined,
36
+ );
37
+
38
+ if (errors.length > 0) {
39
+ throw errors;
40
+ }
41
+
42
+ return models.map(({ model }) => model);
43
+ }
44
+
45
+ export function revalidateGetCustomTypes(format?: CustomTypeFormat) {
46
+ void revalidateData(getCustomTypes, []);
47
+ void revalidateData(getCustomTypes, [format]);
48
+ }
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import useSWR from "swr";
3
3
 
4
+ import { Hint as ContentRelationshipHint } from "@/features/builder/fields/contentRelationship/Hint";
4
5
  import { managerClient } from "@/managerClient";
5
6
 
6
7
  import CodeBlock, { Item, RenderHintBaseFN } from "./CodeBlock";
@@ -12,7 +13,7 @@ interface HintProps {
12
13
  hintItemName?: string;
13
14
  }
14
15
 
15
- const Hint: React.FC<HintProps> = ({
16
+ const RegularHint: React.FC<HintProps> = ({
16
17
  show,
17
18
  renderHintBase,
18
19
  item,
@@ -62,4 +63,14 @@ const Hint: React.FC<HintProps> = ({
62
63
  );
63
64
  };
64
65
 
66
+ const Hint: React.FC<HintProps> = (props) => {
67
+ const { item } = props;
68
+
69
+ if (item.value.type === "Link" && item.value.config?.select === "document") {
70
+ return <ContentRelationshipHint show={props.show} />;
71
+ }
72
+
73
+ return <RegularHint {...props} />;
74
+ };
75
+
65
76
  export default Hint;
@@ -1,105 +1,63 @@
1
+ import { LinkConfig } from "@prismicio/types-internal/lib/customtypes";
1
2
  import { FormikProps } from "formik";
2
- import { useSelector } from "react-redux";
3
- import Select from "react-select";
4
- import { Box, Label } from "theme-ui";
3
+ import { Box } from "theme-ui";
5
4
  import * as yup from "yup";
6
5
 
6
+ import { ContentRelationshipFieldPicker } from "@/features/builder/fields/contentRelationship/ContentRelationshipFieldPicker";
7
7
  import { Col, Flex as FlexGrid } from "@/legacy/components/Flex";
8
8
  import WidgetFormField from "@/legacy/lib/builders/common/EditModal/Field";
9
9
  import { createFieldNameFromKey } from "@/legacy/lib/forms";
10
10
  import { DefaultFields } from "@/legacy/lib/forms/defaults";
11
- import { selectAllCustomTypes } from "@/modules/availableCustomTypes";
12
-
13
- import { hasLocal } from "../../ModelData";
14
11
 
15
12
  const FormFields = {
16
13
  label: DefaultFields.label,
17
14
  id: DefaultFields.id,
18
15
  customtypes: {
19
- validate: () => yup.array().of(yup.string()),
16
+ validate: () => yup.array(),
20
17
  },
21
18
  };
22
19
 
23
20
  type FormProps = {
24
- config: { label: string; select: string; customtypes?: string[] };
21
+ config: {
22
+ label: string;
23
+ select: string;
24
+ customtypes?: LinkConfig["customtypes"];
25
+ };
25
26
  id: string;
26
- // type: string; // TODO: this exists in the yup schema but this doesn't seem to be validated by formik
27
+ // TODO: this exists in the yup schema but this doesn't seem to be validated by formik
27
28
  };
28
29
 
29
30
  const WidgetForm = ({
30
31
  initialValues,
31
- values: formValues,
32
- fields,
32
+ values,
33
33
  setFieldValue,
34
+ fields,
34
35
  }: FormikProps<FormProps> & { fields: Record<string, unknown> }) => {
35
- const customTypes = useSelector(selectAllCustomTypes).filter(hasLocal);
36
-
37
- const options = customTypes.map((ct) => ({
38
- value: ct.local.id,
39
- label: ct.local.label,
40
- }));
41
-
42
- const selectValues = formValues.config.customtypes
43
- ? formValues.config.customtypes.map((id) => {
44
- const ct = customTypes.find(
45
- (frontendCustomType) => frontendCustomType.local.id === id,
46
- );
47
- return { value: ct?.local.id, label: ct?.local.label };
48
- })
49
- : null;
50
-
51
36
  return (
52
- <FlexGrid>
53
- {Object.entries(FormFields)
54
- .filter((e) => e[0] !== "customtypes")
55
- .map(([key, field]) => (
56
- <Col key={key}>
57
- <WidgetFormField
58
- fieldName={createFieldNameFromKey(key)}
59
- formField={field}
60
- fields={fields}
61
- initialValues={initialValues}
62
- />
63
- </Col>
64
- ))}
65
- <Col>
66
- <Box
67
- sx={{
68
- mt: 2,
69
- alignItems: "center",
37
+ <>
38
+ <FlexGrid>
39
+ {Object.entries(FormFields)
40
+ .filter((e) => e[0] !== "customtypes")
41
+ .map(([key, field]) => (
42
+ <Col key={key}>
43
+ <WidgetFormField
44
+ fieldName={createFieldNameFromKey(key)}
45
+ formField={field}
46
+ fields={fields}
47
+ initialValues={initialValues}
48
+ />
49
+ </Col>
50
+ ))}
51
+ </FlexGrid>
52
+ <Box mt={20}>
53
+ <ContentRelationshipFieldPicker
54
+ value={values.config.customtypes}
55
+ onChange={(fields) => {
56
+ void setFieldValue("config.customtypes", fields);
70
57
  }}
71
- >
72
- <Label htmlFor="origin" mb="1">
73
- Types
74
- </Label>
75
- <Select
76
- isMulti
77
- name="origin"
78
- options={options}
79
- onChange={(v) => {
80
- // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
81
- if (v) {
82
- void setFieldValue(
83
- "config.customtypes",
84
- v.map(({ value }) => value),
85
- );
86
- }
87
- }}
88
- value={selectValues}
89
- theme={(theme) => {
90
- return {
91
- ...theme,
92
- colors: {
93
- ...theme.colors,
94
- text: "text",
95
- primary: "background",
96
- },
97
- };
98
- }}
99
- />
100
- </Box>
101
- </Col>
102
- </FlexGrid>
58
+ />
59
+ </Box>
60
+ </>
103
61
  );
104
62
  };
105
63
 
@@ -7,17 +7,44 @@ import { Widget } from "../Widget";
7
7
  import Form, { FormFields } from "./Form";
8
8
 
9
9
  /**
10
+ * Legacy:
11
+ * {
12
+ * "type": "Link",
13
+ * "config": {
14
+ * "select": "document",
15
+ * "label": "relationship"
16
+ * "customtypes": [
17
+ * "page"
18
+ * ],
19
+ * }
20
+ * }
21
+ *
22
+ * Current format (field picking):
10
23
  * {
11
- "type": "Link",
12
- "config": {
13
- "select": "document",
14
- "customtypes": [
15
- "page"
16
- ],
17
- "label": "relationship"
18
- }
19
- }
20
- */
24
+ * "type": "Link",
25
+ * "config": {
26
+ * "select": "document",
27
+ * "label": "relationship"
28
+ * "customtypes": [
29
+ * {
30
+ * "id": "page",
31
+ * "fields": [
32
+ * "category",
33
+ * {
34
+ * "id": "countryRelation",
35
+ * "customtypes": [
36
+ * {
37
+ * "id": "country",
38
+ * "fields": ["name"]
39
+ * }
40
+ * ]
41
+ * }
42
+ * ]
43
+ * }
44
+ * ],
45
+ * }
46
+ * }
47
+ */
21
48
 
22
49
  const Meta = {
23
50
  icon: MdSettingsEthernet,
@@ -30,7 +57,7 @@ const contentRelationShipConfigSchema = linkConfigSchema.shape({
30
57
  .string()
31
58
  .required()
32
59
  .matches(/^document$/, { excludeEmptyString: true }),
33
- customtypes: yup.array(yup.string()).strict().optional(),
60
+ customtypes: yup.array().optional(),
34
61
  });
35
62
 
36
63
  const schema = yup.object().shape({
@@ -43,12 +70,13 @@ const schema = yup.object().shape({
43
70
  });
44
71
 
45
72
  export const ContentRelationshipWidget: Widget<Link, typeof schema> = {
46
- create: (label: string) => ({
73
+ create: (label: string): Link => ({
47
74
  type: "Link",
48
75
  config: {
49
76
  label,
50
77
  select: "document",
51
78
  repeat: false,
79
+ customtypes: [],
52
80
  },
53
81
  }),
54
82
  Meta,
@@ -65,9 +93,12 @@ export const ContentRelationshipWidget: Widget<Link, typeof schema> = {
65
93
  return {
66
94
  ...initialValues,
67
95
  customtypes: initialValues.customtypes.filter((ct) =>
68
- customTypes.find(
69
- (frontendCustomType) => frontendCustomType.local.id === ct,
70
- ),
96
+ customTypes.find((frontendCustomType) => {
97
+ if (typeof ct === "string") {
98
+ return frontendCustomType.local.id === ct;
99
+ }
100
+ return frontendCustomType.local.id === ct.id;
101
+ }),
71
102
  ),
72
103
  };
73
104
  },
@@ -72,7 +72,7 @@ export const linkConfigSchema = yup
72
72
  .optional()
73
73
  .oneOf(["media", "document", "web", null])
74
74
  .nullable(),
75
- customtypes: yup.array(yup.string()).strict().optional(),
75
+ customtypes: yup.array().strict().optional(),
76
76
  masks: yup.array(yup.string()).optional(),
77
77
  tags: yup.array(yup.string()).optional(),
78
78
  allowTargetBlank: yup.boolean().strict().optional(),