Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

How would I go about making a document type not deletable? I’ve come as far as adding only once instance to the structurebuilder but it’s still possible to duplicate anddelete...

8 replies
Last updated: Feb 1, 2021
How would I go about making a document type not deletable? I’ve come as far as adding only once instance to the structurebuilder but it’s still possible to duplicate and delete it. Tried with the following: “__experimental_actions: [“update”, /* ‘create’, ‘delete’, */ “publish”],” but it didn’t do anything for it.
Feb 1, 2021, 1:29 PM
you can set up custom document actions https://www.sanity.io/docs/document-actions and filter out the DeleteAction. Something like this:

import { DeleteAction } from "part:@sanity/base/document-actions";

export default function resolveDocumentActions(props) {
  if (props.type === "something") {
    return defaultResolve(props).filter(
      (Action) => Action !== DeleteAction
    );
  }
}
Feb 1, 2021, 1:32 PM
Thanks Arjen. That did it for me, I made the following solution:
import defaultResolve from "part:@sanity/base/document-actions";
import { DeleteAction } from "part:@sanity/base/document-actions";

export default function resolveDocumentActions(props) {
  if (props.type === "siteSettings") {
    return [
      ...defaultResolve(props).filter((Action) => Action !== DeleteAction),
    ];
  }
  return [...defaultResolve(props)];
}
Feb 1, 2021, 1:39 PM
user B
Is it possible not to show that menu entirely instead of just delete action? Can’t find it in the API docs
Feb 1, 2021, 1:40 PM
return an empty array?
Feb 1, 2021, 1:41 PM
user B
I tried that but then the publish button disappears
Feb 1, 2021, 1:41 PM
only return the publish action then?

return [PublishAction]
or maybe even

return PublishAction
haven't tried it
Feb 1, 2021, 1:42 PM
Thanks I was missing the name of it
user B
couldnt find it in the docs
Feb 1, 2021, 1:59 PM
This did the trick:
return [
      ...defaultResolve(props).filter((Action) => Action === PublishAction),
    ];
Feb 1, 2021, 1:59 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?