Skip to content

Commit

Permalink
feat: warn on unknown schema type
Browse files Browse the repository at this point in the history
  • Loading branch information
nkgentile authored and snorrees committed Feb 2, 2023
1 parent f719abf commit 755ef81
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Documents.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React, {useCallback} from 'react'
import {Box, Button, Stack, Flex, Spinner} from '@sanity/ui'
import {Box, Button, Stack, Flex, Spinner, Card} from '@sanity/ui'
import {fromString as pathFromString} from '@sanity/util/paths'
import {Preview, useSchema} from 'sanity'
import {Preview, useSchema, DefaultPreview} from 'sanity'
import {usePaneRouter} from 'sanity/desk'
import {WarningOutlineIcon} from '@sanity/icons'

import Debug from './Debug'
import Feedback from './Feedback'
Expand Down Expand Up @@ -77,10 +78,8 @@ export default function Documents(props: DocumentsProps) {
<Stack padding={2} space={1}>
{data.map((doc) => {
const schemaType = schema.get(doc._type)
if (!schemaType) {
return null
}
return (

return schemaType ? (
<Button
key={doc._id}
onClick={() => handleClick(doc._id, doc._type)}
Expand All @@ -89,6 +88,14 @@ export default function Documents(props: DocumentsProps) {
>
<Preview value={doc} schemaType={schemaType} />
</Button>
) : (
<Card radius={2} tone="caution" data-ui="Alert" padding={2} key={doc._id}>
<DefaultPreview
media={<WarningOutlineIcon />}
title="Unknown schema type found"
subtitle={`Encountered type "${doc._type}" that is not defined in the schema.`}
/>
</Card>
)
})}
</Stack>
Expand Down

0 comments on commit 755ef81

Please sign in to comment.