diff --git a/packages/@sanity/default-layout/src/components/SchemaErrorReporter.js b/packages/@sanity/default-layout/src/components/SchemaErrorReporter.js index f3c27a6083b..ddd9682282f 100644 --- a/packages/@sanity/default-layout/src/components/SchemaErrorReporter.js +++ b/packages/@sanity/default-layout/src/components/SchemaErrorReporter.js @@ -1,7 +1,7 @@ import React from 'react' import PropTypes from 'prop-types' import schema from 'part:@sanity/base/schema' -import {SchemaErrors} from './SchemaErrors' +import SchemaErrors from './SchemaErrors' function renderPath(path) { return path diff --git a/packages/@sanity/default-layout/src/components/SchemaErrors.js b/packages/@sanity/default-layout/src/components/SchemaErrors.js index eb78617df46..db3ef42ab0a 100644 --- a/packages/@sanity/default-layout/src/components/SchemaErrors.js +++ b/packages/@sanity/default-layout/src/components/SchemaErrors.js @@ -1,19 +1,22 @@ import React from 'react' -import styles from './styles/SchemaErrors.css' +import PropTypes from 'prop-types' import ErrorIcon from 'part:@sanity/base/error-icon' import WarningIcon from 'part:@sanity/base/warning-icon' import generateHelpUrl from '@sanity/generate-help-url' +import styles from './styles/SchemaErrors.css' function renderPath(path) { return path - .map(segment => { + .map((segment, i) => { + const key = `s_${i}` if (segment.kind === 'type') { return ( - + {segment.name} -   +   + {segment.type} @@ -21,14 +24,14 @@ function renderPath(path) { } if (segment.kind === 'property') { return ( - + {segment.name} ) } if (segment.kind === 'type') { return ( - + {segment.name} @@ -43,7 +46,7 @@ function renderPath(path) { .filter(Boolean) } -export function SchemaErrors(props) { +function SchemaErrors(props) { const {problemGroups} = props return (
@@ -51,11 +54,11 @@ export function SchemaErrors(props) {
    {problemGroups.map((group, i) => { return ( -
  • +
  • {renderPath(group.path)}

      {group.problems.map((problem, j) => ( -
    • +
    • {problem.severity === 'error' && } @@ -70,6 +73,7 @@ export function SchemaErrors(props) { className={styles.problemLink} href={generateHelpUrl(problem.helpId)} target="_blank" + rel="noopener noreferrer" > View documentation @@ -85,3 +89,24 @@ export function SchemaErrors(props) {
      ) } + +SchemaErrors.propTypes = { + problemGroups: PropTypes.arrayOf( + PropTypes.shape({ + path: PropTypes.arrayOf( + PropTypes.shape({ + kind: PropTypes.string, + type: PropTypes.string, + name: PropTypes.string + }) + ), + problems: PropTypes.arrayOf( + PropTypes.shape({ + severity: PropTypes.string + }) + ) + }).isRequired + ).isRequired +} + +export default SchemaErrors diff --git a/packages/@sanity/schema/src/sanity/validation/types/array.js b/packages/@sanity/schema/src/sanity/validation/types/array.js index 648526b8219..d2c383c1645 100644 --- a/packages/@sanity/schema/src/sanity/validation/types/array.js +++ b/packages/@sanity/schema/src/sanity/validation/types/array.js @@ -20,10 +20,25 @@ export default (typeDef, visitorContext) => { HELP_IDS.ARRAY_OF_INVALID ) ]) + const of = ofIsArray ? typeDef.of : [] + + // Don't allow object types without a name in block arrays + const hasObjectTypesWithoutName = of.some( + type => type.type === 'object' && typeof type.name === 'undefined' + ) + const hasBlockType = of.some(ofType => ofType.type === 'block') + if (hasBlockType && hasObjectTypesWithoutName) { + problems.push( + error( + "The array type's 'of' property can't have an object type without a 'name' property as member, when the 'block' type is also a member of that array.", + HELP_IDS.ARRAY_OF_INVALID + ) + ) + } return { ...typeDef, - of: (ofIsArray ? typeDef.of : []).map(visitorContext.visit), + of: of.map(visitorContext.visit), _problems: problems } }