Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(presentation): remove explicit check for r in perspectives #8468

Merged
merged 2 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions packages/sanity/src/core/perspective/useSetPerspective.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,9 @@ export function useSetPerspective() {
const router = useRouter()
const setPerspective = useCallback(
(releaseId: 'published' | 'drafts' | ReleaseId | undefined) => {
let perspectiveParam = ''

if (!releaseId || releaseId === 'drafts') {
perspectiveParam = ''
} else if (releaseId === 'published' || releaseId.startsWith('r')) {
perspectiveParam = releaseId
} else {
throw new Error(`Invalid releaseId: ${releaseId}`)
}

router.navigateStickyParams({
excludedPerspectives: '',
perspective: perspectiveParam,
perspective: releaseId === 'drafts' ? '' : releaseId,
})
},
[router],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,5 @@ export function getReleaseIdFromReleaseDocumentId(releaseDocumentId: string): Re
)
}
const releaseId = releaseDocumentId.slice(PATH_ID_PREFIX.length)
if (!releaseId.startsWith('r')) {
throw new Error(`Release id was ${releaseId} but should start with "r"`)
}
return releaseId as ReleaseId
}
8 changes: 6 additions & 2 deletions packages/sanity/src/presentation/PresentationTool.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ export default function PresentationTool(props: {
state: PresentationStateParams
}
const routerSearchParams = useUnique(Object.fromEntries(routerState._searchParams || []))
const {perspectiveStack, selectedPerspectiveName = 'previewDrafts'} = usePerspective()
const {
perspectiveStack,
selectedPerspectiveName = 'previewDrafts',
selectedReleaseId,
} = usePerspective()
const perspective = (
selectedPerspectiveName.startsWith('r') ? perspectiveStack : selectedPerspectiveName
selectedReleaseId ? perspectiveStack : selectedPerspectiveName
) as PresentationPerspective

const initialPreviewUrl = usePreviewUrl(
Expand Down
Loading