"Removing mid section and accessing documents directly - desk structure issue"

27 replies
Last updated: Dec 3, 2021
Hi there, i need to remove this mid section and want to access documents directly. How to achieve this?
AI Update

Based on your question about removing the mid section and accessing documents directly, I believe you're asking how to customize the Structure tool (formerly Desk tool) in Sanity Studio to skip the default document type list and go straight to your documents.

You can achieve this by using the Structure Builder API to create a custom structure. Here's how:

1. Create a custom structure file (e.g., structure/index.ts):

import type {StructureResolver} from 'sanity/structure'

export const structure: StructureResolver = (S) =>
  S.list()
    .id('root')
    .title('Content')
    .items([
      S.documentTypeListItem('post').title('Blog Posts'),
      S.documentTypeListItem('author').title('Authors'),
      S.documentTypeListItem('category').title('Categories'),
      // Add your document types here
    ])

2. Import and configure it in your sanity.config.ts:

import {defineConfig} from 'sanity'
import {structureTool} from 'sanity/structure'
import {structure} from './structure'

export default defineConfig({
  // ...other config
  plugins: [
    structureTool({structure}),
    // ...other plugins
  ],
})

This replaces the default "all document types" view with your custom structure, giving you direct control over what appears and in what order. You can use S.documentTypeListItem() for simple document type lists, or go deeper with S.documentList() and GROQ filters to create filtered and grouped lists.

If you want even more control, you can create nested structures, custom views, or integrate custom React components to build exactly the navigation experience you need for your content team.

code:

const articleStruct = S.listItem()

.title('News')

.icon(ImNewspaper)

.child(

S.list()

.title('Articles')

.items([

S.documentTypeListItem('newsArticle').title('All News Articles').icon(ImNewspaper),


S.documentTypeListItem('latestNews').schemaType('latestNews').title('Latest News Articles').icon(ImNewspaper),


S.documentTypeListItem('featuredNews').schemaType('latestNews').title('Featured News Article').icon(ImNewspaper),

S.divider(),


S.documentTypeListItem('articleCategory').title('Article Categories').icon(FiList),

]),

);
Is this one specific document, or will the document change based on dynamic values elsewhere in the studio?
user H
this is due to different desk structure for latest and feature articles. Ive changed some and i got my desired results but now facing a warning.
missing id issue occuring
Hmm, I’ve only had that error the first time I create a defined page like this - it usually goes away after I publish the document.
facing same afetr publishing as well,
Try adding this to the bottom of your structure definition:
It will add an additional item only available in development that will list all document types.

process.env.NODE_ENV === "development"
				? S.listItem()
						.title("All Document Types")
						.child(
							S.list()
								.title("All Types")
								.items([
									// This returns an array of all the document types b
									// defined in schema.js. We filter out those that we have
									// defined the structure above
									...S.documentTypeListItems() /* .filter(hiddenDocTypes) */,
								]),
						)
				: S.divider()
With this you can navigate to your document type and see if your documents exist there.
Can you open inspect in the top right to view the documents JSON and show the oputput?
the weird thing is that these missing id doesn't exist in my model/schema. I have nowhere
featuredNewsArticle
and
latestNewsArticle
^^ The JSON output should help us understand this
ive added all docuements in structure and latest and feature news are showing
here's the code,


const articleStruct = S.listItem()

.title('News')

.icon(ImNewspaper)

.child(

S.list()

.title('Articles')

.items([

S.documentTypeListItem('newsArticle').title('All News Articles').icon(ImNewspaper),

S.documentListItem()

.schemaType('latestNews')

.title('Latest News Articles')

.icon(ImNewspaper)

.child(S.document().schemaType('latestNews').id('latestNews')),

S.documentListItem()

.schemaType('featuredNews')

.title('Featured News Article')

.icon(ImNewspaper)

.child(S.document().schemaType('featuredNews').id('featuredNews')),

//S.documentTypeListItem('latestNews').schemaType('latestNews').title('Latest News Articles').icon(ImNewspaper),

//S.documentTypeListItem('featuredNews').schemaType('latestNews').title('Featured News Article').icon(ImNewspaper),

S.divider(),

S.documentTypeListItem('articleCategory').title('Article Categories').icon(FiList),

]),

);
Could you go back to where you’re having the error.
• In the top right select inspect.
• Screenshot the parsed JSON
id is latestNews but on cms its showing missing id latestNewsArticles. 😶
Looks like you need to delete the document, then return to where you’re seeing the error and recreate it there.
OR change the id in the structure to match what it actually is
already changhed the id in structure but i guess i have to delete and recreate it. Can you share the doc delete cmd??
You can delete from the bottom right of the editor
ive deleted but same issue is there as you can see.
Yes - the UI is showing but you haven’t actually created it yet
its same,
it looks like desk structure issue,
Yeah, I’m not sure what’s wrong then.
Try setting an
id
on the document list item:

S.documentListItem()
  .id('featuredNews')
  .schemaType('featuredNews')
  .title('Featured News Article')
  .icon(ImNewspaper)
(if you don't have any custom needs for the child editor, you don't have to specify the
.child()
for what it's worth)
user Z
user H
i removed the id part in child and it fixed, 🤦‍♂️
user Z
user H
i removed the id part and it fixed, 🤦‍♂️

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?