How to define a singleton page in Studio v3 using Sanity.io

4 replies
Last updated: Dec 3, 2022
How to define a singleton page in Studio v3. Can anybody point me to an example?
Dec 2, 2022, 5:01 PM
Granted it's been a minute since I ported my test studio over, but you would define the Structure in the same way as you would for V2.
Then, to control deletion/duplication/creation of new documents you'd add something like the following to your config:

document: {
      newDocumentOptions: (prev, context) =>
        prev.filter(document => !singleEdits.includes(document.templateId)),
      actions: (prev, { schemaType }) => {
        if (singleEdits.includes(schemaType)) {
          return prev.filter(prevAction => prevAction.action == 'publish');
        }
        return prev;
      },
    },
Note that my
singleEdits
is an array of document types.
Dec 2, 2022, 8:50 PM
Could you show me the config file so I see this in context?
Dec 2, 2022, 9:15 PM
Yep!
export default createConfig([
  {
    name: 'default',
    title: 'studioDaddy',
    projectId: 'k8p6uw8a',
    dataset: 'development',
    basePath: '/',
    plugins: [
      deskTool({
        name: 'sandbox',
        title: 'Sanbox',
        icon: MdOutlineBugReport,
        structure: sandbox,
      }),
    ],
    tools: [],
    schema: {
      types: schemaTypes,
      templates: [],
    },
    document: {
      newDocumentOptions: (prev, context) =>
        prev.filter(document => !singleEdits.includes(document.templateId)),
      actions: (prev, { schemaType }) => {
        if (singleEdits.includes(schemaType)) {
          return prev.filter(prevAction => prevAction.action == 'publish');
        }
        return prev;
      },
    },
  },
]);
Dec 2, 2022, 11:41 PM
As you probably noted, I am a total Sanity noobie ๐Ÿ˜‰ I have this config file now but it does not change the
siteSettings
and
navigation
content types into Singletons. I can still create more copies. Any idea why?
import {defineConfig} from 'sanity'
import {deskTool} from 'sanity/desk'
import {schemaTypes} from './schemas'

const singleEdits = [
  { type: 'siteSettings' },
  { type: 'navigations' },
] 

export default defineConfig({
  name: 'default',
  title: 'ruhrpott-studio',
  projectId: '349a1vg2',
  dataset: 'production',
  plugins: [deskTool()],
  schema: {
    types: schemaTypes,
  },
  document: {
    newDocumentOptions: (prev, context) =>
      prev.filter(document => !singleEdits.includes(document.templateId)),
    actions: (prev, { schemaType }) => {
      if (singleEdits.includes(schemaType)) {
        return prev.filter(prevAction => prevAction.action == 'publish');
      }
      return prev;
    },
  },
});
Dec 3, 2022, 10:13 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?