Sanity desk structure missing "Create new" button for custom document type

3 replies
Last updated: Mar 25, 2021
Hey guys, I have created a field (Page/Pages) for my menu. But for some reason it is not showing “Create a new page” option. This works for my different field types. Any idea? Create new document for this type is missing. No errors but It is showing up in the menu.
Page field:


import { UniqueSlug } from "../../lib/helpers";


export default {

name: "page",

title: "Pages",

type: "document",

fields: [

{

title: "Naslov",

name: "title",

type: "string",

validation: (Rule) => Rule.required().error("Naslov je obavezan"),

},

{

name: "slug",

title: "Slug",

type: "slug",

validation: (Rule) => Rule.error("Slug/Link je već u upotrebi"),

options: {

source: "title",

maxLength: 100,

slugify: (input) =>

input.toLowerCase().replace(/\s+/g, "-").slice(0, 100),

isUnique: UniqueSlug,

},

},

{

name: "autor",

title: "Autor",

type: "reference",

to: { type: "autor" },

},

{

name: "mainImage",

title: "Glavna slika",

type: "image",

fields: [

{

title: "Alternativni tekst",

name: "alt",

type: "string",

validation: (Rule) =>

Rule.required().error("Alternativni tekst je obavezan"),

},

],

options: {

hotspot: true,

accept: "image/*",

},

validation: (Rule) =>

Rule.custom(async (image) => {

// short circuit if no image

if (!image) return true;

`const result = await client.fetch(
*[_id == $id][0].size
, {`
id: image.asset._ref,

});


return result <= 1_000_000 || "1MB je limit slike.";

}),

},

{

name: "publishedAt",

title: "Objavljeno u",

type: "datetime",

},

{

name: "body",

title: "Sadržaj",

type: "blockContent",

},

],

preview: {

select: {

title: "title",

author: "autor.name",

publishedAt: "publishedAt",

media: "mainImage",

},


prepare(selection) {

const { author, title = "Nema naslova", publishedAt } = selection;


return Object.assign({}, selection, {

title,

subtitle:

publishedAt &&
```

Datum objave ${publishedAt}
,

      
});`
},

},

};


My desk structure:


// deskStructure.js

import S from "@sanity/desk-tool/structure-builder";


import {

IoFastFoodOutline,

IoPersonOutline,

IoTicketOutline,

IoSettingsOutline,

IoDocumentTextOutline,

} from "react-icons/io5";


export default () =>

S.list()

.title("Sadržaj")

.items([

S.listItem()

.title("Pages")

.icon(IoDocumentTextOutline)

.schemaType("page")

.child(S.documentTypeList("page").title("Pages")),


S.listItem()

.title("Recepti")

.icon(IoFastFoodOutline)

.schemaType("recept")

.child(S.documentTypeList("recept").title("Recepti")),


S.listItem()

.title("Kategorije")

.icon(IoTicketOutline)

.schemaType("category")

.child(S.documentTypeList("category").title("Kategorije")),


S.listItem()

.title("Autori")

.icon(IoPersonOutline)

.schemaType("autor")

.child(S.documentTypeList("autor").title("Autori")),


S.divider(),

S.listItem()

.title("Postavke")

.icon(IoSettingsOutline)

.child(

S.editor().schemaType("siteSettings").documentId("siteSettings")

),


`//
S.documentTypeListItems()
returns an array of all the document types`

// defined in schema.js. We filter out those that we have

// defined the structure above.

...S.documentTypeListItems().filter(

(listItem) =>

!["autor", "recept", "category", "siteSettings", "page"].includes(

listItem.getId()

)

),

]);
AI Update

Looking at your code, I can see you're using Sanity Studio v2 syntax (the @sanity/desk-tool/structure-builder import), which reached end-of-life on December 7, 2023. The missing "Create new" button is likely happening because of how v2's desk structure works - when you explicitly define a custom structure, you need to ensure the document type is properly configured.

However, before diving into a v2-specific fix, I'd strongly recommend upgrading to Studio v3, since v2 is no longer supported and won't receive security updates or bug fixes.

Quick Fix for v2 (if you must stay on v2 temporarily)

The issue in your current v2 setup is that when using .child(S.documentTypeList("page")), you need to make sure the create button is enabled. Try this modification:

S.listItem()
  .title("Pages")
  .icon(IoDocumentTextOutline)
  .schemaType("page")
  .child(
    S.documentTypeList("page")
      .title("Pages")
      .canHandleIntent(S.documentTypeList.canHandleIntent)
  ),

Also, double-check that your page document type doesn't have any configuration that might be hiding it from creation menus.

Better Solution: Migrate to Studio v3

Since Studio v2 support ended in December 2023, I'd recommend migrating to v3 where this pattern works more reliably. In v3, the structure configuration looks like this:

// structure/index.ts
import type {StructureResolver} from 'sanity/structure'
import {IoDocumentTextOutline, IoFastFoodOutline, IoTicketOutline, IoPersonOutline, IoSettingsOutline} from 'react-icons/io5'

export const structure: StructureResolver = (S) =>
  S.list()
    .title("Sadržaj")
    .items([
      S.documentTypeListItem("page")
        .title("Pages")
        .icon(IoDocumentTextOutline),
      
      S.documentTypeListItem("recept")
        .title("Recepti")
        .icon(IoFastFoodOutline),
      
      S.documentTypeListItem("category")
        .title("Kategorije")
        .icon(IoTicketOutline),
      
      S.documentTypeListItem("autor")
        .title("Autori")
        .icon(IoPersonOutline),
      
      S.divider(),
      
      S.listItem()
        .title("Postavke")
        .icon(IoSettingsOutline)
        .child(
          S.editor().schemaType("siteSettings").documentId("siteSettings")
        ),
      
      ...S.documentTypeListItems().filter(
        (listItem) =>
          !["autor", "recept", "category", "siteSettings", "page"].includes(
            listItem.getId()
          )
      ),
    ])

Then in your sanity.config.ts:

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

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

Notice in v3, the Structure Builder uses S.documentTypeListItem() as a convenience method - it automatically handles the create button, menu items, and initial value templates for you. This is cleaner and more reliable than the v2 pattern you're using with .listItem().child(S.documentTypeList()).

The migration guide will help you through the upgrade process. The main changes are moving from sanity.json to sanity.config.ts and updating import paths, but it's worth it for ongoing support and better functionality!

Show original thread
3 replies
Hey Nino, to be clear, all other types in this structure have a new document button except the
page
type, correct?
user M
Yes, that is correct! It is basically a copy of “recipes” but with a different name &amp; title and fields.
I am not sure if it is a bug. But it seems if you customize the “Create new document” to add icons. The “field/pages” will not show “Create new document” menu in the right corner. Very weird.. Basically it makes it required to also add that specific field to the “Create new document” otherwise the “Create new document” will not show up.
I’m glad you got it working!

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?