"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?
Dec 2, 2021, 11:22 AM
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),

]),

);
Dec 2, 2021, 11:23 AM
Is this one specific document, or will the document change based on dynamic values elsewhere in the studio?
Dec 2, 2021, 11:52 AM
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.
Dec 2, 2021, 11:54 AM
missing id issue occuring
Dec 2, 2021, 11:55 AM
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.
Dec 2, 2021, 11:58 AM
facing same afetr publishing as well,
Dec 2, 2021, 11:59 AM
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.
Dec 2, 2021, 11:59 AM
Can you open inspect in the top right to view the documents JSON and show the oputput?
Dec 2, 2021, 12:00 PM
the weird thing is that these missing id doesn't exist in my model/schema. I have nowhere
featuredNewsArticle
and
latestNewsArticle
Dec 2, 2021, 12:00 PM
^^ The JSON output should help us understand this
Dec 2, 2021, 12:01 PM
ive added all docuements in structure and latest and feature news are showing
Dec 2, 2021, 12:05 PM
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),

]),

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

S.documentListItem()
  .id('featuredNews')
  .schemaType('featuredNews')
  .title('Featured News Article')
  .icon(ImNewspaper)
Dec 2, 2021, 4:38 PM
(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)
Dec 2, 2021, 4:39 PM
user Z
user H
i removed the id part in child and it fixed, 🤦‍♂️
Dec 3, 2021, 7:06 AM
user Z
user H
i removed the id part and it fixed, 🤦‍♂️
Dec 3, 2021, 7:06 AM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?