Skip to content

Commit

Permalink
fix(core): fix array items not showing in field groups (#4930)
Browse files Browse the repository at this point in the history
* chore(core): add a debug schema for one off issue

* fix(core): fix array items not showing in field groups

* chore(debug): add a debug schema for nested field group
  • Loading branch information
binoy14 authored Oct 2, 2023
1 parent c672253 commit f55b7d8
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
91 changes: 89 additions & 2 deletions dev/test-studio/schema/debug/virtualizationDebug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export function MyField(props: FieldProps) {
)
}

const getAuthors = (client: SanityClient) => {
const query = `*[_type == "author"][0...20]{_id}`
const getAuthors = (client: SanityClient, limit = 20) => {
const query = `*[_type == "author"][0...${limit}]{_id}`

return client.fetch(query)
}
Expand All @@ -38,6 +38,14 @@ export const virtualizationDebug = defineType({
name: 'objects',
title: 'Objects',
},
{
name: 'singleItem',
title: 'Single Item test',
},
{
name: 'singleItemNested',
title: 'Single Item Nested Group',
},
],

fields: [
Expand Down Expand Up @@ -245,5 +253,84 @@ export const virtualizationDebug = defineType({
}),
],
}),
defineField({
name: 'arrayListSingleGroup',
title: 'Array List single item in group',
type: 'array',
group: 'singleItem',
of: [
{
type: 'reference',
to: [{type: 'author'}],
},
],
initialValue: async (_, context) => {
const {getClient} = context
const client = getClient({apiVersion: '2022-12-07'})
const authors = await getAuthors(client, 8)

return authors.map((author: any) => ({
_type: 'reference',
_ref: author._id,
}))
},
}),

defineField({
name: 'arrayInObjectNestedGroup',
title: 'Array in Object Arrays',
type: 'object',
group: 'singleItemNested',
options: {
collapsible: true,
},
groups: [
{
name: 'nestedGroup',
title: 'Nested Group',
},
],
fields: [
defineField({
name: 'arrayListNestedGroup',
title: 'Array List with no customization',
type: 'array',
of: [
{
type: 'playlist',
},
],
initialValue: () => {
const arr = new Array(10).fill(null)
return arr.map((_, i) => ({
_type: 'playlist',
name: `Playlist ${i}`,
}))
},
}),
defineField({
name: 'arrayListNestedSingleGroup',
title: 'Array List single item in nested group',
type: 'array',
group: 'nestedGroup',
of: [
{
type: 'reference',
to: [{type: 'author'}],
},
],
initialValue: async (_, context) => {
const {getClient} = context
const client = getClient({apiVersion: '2022-12-07'})
const authors = await getAuthors(client, 8)

return authors.map((author: any) => ({
_type: 'reference',
_ref: author._id,
}))
},
}),
],
}),
],
})
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export const DocumentPanel = function DocumentPanel(props: DocumentPanelProps) {
isDeleting,
isDeleted,
timelineStore,
formState,
} = useDocumentPane()
const {collapsed: layoutCollapsed} = usePaneLayout()
const {collapsed} = usePane()
Expand All @@ -75,6 +76,12 @@ export const DocumentPanel = function DocumentPanel(props: DocumentPanelProps) {

const requiredPermission = value._createdAt ? 'update' : 'create'

const selectedGroup = useMemo(() => {
if (!formState) return undefined

return formState.groups.find((group) => group.selected)
}, [formState])

const activeView = useMemo(
() => views.find((view) => view.id === activeViewId) || views[0] || {type: 'form'},
[activeViewId, views],
Expand Down Expand Up @@ -172,6 +179,10 @@ export const DocumentPanel = function DocumentPanel(props: DocumentPanelProps) {
$disabled={layoutCollapsed || false}
data-testid="document-panel-scroller"
ref={setDocumentScrollElement}
// Note: this is to make sure the scroll container is changed
// when the selected group changes which causes virtualization
// to re-render and re-measure the scroll container
key={`${selectedGroup?.name}-${documentId}}`}
>
<FormView
hidden={formViewHidden}
Expand Down

2 comments on commit f55b7d8

@vercel
Copy link

@vercel vercel bot commented on f55b7d8 Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio-git-next.sanity.build
performance-studio.sanity.build

@vercel
Copy link

@vercel vercel bot commented on f55b7d8 Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio.sanity.build
test-studio-git-next.sanity.build

Please sign in to comment.