@sanity/assist 4.4.7 → 4.4.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/assist",
3
- "version": "4.4.7",
3
+ "version": "4.4.8",
4
4
  "description": "You create the instructions; Sanity AI Assist does the rest.",
5
5
  "keywords": [
6
6
  "sanity",
@@ -227,6 +227,49 @@ describe('conditionalMembers', () => {
227
227
  ])
228
228
  })
229
229
 
230
+ test('should include field with conditional state inside fieldset', () => {
231
+ const docSchema: ObjectSchemaType = Schema.compile({
232
+ name: 'test',
233
+ types: [
234
+ defineType({
235
+ type: 'document',
236
+ name: 'article',
237
+ fieldsets: [{name: 'set'}],
238
+ fields: [{type: 'string', fieldset: 'set', name: 'title', hidden: () => false}],
239
+ }),
240
+ ],
241
+ }).get('article')
242
+
243
+ const docState = {
244
+ path: [],
245
+ schemaType: docSchema,
246
+ members: [
247
+ {
248
+ kind: 'fieldSet',
249
+ fieldSet: {
250
+ name: 'set',
251
+ path: ['set'],
252
+ members: [
253
+ {
254
+ kind: 'field',
255
+ field: {path: [docSchema.fields[0].name], schemaType: docSchema.fields[0].type},
256
+ },
257
+ ],
258
+ },
259
+ },
260
+ ],
261
+ } as any
262
+ const conditionalMembers = getConditionalMembers(docState)
263
+
264
+ expect(conditionalMembers).toEqual([
265
+ {
266
+ path: 'title',
267
+ hidden: false,
268
+ readOnly: false,
269
+ },
270
+ ])
271
+ })
272
+
230
273
  test('should respect max-depth', () => {
231
274
  const docSchema: ObjectSchemaType = Schema.compile({
232
275
  name: 'test',
@@ -67,8 +67,8 @@ function conditionalState(memberState: {
67
67
  }): ConditionalMemberInnerState {
68
68
  return {
69
69
  path: pathToString(memberState.path),
70
- readOnly: !!memberState.readOnly,
71
- hidden: false, // if its in members, its not hidden
70
+ readOnly: !!memberState.readOnly, // Use actual form state readOnly value
71
+ hidden: false, // If it's in form state members, it's not hidden
72
72
  conditional: isConditional(memberState.schemaType),
73
73
  }
74
74
  }
@@ -124,7 +124,7 @@ function extractConditionalPaths(
124
124
  const innerFields = extractConditionalPaths(member.fieldSet, maxDepth).map((f) => ({
125
125
  ...f,
126
126
  // if fieldset is conditional, visible fields must also be considered conditional
127
- conditional: conditionalFieldset ?? f.conditional,
127
+ conditional: conditionalFieldset || f.conditional,
128
128
  }))
129
129
  return [...acc, ...innerFields]
130
130
  }