sanity icon indicating copy to clipboard operation
sanity copied to clipboard

Singleton Document Setup is Complex + [BUG] Its is still repeatable

Open surjithctly opened this issue 4 years ago • 10 comments
trafficstars

Describe the bug Creating a singleton document is really hard in Sanity. Just to make it non-ropeable, I had to create extra files & hours of finding proper docs, asking in the slack community etc.

To Reproduce

Steps to reproduce the behavior:

  1. Try to make a singleton document from scratch and see how complex it is.
  2. Click on the Top Edit button (Top-Left: just after name )
  3. Now click the option to add Document
  4. Click on the Singleton Type created
  5. We are still able to create new one

Expected behavior

It should not be able to add an array[] if its singleton, Also the configuration should be as simple using Schema. eg:

"repeatable": false

Screenshots image

So, please consider this issue and try to come up with a better solution.

Thank you. ~Surjith

surjithctly avatar Jan 29 '21 14:01 surjithctly

I also found it confusing to setup the desk interface especially when we also integrated intl-input plugin later on in the project.

raffij avatar Mar 18 '21 16:03 raffij

It's not well documented, if you've never done it before it takes like half an hour to figure this out

j2is avatar Aug 24 '21 12:08 j2is

https://www.sanity.io/docs/create-a-link-to-a-single-edit-page-in-your-main-document-type-list for anyone looking

j2is avatar Aug 24 '21 12:08 j2is

I use singleton's a lot, I'm only just looking into Sanity and I was surprised by the complexity needed to create one. I often try to put as much of the site content into the CMS as possible such as an about page etc.

TomSmedley avatar Dec 05 '21 15:12 TomSmedley

You're looking for...

__experimental_actions: ["update", /* 'create', 'delete', */ "publish"],

doublejosh avatar Feb 22 '22 19:02 doublejosh

It's been a year since this issue was created and Sanity still doesn't want to make the process any simpler? What a shame! Might have to consider another CMS if convenience is not Sanity wants to offer.

pexeixv avatar Jul 01 '22 17:07 pexeixv

@pexeixv I'm with you. But believe me, Sanity is the best CMS apart from these minor issues.

Now I can create singleton in 5 minutes even though its a hack. I'm used to it.

Steps:

  1. Create normal document
  2. Add some content
  3. Disable create & delete as @doublejosh said
  4. That's it

Here's how the code looks like: https://github.com/web3templates/stablo/blob/main/studio/schemas/siteConfig.js

Note: Make sure you add step 3 only after 1 & 2.

surjithctly avatar Jul 02 '22 06:07 surjithctly

@surjithctly, I did not understand what @doublejosh initially said. Thanks for elaborating on it. I will definitely use this hack for creating singleton documents.

pexeixv avatar Jul 02 '22 15:07 pexeixv

I've found the easiest way to create singletons is with the Sanity CLI. Create a .json with your types and ids:

[
  {
    "_id": "privacyPage",
    "_type": "privacyPage"
  },
  {
    "_id": "contactUsPage",
    "_type": "contactUsPage"
  },
  {
    "_id": "supportPage",
    "_type": "supportPage"
  }
]

Then from the CLI use sanity documents create myNewDocs.json

Then reference the document id in your Desk Structure, something like:

export default () =>
  S.list()
    .title("Root")
    .items([
      S.listItem()
        .title("Contact Us")
        .child(S.document().documentId("contactUsPage"))
    ])
        

JohnGemstone avatar Nov 27 '22 14:11 JohnGemstone