Skip to content

Commit

Permalink
fix(structure): enable published chip for live edit documents (#8000)
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobonamin authored Dec 10, 2024
1 parent 7b28097 commit 7406916
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
VersionChip,
versionDocumentExists,
} from 'sanity'
import {usePaneRouter} from 'sanity/structure'

import {useDocumentPane} from '../../../useDocumentPane'

Expand Down Expand Up @@ -71,7 +70,6 @@ export const DocumentPerspectiveList = memo(function DocumentPerspectiveList() {
dateStyle: 'medium',
timeStyle: 'short',
})
const {setParams, params} = usePaneRouter()
const {data: releases, loading} = useReleases()

const {documentVersions, editState, displayed, documentType} = useDocumentPane()
Expand Down Expand Up @@ -101,18 +99,12 @@ export const DocumentPerspectiveList = memo(function DocumentPerspectiveList() {
)

const isPublishedChipDisabled = useMemo(() => {
if (editState?.liveEdit) {
if (!editState?.published) {
return true
}
// If it's a live edit document the only option to edit it is through
// the published perspective, users should be able to select it.
if (editState?.liveEdit) return false

return false
}

if (!editState?.published) {
return true
}
return false
// If it's not live edit, we want to check for the existence of the published doc.
return !editState?.published
}, [editState?.liveEdit, editState?.published])

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('DocumentPerspectiveList', () => {
expect(screen.getByRole('button', {name: 'Published'})).toBeDisabled()
})

it('should disable the "Published" chip when there is no published document and IS live edit', async () => {
it('should enable the "Published" chip when there is no published document and IS live edit', async () => {
mockUseDocumentPane.mockReturnValue({
...mockUsePane,
editState: {...mockUsePane.editState, liveEdit: true},
Expand All @@ -138,7 +138,7 @@ describe('DocumentPerspectiveList', () => {
const wrapper = await createTestProvider()
render(<DocumentPerspectiveList />, {wrapper})

expect(screen.getByRole('button', {name: 'Published'})).toBeDisabled()
expect(screen.getByRole('button', {name: 'Published'})).not.toBeDisabled()
})

it('should enable the "Published" chip when the document is "liveEdit"', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {type DocumentActionComponent, type DocumentActionDescription, Hotkeys} f
import {Button, Tooltip} from '../../../../ui-components'
import {RenderActionCollectionState} from '../../../components'
import {HistoryRestoreAction} from '../../../documentActions'
import {toLowerCaseNoSpaces} from '../../../util/toLowerCaseNoSpaces'
import {useDocumentPane} from '../useDocumentPane'
import {ActionMenuButton} from './ActionMenuButton'
import {ActionStateDialog} from './ActionStateDialog'
Expand Down Expand Up @@ -61,7 +62,7 @@ const DocumentStatusBarActionsInner = memo(function DocumentStatusBarActionsInne
<Stack>
{!existsInBundle && (
<Button
data-testid={`action-${firstActionState.label}`}
data-testid={`action-${toLowerCaseNoSpaces(firstActionState.label)}`}
disabled={disabled || Boolean(firstActionState.disabled)}
icon={firstActionState.icon}
// eslint-disable-next-line react/jsx-handler-names
Expand Down

0 comments on commit 7406916

Please sign in to comment.