-
Notifications
You must be signed in to change notification settings - Fork 428
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(sanity): open correct groups and fieldsets on
setOpenPath
- Loading branch information
Showing
8 changed files
with
214 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
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 | ||
field5: string | null | ||
nested: { | ||
field6: string | null | ||
field7: string | null | ||
field8: string | null | ||
} | null | ||
} | null | ||
}[] | ||
>( | ||
/* groq */ `*[_type == "fieldGroupsWithFieldsetsHidden"]{_id,field1,field2,nested{field3,field4,field5,nested{field6,field7,field8}}}`, | ||
) | ||
|
||
if (error) { | ||
throw error | ||
} | ||
|
||
if (loading) { | ||
return <p>Loading...</p> | ||
} | ||
|
||
return ( | ||
<Box paddingX={4}> | ||
{data?.map((item) => { | ||
return ( | ||
<Card key={item._id} padding={4}> | ||
<Stack space={4}> | ||
<Text weight={'bold'}>{item.field1 || 'N/A'}</Text> | ||
<Text weight={'bold'}>{item.field2 || 'N/A'}</Text> | ||
{item.nested && ( | ||
<Stack space={4} paddingLeft={2}> | ||
<Text>{item.nested.field3 || 'N/A'}</Text> | ||
<Text>{item.nested.field4 || 'N/A'}</Text> | ||
<Text>{item.nested.field5 || 'N/A'}</Text> | ||
{item.nested.nested && ( | ||
<Stack space={4} paddingLeft={2}> | ||
<Text>{item.nested.nested.field6 || 'N/A'}</Text> | ||
<Text>{item.nested.nested.field7 || 'N/A'}</Text> | ||
<Text>{item.nested.nested.field8 || 'N/A'}</Text> | ||
</Stack> | ||
)} | ||
</Stack> | ||
)} | ||
</Stack> | ||
</Card> | ||
) | ||
})} | ||
</Box> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
dev/test-studio/schema/debug/fieldGroupsWithFieldsetsHidden.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
const group = { | ||
name: 'group', | ||
title: 'Group', | ||
default: true, | ||
} | ||
const group2 = { | ||
name: 'group2', | ||
title: 'Group 2', | ||
} | ||
const fieldset = { | ||
name: 'fieldset', | ||
title: 'Fieldset', | ||
options: {collapsed: true}, | ||
} | ||
|
||
export default { | ||
name: 'fieldGroupsWithFieldsetsHidden', | ||
title: 'With default groups and collapsed fieldsets', | ||
type: 'document', | ||
groups: [group, group2], | ||
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, group2], | ||
fieldsets: [fieldset], | ||
fields: [ | ||
{ | ||
name: 'field3', | ||
type: 'string', | ||
fieldset: fieldset.name, | ||
}, | ||
{ | ||
name: 'field4', | ||
type: 'string', | ||
group: group.name, | ||
fieldset: fieldset.name, | ||
}, | ||
{ | ||
name: 'field5', | ||
type: 'string', | ||
group: group2.name, | ||
}, | ||
{ | ||
name: 'nested', | ||
type: 'object', | ||
group: group.name, | ||
fieldset: fieldset.name, | ||
groups: [group, group2], | ||
fieldsets: [fieldset], | ||
fields: [ | ||
{ | ||
name: 'field6', | ||
type: 'string', | ||
fieldset: fieldset.name, | ||
}, | ||
{ | ||
name: 'field7', | ||
type: 'string', | ||
group: group.name, | ||
fieldset: fieldset.name, | ||
}, | ||
{ | ||
name: 'field8', | ||
type: 'string', | ||
group: group2.name, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters