Created
October 22, 2021 15:25
-
-
Save d4rekanguok/477548814fc6c59104c158840a3ab966 to your computer and use it in GitHub Desktop.
Monkey patch document list to hide create menu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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