diff --git a/dev/test-studio/preview/FieldGroups.tsx b/dev/test-studio/preview/FieldGroups.tsx new file mode 100644 index 000000000000..e05cde6c5746 --- /dev/null +++ b/dev/test-studio/preview/FieldGroups.tsx @@ -0,0 +1,48 @@ +import {Box, Card, Stack, Text} from '@sanity/ui' + +import {useQuery} from './loader' + +export function FieldGroups(): JSX.Element { + const {data, loading, error} = useQuery< + { + _id: string + field1: string | null + field2: string | null + nested: { + field3: string | null + field4: string | null + } | null + }[] + >( + /* groq */ `*[_type == "fieldGroupsWithFieldsetsHidden"]{_id,field1,field2,nested{field3,field4}}`, + ) + + if (error) { + throw error + } + + if (loading) { + return

Loading...

+ } + + return ( + + {data?.map((item) => { + return ( + + + {item.field1 || 'Not Set'} + {item.field2 || 'Not Set'} + {item.nested && ( + + {item.nested.field3 || 'Not Set'} + {item.nested.field4 || 'Not Set'} + + )} + + + ) + })} + + ) +} diff --git a/dev/test-studio/preview/main.tsx b/dev/test-studio/preview/main.tsx index 2d8b6eac32ef..7fb32fa58a77 100644 --- a/dev/test-studio/preview/main.tsx +++ b/dev/test-studio/preview/main.tsx @@ -1,14 +1,51 @@ +import {Box, Flex, studioTheme, Tab, TabList, TabPanel, ThemeProvider} from '@sanity/ui' import {enableVisualEditing} from '@sanity/visual-editing' -import {Suspense, useEffect} from 'react' +import {Suspense, useEffect, useState} from 'react' import {createRoot} from 'react-dom/client' +import {FieldGroups} from './FieldGroups' import {useLiveMode} from './loader' import {SimpleBlockPortableText} from './SimpleBlockPortableText' function Main() { + const [id, setId] = useState('simple') return ( <> - + + + + + setId('simple')} + selected={id === 'simple'} + /> + setId('nested')} + selected={id === 'nested'} + /> + + + + {id === 'simple' && ( + + + + )} + + {id === 'nested' && ( + + + + )} + + + diff --git a/dev/test-studio/schema/debug/fieldGroupsWithFieldsetsHidden.js b/dev/test-studio/schema/debug/fieldGroupsWithFieldsetsHidden.js new file mode 100644 index 000000000000..f0a9d2f8403b --- /dev/null +++ b/dev/test-studio/schema/debug/fieldGroupsWithFieldsetsHidden.js @@ -0,0 +1,50 @@ +const group = { + name: 'group', + title: 'Group', + default: true, +} +const fieldset = { + name: 'fieldset', + title: 'Fieldset', + options: {collapsed: true}, +} + +export default { + name: 'fieldGroupsWithFieldsetsHidden', + title: 'With default groups and collapsed fieldsets', + type: 'document', + groups: [group], + fieldsets: [fieldset], + fields: [ + { + name: 'field1', + type: 'string', + }, + { + name: 'field2', + type: 'string', + group: group.name, + fieldset: fieldset.name, + }, + { + name: 'nested', + type: 'object', + group: group.name, + fieldset: fieldset.name, + groups: [group], + fieldsets: [fieldset], + fields: [ + { + name: 'field3', + type: 'string', + fieldset: fieldset.name, + }, + { + name: 'field4', + type: 'string', + group: group.name, + }, + ], + }, + ], +} diff --git a/dev/test-studio/schema/index.ts b/dev/test-studio/schema/index.ts index 7edf1e4a58ff..8f8667146329 100644 --- a/dev/test-studio/schema/index.ts +++ b/dev/test-studio/schema/index.ts @@ -32,6 +32,7 @@ import fieldGroupsDefault from './debug/fieldGroupsDefault' import fieldGroupsMany from './debug/fieldGroupsMany' import fieldGroupsWithFieldsets from './debug/fieldGroupsWithFieldsets' import fieldGroupsWithFieldsetsAndValidation from './debug/fieldGroupsWithFieldsetsAndValidation' +import fieldGroupsWithFieldsetsHidden from './debug/fieldGroupsWithFieldsetsHidden' import fieldGroupsWithI18n from './debug/fieldGroupsWithI18n' import fieldGroupsWithValidation from './debug/fieldGroupsWithValidation' import fieldsets from './debug/fieldsets' @@ -253,6 +254,7 @@ export const schemaTypes = [ fieldGroupsWithI18n, fieldGroupsWithValidation, fieldGroupsWithFieldsetsAndValidation, + fieldGroupsWithFieldsetsHidden, virtualizationInObject, virtualizationDebug, diff --git a/dev/test-studio/structure/constants.ts b/dev/test-studio/structure/constants.ts index fbbc480ed0d0..ffcdea6447a4 100644 --- a/dev/test-studio/structure/constants.ts +++ b/dev/test-studio/structure/constants.ts @@ -98,6 +98,7 @@ export const DEBUG_FIELD_GROUP_TYPES = [ 'fieldGroupsWithValidation', 'fieldGroupsWithFieldsets', 'fieldGroupsWithFieldsetsAndValidation', + 'fieldGroupsWithFieldsetsHidden', ] export const EXTERNAL_PLUGIN_INPUT_TYPES = ['markdownTest', 'muxVideoPost'] diff --git a/packages/sanity/src/core/form/store/formState.ts b/packages/sanity/src/core/form/store/formState.ts index 6862208ddcdd..4889860b75e3 100644 --- a/packages/sanity/src/core/form/store/formState.ts +++ b/packages/sanity/src/core/form/store/formState.ts @@ -761,7 +761,7 @@ function prepareObjectInputState( } Object.defineProperty(node, '_allMembers', { value: members, - enumerable: false, + enumerable: true, }) return node } diff --git a/packages/sanity/src/core/form/store/utils/getExpandOperations.ts b/packages/sanity/src/core/form/store/utils/getExpandOperations.ts index be285de9c1c3..7ee62b11e62a 100644 --- a/packages/sanity/src/core/form/store/utils/getExpandOperations.ts +++ b/packages/sanity/src/core/form/store/utils/getExpandOperations.ts @@ -107,7 +107,6 @@ function getObjectFieldsetAndFieldGroupOperations( // Group handling const schemaField = node.schemaType.fields.find((field) => field.name === fieldName) const selectedGroupName = node.groups.find((group) => group.selected)?.name - const defaultGroupName = (node.schemaType.groups || []).find((group) => group.default)?.name const inSelectedGroup = selectedGroupName && (selectedGroupName === ALL_FIELDS_GROUP.name || @@ -116,10 +115,12 @@ function getObjectFieldsetAndFieldGroupOperations( const ops: (ExpandFieldSetOperation | SetActiveGroupOperation)[] = [] if (!inSelectedGroup) { + const groupName = + node.groups.find((group) => group.name === schemaField?.group)?.name || ALL_FIELDS_GROUP.name ops.push({ type: 'setSelectedGroup', path: node.path, - groupName: defaultGroupName || ALL_FIELDS_GROUP.name, + groupName, }) }