@sanity/personalization-plugin 2.3.0 → 2.4.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.
- package/dist/index.js +11 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/fieldExperiments.tsx +6 -5
- package/src/utils/flattenSchemaType.ts +11 -14
package/package.json
CHANGED
package/src/fieldExperiments.tsx
CHANGED
|
@@ -219,16 +219,17 @@ export const fieldLevelExperiments = definePlugin<FieldPluginConfig>((config) =>
|
|
|
219
219
|
return props.renderDefault(props)
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
222
|
+
const flatFields = flattenSchemaType(props.schemaType)
|
|
223
|
+
const hasExperiment = flatFields.some(
|
|
224
|
+
(field) =>
|
|
225
|
+
field.type.name.startsWith(experimentNameOverride) ||
|
|
226
|
+
field.name.startsWith(experimentNameOverride),
|
|
227
227
|
)
|
|
228
228
|
|
|
229
229
|
if (!hasExperiment) {
|
|
230
230
|
return props.renderDefault(props)
|
|
231
231
|
}
|
|
232
|
+
|
|
232
233
|
const providerProps = {
|
|
233
234
|
...props,
|
|
234
235
|
experimentFieldPluginConfig: {
|
|
@@ -11,7 +11,7 @@ export function flattenSchemaType(schemaType: SchemaType): ObjectFieldWithPath[]
|
|
|
11
11
|
return []
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
return extractInnerFields(schemaType.fields, [],
|
|
14
|
+
return extractInnerFields(schemaType.fields, [], 5)
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
function extractInnerFields(
|
|
@@ -28,20 +28,17 @@ function extractInnerFields(
|
|
|
28
28
|
|
|
29
29
|
if (field.type.jsonType === 'object') {
|
|
30
30
|
const innerFields = extractInnerFields(field.type.fields, [...path, field.name], maxDepth)
|
|
31
|
-
|
|
32
31
|
return [...acc, thisFieldWithPath, ...innerFields]
|
|
33
|
-
} else if (
|
|
34
|
-
|
|
35
|
-
field.type.of
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
)
|
|
44
|
-
|
|
32
|
+
} else if (field.type.jsonType === 'array') {
|
|
33
|
+
// Handle array types by checking each possible type in the array
|
|
34
|
+
const arrayTypes = field.type.of || []
|
|
35
|
+
const innerFields = arrayTypes.reduce<ObjectFieldWithPath[]>((arrayAcc, arrayType) => {
|
|
36
|
+
if ('fields' in arrayType) {
|
|
37
|
+
const typeFields = extractInnerFields(arrayType.fields, [...path, field.name], maxDepth)
|
|
38
|
+
return [...arrayAcc, ...typeFields]
|
|
39
|
+
}
|
|
40
|
+
return arrayAcc
|
|
41
|
+
}, [])
|
|
45
42
|
return [...acc, thisFieldWithPath, ...innerFields]
|
|
46
43
|
}
|
|
47
44
|
|