When Should the `.documentId` Parameter be Added to the Desk Structure Schema?
7 replies
Last updated: Apr 13, 2022
R
Hey everyone! I have a question about how to properly build my
Anyway, my question is when should I add in the
Meanwhile my
Any clarification on this would be really helpful. I have tried reading the docs to find the answer, but I am still confused on this aspect of Sanity.
desk-structureschema.. I am in the process of updating my Sanity Studio for an open-source project to make it more organized and and I have somewhat referencing the https://github.com/sanity-io/sanity-shopify-studio
deskstructure..
Anyway, my question is when should I add in the
.documentIdparameter? So far my desk structure schema works, but I have actually always been confused about when to actually use this (even though I've been using Sanity for a couple years now lol). For instance I have a
home.jsfile that is fed into my
desk-structure.jsfile:
home.js
import S from '@sanity/desk-tool/structure-builder' // Icons import { House, } from 'phosphor-react' export const home = S.listItem() .title('Home') .icon(House) .child( S.document() .title('Home Page') .schemaType('landingPage') )
desk-structure.js
import S from '@sanity/desk-tool/structure-builder' import { home } from './desk/home' import { pages } from './desk/pages' import { articles } from './desk/articles' import { authors } from './desk/authors' import { settings } from './desk/settings' // Doc types const hiddenDocTypes = (listItem) => ![ 'landingPage', 'page', 'article', 'author', 'headerSettings', 'footerSettings', 'seoSettings', 'promoSettings', 'cookieSettings' ].includes(listItem.getId()) export default () => S.list() .title('Content') .items([ home, pages, articles, S.divider(), authors, S.divider(), settings, // Filter out docs already defined above ...S.documentTypeListItems().filter(hiddenDocTypes) ])
settings.jscontains the
.documentIdparameter (and I dont really know why I should have it in here and not in my
home.jsas well?):
import S from '@sanity/desk-tool/structure-builder' // Icons import { Sliders, NavigationArrow, List, Globe, FlagBanner, Cookie } from 'phosphor-react' export const settings = S.listItem() .title('Settings') .icon(Sliders) .child( S.list() .title('Settings') .items([ S.listItem() .title('Header') .icon(NavigationArrow) .child( S.editor() .schemaType('headerSettings') .documentId('headerSettings') ), ...etc.
Apr 13, 2022, 7:15 PM
R
Hey
Yes the only single document I have is my
Here is my schema now: (which breaks my page-builder)
It seems it works better not using
user M
thanks for getting back to me! Actually my settings.jsis made up of many document items.. (I added in the ...etc. to indicate this, but I just didn't want to post a long code bracket lol).
Yes the only single document I have is my
landingPagewhich does not have a
.documentId. Here is the weird thing though.. When I add in a
.documentIdto my
home.jsmy page builder seems to break.. I attached a short screen grab of this.
Here is my schema now: (which breaks my page-builder)
import S from '@sanity/desk-tool/structure-builder' // Icons import { House, } from 'phosphor-react' export const home = S.listItem() .title('Home') .icon(House) .child( S.document() .title('Home Page') .schemaType('landingPage') .documentId('landingPage') )
.documentId
Apr 13, 2022, 7:52 PM
R
yeah idk what is going on lol.. After an hour messing around with it adding in
.documentIdbreaks my page builder schema lol.. I mean it working though (and also works on live) so I guess its okay? I am just not sure whats going on lol
Apr 13, 2022, 9:48 PM
R
Ah, so the Studio doesn't break, but your frontend stops responding to the changes. I'm guessing that the singleton you're editing before adding in the document ID is a different document, maybe? How are you querying for it?
Apr 13, 2022, 9:52 PM
R
Yeah thats exactly whats going on! Hmm no I am editing the correct singleton.. Let me share the repo. This is for my open-source Gridsome/Shopify project using Sanity: https://github.com/rylanharper/BELRAD I am just trying to touch up the studio to make it more accessible.
The issue is with the
The issue is with the
home.jsschema here . And I am querying the data in my
Index.vue(using Graphql) here with a content-section builder using the
_typefrom the Sanity schema found here . Lol again the website it working on my development sever and on live so nothing is technically wrong.. Its just that it my
home.jsdesk schema seems to break when I add in a
documentIdwhich is really weird.
Apr 13, 2022, 10:16 PM
R
Hmm okay so I have been messing around and there is definitely something wrong with my landing page schema.. I changed the
landingPagedocument to
homePage(and also changed the name within my
schema.jsand
desk-structure.js) and now I get the following message
This document is of type landingPage and cannot be edited as homePage.However, upon inspecting the document the id is
homePagebut the _type is
landingPage.. I just have no clue whats going on π
Apr 13, 2022, 11:14 PM
R
user M
I FIGURED IT OUT!! Lol this all was a really dumb mistake π€¦ββοΈ.. It turns out that I never actually deleted the original document I was editing.. So even back when I was editing my landingPage(now homePage) and added in the
.documentIdto the schema I was actually editing the old document. To fix it I just had to go to the bottom and delete the document and then create a new one.. Now my page-builder is working. I am so sorry to waste your time with this.. It was just a dumb mistake/error on my end
Apr 13, 2022, 11:36 PM
R
No worries! Very happy to be your rubber duck as you worked it out :rubberduck: !
Apr 13, 2022, 11:50 PM
Sanity.io β build remarkable experiences at scale
Sanity is a customizable solution that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.