Skip to content

Commit

Permalink
fix(sanity): issue with selected state on header
Browse files Browse the repository at this point in the history
fix(sanity): issue with selected state on header
  • Loading branch information
RitaDias committed Oct 17, 2024
1 parent 53a1f4e commit 3edd0ad
Showing 1 changed file with 25 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Text} from '@sanity/ui'
import {memo, useCallback} from 'react'
import {
getVersionFromId,
isVersionId,
useBundles,
useDateTimeFormat,
usePerspective,
Expand All @@ -25,7 +26,7 @@ export const DocumentPerspectiveMenu = memo(function DocumentPerspectiveMenu() {
})
const {data: bundles, loading} = useBundles()

const {documentVersions, editState, displayed, documentType} = useDocumentPane()
const {documentVersions, editState, displayed, documentType, version} = useDocumentPane()

// remove the versions that the document already has
// remove the archived releases
Expand Down Expand Up @@ -59,20 +60,26 @@ export const DocumentPerspectiveMenu = memo(function DocumentPerspectiveMenu() {
}
disabled={!editState?.published}
onClick={handleBundleChange('published')}
selected={editState?.published?._id === displayed?._id}
selected={
editState?.published?._id === displayed?._id &&
Boolean(editState?.published) &&
Boolean(editState?.draft)
}
// eslint-disable-next-line @sanity/i18n/no-attribute-string-literals
text="Published"
icon={DotIcon}
tone="positive"
menuContent={
<VersionPopoverMenu
documentId={editState?.published?._id || ''}
menuReleaseId={editState?.published?._id || ''}
releases={filteredReleases}
releasesLoading={loading}
documentType={documentType}
fromRelease={''}
/>
editState?.published ? (
<VersionPopoverMenu
documentId={editState?.published?._id || ''}
menuReleaseId={editState?.published?._id || ''}
releases={filteredReleases}
releasesLoading={loading}
documentType={documentType}
fromRelease={''}
/>
) : null
}
/>
<VersionChip
Expand All @@ -94,17 +101,21 @@ export const DocumentPerspectiveMenu = memo(function DocumentPerspectiveMenu() {
)}
</Text>
}
disabled={!editState?.published && !editState?.draft}
icon={DotIcon}
selected={editState?.draft?._id === displayed?._id}
selected={
(editState?.draft?._id === displayed?._id ||
!editState?.draft ||
!editState?.published) &&
!isVersionId(displayed?._id || '')
}
// eslint-disable-next-line @sanity/i18n/no-attribute-string-literals
text="Draft"
tone="caution"
onClick={handleBundleChange('drafts')}
menuContent={
<VersionPopoverMenu
documentId={editState?.draft?._id || ''}
menuReleaseId={editState?.draft?._id || ''}
documentId={editState?.draft?._id || editState?.published?._id || ''}
menuReleaseId={editState?.draft?._id || editState?.published?._id || ''}
releases={filteredReleases}
releasesLoading={loading}
documentType={documentType}
Expand Down

0 comments on commit 3edd0ad

Please sign in to comment.