Skip to content

Instantly share code, notes, and snippets.

@d4rekanguok
Created October 22, 2021 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d4rekanguok/477548814fc6c59104c158840a3ab966 to your computer and use it in GitHub Desktop.
Save d4rekanguok/477548814fc6c59104c158840a3ab966 to your computer and use it in GitHub Desktop.
Monkey patch document list to hide create menu
import S from '@sanity/desk-tool/structure-builder'
const DocumentListSansCreate = ({ title, filter }) => {
const _documentList = S.documentList()
.title(title)
.filter(filter)
_documentList.__serialize = _documentList.serialize.bind(_documentList)
_documentList.serialize = (...args) => {
const { menuItems, ...rest } = _documentList.__serialize(...args)
const createMenuIdx = menuItems.findIndex(({ intent }) => intent.type === 'create')
menuItems.splice(createMenuIdx, 1)
return {
menuItems,
...rest,
}
}
return _documentList
}
const PostList = () =>
S.listItem()
.title('Posts')
.child(
DocumentListSansCreate({
title: 'Post',
filter: '_type in ["post"]',
})
)
export default () => {
return S.list()
.title('Content')
.items([
PostList(),
/* etc */
])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment