Skip to content

Commit

Permalink
fix(structure): add release title to archived banner
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin committed Dec 10, 2024
1 parent eb8e105 commit 3d2366a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/sanity/src/structure/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const structureLocaleStrings = defineLocalesResources('structure', {
'This document has live edit enabled and cannot be unpublished',
/** Description for the archived release banner, rendered when viewing the history of a version document from the publihed view */
'banners.archived-release.description':
"You are viewing a read-only document that was published in a release. It can't be edited",
"You are viewing a read-only document that was published as part of <VersionBadge> a release</VersionBadge>. It can't be edited",
/** The text for the restore button on the deleted document banner */
'banners.deleted-document-banner.restore-button.text': 'Restore most recent revision',
/** The text content for the deleted document banner */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import {Flex, Text} from '@sanity/ui'
import {useTranslation} from 'sanity'
import {useMemo} from 'react'
import {
getReleaseIdFromReleaseDocumentId,
getReleaseTone,
Translate,
useReleases,
useTranslation,
VersionInlineBadge,
} from 'sanity'
import {structureLocaleNamespace, usePaneRouter} from 'sanity/structure'

import {Banner} from './Banner'

export function ArchivedReleaseDocumentBanner(): JSX.Element {
const {t} = useTranslation(structureLocaleNamespace)
const {archivedReleases} = useReleases()

const {params, setParams} = usePaneRouter()
const handleGoBack = () => {
Expand All @@ -17,13 +26,33 @@ export function ArchivedReleaseDocumentBanner(): JSX.Element {
})
}

const release = useMemo(() => {
return archivedReleases.find(
(r) => getReleaseIdFromReleaseDocumentId(r._id) === params?.historyVersion,
)
}, [archivedReleases, params?.historyVersion])
return (
<Banner
tone="caution"
paddingY={2}
content={
<Flex align="center" justify="space-between" gap={1} flex={1}>
<Text size={1}>{t('banners.archived-release.description')}</Text>
<Text size={1}>
<Translate
t={t}
i18nKey="banners.archived-release.description"
components={{
VersionBadge: ({children}) => {
if (!release) return children
return (
<VersionInlineBadge $tone={getReleaseTone(release)}>
{release?.metadata.title}
</VersionInlineBadge>
)
},
}}
/>
</Text>
</Flex>
}
action={{
Expand Down

0 comments on commit 3d2366a

Please sign in to comment.