Go Behind the Experience to see how Tecovas brings the West to life with Sanity 🤠 July 18th

How to change the title of a document in Sanity's structure builder and how to make a schema type a singleton.

7 replies
Last updated: May 13, 2020
How do I in structure builder change the title of the document that is selected seen in this image
May 13, 2020, 4:21 PM
This is my structure so far
May 13, 2020, 4:22 PM
import S from "@sanity/desk-tool/structure-builder";

export default () =>
  // Make a new list item
  S.list()
    .title("Content")
    .items([
      S.listItem()
        .title("KM Posts")
        // This automatically gives it properties from the project type
        .schemaType("twentyTwentyKmPost")
        // When you open this list item, list out the documents
        // of the type "project"
        .child(S.documentTypeList("twentyTwentyKmPost").title("2020-2021")),
      S.listItem()
        .title("KT Posts")
        // This automatically gives it properties from the project type
        .schemaType("twentyTwentyKtPost")
        // When you open this list item, list out the documents
        // of the type "project"
        .child(S.documentTypeList("twentyTwentyKtPost").title("2020-2021")),
      S.listItem()
        .title("Slide Deck")
        // This automatically gives it properties from the project type
        .schemaType("slideDeck")
        // When you open this list item, list out the documents
        // of the type "project"
        .child(S.documentTypeList("slideDeck").title("Cards")),
      S.listItem()
        .title("Curriculum")
        // This automatically gives it properties from the project type
        .schemaType("curriculumPost")
        // When you open this list item, list out the documents
        // of the type "project"
        .child(S.documentTypeList("curriculumPost").title("Content")),
      S.listItem()
        // Give it a title
        .title("Archives")
        .child(
          // Make a list in the second pane called Portfolio
          S.list()
            .title("2010-2017")
            .items([
              // Add the first list item
              S.listItem()
                .title("2010 - 2011")
                // This automatically gives it properties from the project type
                .schemaType("twentyTenPost")
                // When you open this list item, list out the documents
                // of the type "project"
                .child(S.documentTypeList("twentyTenPost").title("Posts")),
              // Add a second list item
              S.listItem()
                .title("2011 - 2012")
                .schemaType("twentyElevenPost")
                // When you open this list item, list out the documents
                // of the type category"
                .child(S.documentTypeList("twentyElevenPost").title("Posts")),
              S.listItem()
                .title("2012 - 2013")
                .schemaType("twentyThirteenPost")
                // When you open this list item, list out the documents
                // of the type category"
                .child(S.documentTypeList("twentyThirteenPost").title("Posts")),
              S.listItem()
                .title("2014 - 2015")
                .schemaType("twentyFourteenPost")
                // When you open this list item, list out the documents
                // of the type category"
                .child(S.documentTypeList("twentyFourteenPost").title("Posts")),
              S.listItem()
                .title("2015 - 2016")
                .schemaType("twentyFifteenPost")
                // When you open this list item, list out the documents
                // of the type category"
                .child(S.documentTypeList("twentyFifteenPost").title("Posts")),
              S.listItem()
                .title("2016 - 2017")
                .schemaType("twentySixteenPost")
                // When you open this list item, list out the documents
                // of the type category"
                .child(S.documentTypeList("twentySixteenPost").title("Posts")),
              S.listItem()
                .title("2018 - 2019 KT")
                .schemaType("twentyEighteenKtPost")
                // When you open this list item, list out the documents
                // of the type category"
                .child(
                  S.documentTypeList("twentyEighteenKtPost").title("Posts")
                ),
              S.listItem()
                .title("2018 - 2019 KM")
                .schemaType("twentyEighteenKmPost")
                // When you open this list item, list out the documents
                // of the type category"
                .child(
                  S.documentTypeList("twentyEighteenKmPost").title("Posts")
                ),
              S.listItem()
                .title("2019 - 2020 KT")
                .schemaType("twentyNineteenKtPost")
                // When you open this list item, list out the documents
                // of the type category"
                .child(
                  S.documentTypeList("twentyNineteenKtPost").title("Posts")
                ),
              S.listItem()
                .title("2019 - 2020 KM")
                .schemaType("twentyNineteenKmPost")
                // When you open this list item, list out the documents
                // of the type category"
                .child(
                  S.documentTypeList("twentyNineteenKmPost").title("Posts")
                ),
            ])
        ),
    ]);
May 13, 2020, 4:22 PM
Also how would I make curriculumPost a singleton
May 13, 2020, 4:32 PM
I changed it to a singleton with
 S.listItem()
        .title("Curriculum Content")
        .child(
          S.document().schemaType("curriculumPost").documentId("curriculumPost")
        ),
and added this below

...S.documentTypeListItems().filter(
        (listItem) =>
          ![
            "curriculumPost",
            "slideDeck",
            "twentyEighteenKtPost",
            "twentyEighteenKmPost",
            "twentyTenPost",
            "twentyElevenPost",
            "twentyTwelvePost",
            "twentyThirteenPost",
            "twentyFourteenPost",
            "twentyFifteenPost",
            "twentySixteenPost",
            "twentySeventeenKtPost",
            "twentySeventeenKmPost",
            "twentyNineteenKmPost",
            "twentyNineteenKtPost",
            "twentyTwentyKmPost",
            "twentyTwentyKtPost",
          ].includes(listItem.getId())
      ),
but now the content from curriculum post is empty, it's like the filter is also taking away the content.
May 13, 2020, 4:46 PM
I changed it to a singleton with
 S.listItem()
        .title("Curriculum Content")
        .child(
          S.document().schemaType("curriculumPost").documentId("curriculumPost")
        ),
and added this below

...S.documentTypeListItems().filter(
        (listItem) =>
          ![
            "curriculumPost",
            "slideDeck",
            "twentyEighteenKtPost",
            "twentyEighteenKmPost",
            "twentyTenPost",
            "twentyElevenPost",
            "twentyTwelvePost",
            "twentyThirteenPost",
            "twentyFourteenPost",
            "twentyFifteenPost",
            "twentySixteenPost",
            "twentySeventeenKtPost",
            "twentySeventeenKmPost",
            "twentyNineteenKmPost",
            "twentyNineteenKtPost",
            "twentyTwentyKmPost",
            "twentyTwentyKtPost",
          ].includes(listItem.getId())
      ),
but now the content from curriculum post is empty, it's like the filter is also taking away the content.
May 13, 2020, 4:46 PM
Hi Anders, for the singleton, assuming you would like to open it directly in an editor/form view, have you tried something like this?
S.listItem()
  .title('Curriculum Content')
  .child(
    S.editor()
      .title('Curriculum Content')
      .schemaType('curriculumPost')
      .documentId('curriculumPost')
  ),
Also, have you confirmed that the singleton document itself actually has a document
_id
of
curriculumPost
? And not some random string?
May 13, 2020, 4:54 PM
I got it working, I think sanity was having a bug with having two posts in the singleton, I delete both of them just created one and then it acted as needed. I will also try your suggestion to see how that looks thanks
May 13, 2020, 5:01 PM

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?