How to disable the document action "duplicate" in Sanity?

2 replies
Last updated: Sep 11, 2023
Is it possible to disable the document action "duplicate" ?
AI Update

Yes, you can disable the duplicate document action! You can customize which document actions are available in Sanity Studio by creating a document actions resolver.

Here's how to disable the duplicate action:

// In your sanity.config.ts or sanity.config.js
import {defineConfig} from 'sanity'

export default defineConfig({
  // ... other config
  document: {
    actions: (prev, context) => {
      // Filter out the duplicate action
      return prev.filter((action) => action.action !== 'duplicate')
    }
  }
})

If you want to disable it only for specific document types, you can add conditional logic:

document: {
  actions: (prev, context) => {
    // Disable duplicate for specific document types
    if (context.schemaType === 'myDocumentType') {
      return prev.filter((action) => action.action !== 'duplicate')
    }
    return prev
  }
}

You can also be more selective by checking the action name directly:

import {DuplicateAction} from 'sanity'

document: {
  actions: (prev, context) => {
    return prev.filter((action) => action !== DuplicateAction)
  }
}

This approach works for any of the built-in document actions like PublishAction, UnpublishAction, DeleteAction, DuplicateAction, and DiscardAction. You can filter them out individually or combine multiple conditions to create the exact workflow you need for your content team.

Show original thread
2 replies
Yes, in your
sanity.config
you can filter the
prev
array that’s passed into your function. Here is an example of replacing one that can get you started.
Thanks.

  document: {
    actions: (prev) =>
      prev.map((originalAction) =>
        originalAction.action === 'duplicate' ? () => null : originalAction
      ),
  },
did the trick

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?