sanity-io / sanity

Sanity Studio – Rapidly configure content workspaces powered by structured content
https://www.sanity.io
MIT License
5.18k stars 418 forks source link

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

Open surjithctly opened 3 years ago

surjithctly commented 3 years ago

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

raffij commented 3 years ago

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

j2is commented 3 years ago

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

j2is commented 3 years ago

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

TomSmedley commented 2 years ago

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.

doublejosh commented 2 years ago

You're looking for...

__experimental_actions: ["update", /* 'create', 'delete', */ "publish"],
pexeixv commented 2 years ago

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.

surjithctly commented 2 years ago

@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.

pexeixv commented 2 years ago

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

JohnGemstone commented 1 year ago

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"))
    ])