Skip to content

Commit

Permalink
feat(sanity): add call to config from Structure
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Sep 30, 2024
1 parent 92b6071 commit 490e32e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const DocumentTitle = (props: {documentId: string; documentType: string}) => {
document.title = newTitle
}, [documentTitle, settled, newTitle])

throw new Error('This is an error from the structure tool')
return null
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {ErrorBoundary} from '@sanity/ui'
import {useEffect, useState} from 'react'
import {useCallback, useEffect, useState} from 'react'
import {SourceProvider, type Tool, useWorkspace} from 'sanity'

import {setActivePanes} from '../../getIntentState'
Expand All @@ -25,11 +25,24 @@ export function StructureToolBoundary({tool: {options}}: StructureToolBoundaryPr
}, [])

const [{error}, setError] = useState<{error: unknown}>({error: null})

const handleCatchError = useCallback(
({error: caughtError, info: caughtInfo}: {error: Error; info: React.ErrorInfo}) => {
setError({error: caughtError})
const {onStudioError} = firstSource

if (onStudioError) {
onStudioError(caughtError, caughtInfo)
}
},
[firstSource],
)

// this re-throws if the error it catches is not a PaneResolutionError
if (error) return <StructureError error={error} />

return (
<ErrorBoundary onCatch={setError}>
<ErrorBoundary onCatch={handleCatchError}>
<SourceProvider name={source || firstSource.name}>
<StructureToolProvider defaultDocumentNode={defaultDocumentNode} structure={structure}>
<StructureTool onPaneChange={setActivePanes} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@sanity/types'
import {Box, Card, type CardTone, ErrorBoundary, Flex, Stack, Text} from '@sanity/ui'
import {createElement, type ErrorInfo, Fragment, useCallback, useMemo, useState} from 'react'
import {type DocumentInspectorProps, useTranslation} from 'sanity'
import {type DocumentInspectorProps, useSource, useTranslation} from 'sanity'

import {DocumentInspectorHeader} from '../../documentInspector'
import {useDocumentPane} from '../../useDocumentPane'
Expand Down Expand Up @@ -44,6 +44,7 @@ export function ValidationInspector(props: DocumentInspectorProps) {
[onFocus, onPathOpen],
)

throw new Error('This is an error from the validation inspector')
return (
<Flex direction="column" height="fill" overflow="hidden">
<DocumentInspectorHeader
Expand Down

0 comments on commit 490e32e

Please sign in to comment.