Skip to content

Instantly share code, notes, and snippets.

@SimeonGriggs
Last active October 5, 2021 11:04
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 SimeonGriggs/1de3389cbfae5b58d51c4fe9f0bf3d48 to your computer and use it in GitHub Desktop.
Save SimeonGriggs/1de3389cbfae5b58d51c4fe9f0bf3d48 to your computer and use it in GitHub Desktop.
Call Objects using a function that will filter its child fields down to specific keys
const filteredObject = (name, filters = []) => ({
name,
type: 'object',
fields: [
{name: 'size', type: 'string', hidden: () => filters.includes('size')},
{name: 'tone', type: 'string', hidden: () => filters.includes('tone')}
]
})
export default {
name: 'article',
type: 'document',
fields: [
filteredObject('title', ['size', 'tone']),
filteredObject('subtitle', ['size'])
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment