Skip to content

Commit

Permalink
[structure] Check if "create"-action is enabled before infering templ…
Browse files Browse the repository at this point in the history
…ates
  • Loading branch information
rexxars committed Dec 3, 2019
1 parent adf1fbb commit 318d3c5
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/@sanity/structure/src/DocumentList.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {getParameterlessTemplatesBySchemaType} from '@sanity/initial-value-templates'
import {SchemaType} from './parts/Schema'
import {SchemaType, getDefaultSchema} from './parts/Schema'
import {isActionEnabled} from './parts/documentActionUtils'
import {client} from './parts/Client'
import {SortItem} from './Sort'
import {SerializeError, HELP_URL} from './SerializeError'
Expand Down Expand Up @@ -178,6 +179,7 @@ export class DocumentListBuilder extends GenericListBuilder<
function inferInitialValueTemplates(
spec: PartialDocumentList
): InitialValueTemplateItem[] | undefined {
const schema = getDefaultSchema()
const {schemaTypeName, options} = spec
const {filter, params} = options || {filter: '', params: {}}
const typeNames = schemaTypeName ? [schemaTypeName] : getTypeNamesFromFilter(filter, params)
Expand All @@ -188,6 +190,11 @@ function inferInitialValueTemplates(

let templateItems: InitialValueTemplateItem[] = []
return typeNames.reduce((items, typeName) => {
const schemaType = schema.get(typeName)
if (!isActionEnabled(schemaType, 'create')) {
return items
}

return items.concat(
getParameterlessTemplatesBySchemaType(typeName).map(
(tpl): InitialValueTemplateItem => ({
Expand Down

0 comments on commit 318d3c5

Please sign in to comment.