Skip to content

Commit

Permalink
fix(structure): revert structureTitle and DocumentPane changes for ve…
Browse files Browse the repository at this point in the history
…rsion checks
  • Loading branch information
pedrobonamin committed Sep 16, 2024
1 parent a54ebd0 commit 863527b
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,33 +216,5 @@ describe('StructureTitle', () => {
render(<StructureTitle resolvedPanes={mockPanes} />, {wrapper})
expect(document.title).toBe('Untitled | My Structure Tool')
})

it('does not update the title when the document is a version document, opts out to avoid breaking the id rules', async () => {
const useEditStateMock = () => editState
const useValuePreviewMock = () => valuePreview
jest.spyOn(SANITY, 'useSchema').mockImplementationOnce(useSchemaMock)
jest.spyOn(SANITY, 'useEditState').mockImplementationOnce(useEditStateMock)
jest.spyOn(SANITY, 'unstable_useValuePreview').mockImplementationOnce(useValuePreviewMock)

const client = createMockSanityClient()
const wrapper = await createWrapperComponent(client as any)

document.title = 'Sanity Studio'
render(
<StructureTitle
resolvedPanes={mockPanes.splice(3, 1, {
id: 'documentEditor',
type: 'document',
title: '',
options: {
id: 'versions.foo.fake-document',
type: 'author',
},
})}
/>,
{wrapper},
)
expect(document.title).toBe('Sanity Studio')
})
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {type ObjectSchemaType} from '@sanity/types'
import {useEffect} from 'react'
import {
isVersionId,
unstable_useValuePreview as useValuePreview,
useEditState,
useSchema,
Expand Down Expand Up @@ -66,6 +65,7 @@ export const StructureTitle = (props: StructureTitleProps) => {
if (!resolvedPanes?.length) return null

const lastPane = resolvedPanes[resolvedPanes.length - 1]

// If the last pane is loading, display the structure tool title only
if (isLoadingPane(lastPane)) {
return <PassthroughTitle />
Expand All @@ -77,11 +77,9 @@ export const StructureTitle = (props: StructureTitleProps) => {
if (lastPane?.title) {
return <PassthroughTitle title={lastPane.title} />
}
const documentId = lastPane.options.id
// noop if the documentId is a versionId - it's an error if we reach this point
if (isVersionId(documentId)) return null

// Otherwise, display a `document.title` containing the resolved Sanity document title
return <DocumentTitle documentId={documentId} documentType={lastPane.options.type} />
return <DocumentTitle documentId={lastPane.options.id} documentType={lastPane.options.type} />
}

// Otherwise, display the last pane's title (if present)
Expand Down
5 changes: 0 additions & 5 deletions packages/sanity/src/structure/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -381,11 +381,6 @@ const structureLocaleStrings = defineLocalesResources('structure', {
'The document type is not defined, and a document with the <Code>{{id}}</Code> identifier could not be found.',
/** The title of the document not found pane if the schema is known */
'panes.document-pane.document-not-found.title': 'The document was not found',
/** The title of the document not found pane if the schema is known */
'panes.document-pane.document-not-supported-version.text':
'This document was created using a more recent version of the studio which supports releases, please update your studio to edit this document.',
/** The title of the document not found pane if the schema is known */
'panes.document-pane.document-not-supported-version.title': 'Unsupported version document',
/** The text of the document not found pane if the schema is not found */
'panes.document-pane.document-unknown-type.text':
'This document has the schema type <Code>{{documentType}}</Code>, which is not defined as a type in the local content studio schema.',
Expand Down
16 changes: 1 addition & 15 deletions packages/sanity/src/structure/panes/document/DocumentPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {fromString as pathFromString} from '@sanity/util/paths'
import {memo, useMemo} from 'react'
import {
CopyPasteProvider,
isVersionId,
ReferenceInputOptionsProvider,
SourceProvider,
Translate,
Expand Down Expand Up @@ -126,20 +125,7 @@ function DocumentPaneInner(props: DocumentPaneProviderProps) {
</ErrorPane>
)
}
if (isVersionId(options.id)) {
return (
<ErrorPane
flex={2.5}
minWidth={320}
paneKey={paneKey}
title={t('panes.document-pane.document-not-supported-version.title')}
>
<Stack space={4}>
<Text as="p">{t('panes.document-pane.document-not-supported-version.text')}</Text>
</Stack>
</ErrorPane>
)
}

return (
<DocumentPaneProvider
// this needs to be here to avoid formState from being re-used across (incompatible) document types
Expand Down

0 comments on commit 863527b

Please sign in to comment.