Skip to content

Commit

Permalink
Merge branch 'corel' into corel-270-disable-non-active-release-add
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanl17 authored Nov 27, 2024
2 parents 4304865 + 157150f commit 0e4e00b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
18 changes: 14 additions & 4 deletions packages/sanity/src/core/releases/hooks/usePerspective.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useCallback, useMemo} from 'react'
import {useCallback, useEffect, useMemo} from 'react'
import {useRouter} from 'sanity/router'

import {resolveBundlePerspective} from '../../util/resolvePerspective'
Expand Down Expand Up @@ -50,7 +50,7 @@ const EMPTY_ARRAY: string[] = []
*/
export function usePerspective(): PerspectiveValue {
const router = useRouter()
const {data: releases} = useReleases()
const {data: releases, archivedReleases} = useReleases()
// TODO: Actually validate the perspective value, if it's not a valid perspective, we should fallback to undefined
const perspective = router.stickyParams.perspective as
| 'published'
Expand Down Expand Up @@ -84,11 +84,21 @@ export function usePerspective(): PerspectiveValue {
const selectedBundle =
perspective && releases
? releases.find(
(release: ReleaseDocument) =>
`bundle.${getBundleIdFromReleaseDocumentId(release._id)}` === perspective,
(release) => `bundle.${getBundleIdFromReleaseDocumentId(release._id)}` === perspective,
)
: LATEST

// clear the perspective param when it is not an active release
useEffect(() => {
if (
archivedReleases?.find(
(release) => `bundle.${getBundleIdFromReleaseDocumentId(release._id)}` === perspective,
)
) {
setPerspective(LATEST._id)
}
}, [archivedReleases, perspective, selectedBundle, setPerspective])

// TODO: Improve naming; this may not be global.
const currentGlobalBundle: CurrentPerspective = useMemo(
() => (perspective === 'published' ? perspective : selectedBundle || LATEST),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ export function DocumentStatusBar(props: DocumentStatusBarProps) {
>
<Flex align="center" flex={1} gap={collapsed ? 2 : 3} wrap="wrap" paddingRight={3}>
<Flex align="center">
{showingRevision ? (
<RevisionStatusLine />
) : (
<DocumentStatusLine singleLine={!collapsed} />
)}
{showingRevision ? <RevisionStatusLine /> : <DocumentStatusLine />}
<SpacerButton size="large" />
</Flex>
<DocumentBadges />
Expand Down

0 comments on commit 0e4e00b

Please sign in to comment.