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(structure): enable published chip for live edit documents #8000

Merged
merged 2 commits into from
Dec 10, 2024
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simplification 🙌

// 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
Loading