Skip to content

Commit

Permalink
Merge branch 'corel' of github.com:sanity-io/sanity into corel
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanl17 committed Nov 29, 2024
2 parents 8ac1d1c + 58ff054 commit 7a4b7a3
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 29 deletions.
2 changes: 2 additions & 0 deletions packages/sanity/src/core/releases/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const releasesLocaleStrings = {
'action.archive.tooltip': 'Unschedule this release to archive it',
/** Action text for showing the archived releases */
'action.archived': 'Archived',
/** Action text for comparing document versions */
'action.compare-versions': 'Compare versions',
/** Action text for deleting a release */
'action.delete': 'Delete',
/** Description for toast when release deletion failed */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ export default function resolveDocumentActions(
existingActions: Action[],
context: DocumentActionsContext,
): Action[] {
if (context.perspective === 'version') {
const duplicateAction = existingActions.find((action) => {
return action.name === 'DuplicateAction'
})
return [...(duplicateAction ? [duplicateAction] : []), DiscardVersionAction]
}

return existingActions
const duplicateAction = existingActions.filter(({name}) => name === 'DuplicateAction')
return context.perspective === 'version'
? duplicateAction.concat(DiscardVersionAction)
: existingActions
}
4 changes: 4 additions & 0 deletions packages/sanity/src/structure/i18n/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ const structureLocaleStrings = defineLocalesResources('structure', {
'banners.deprecated-document-type-banner.text': 'This document type has been deprecated.',
/** The text for publish action for discarding the version */
'banners.live-edit-draft-banner.discard.tooltip': 'Discard draft',
/** The text content for the live edit document when viewed from the draft perspective */
'banners.live-edit-draft-banner.draft-perspective':
'The type <strong>{{schemaType}}</strong> has <code>liveEdit</code> enabled, select the published document to edit it.',
/** The text for publish action for the draft banner */
'banners.live-edit-draft-banner.publish.tooltip': 'Publish to continue editing',

/** The text content for the live edit document when it's a draft */
'banners.live-edit-draft-banner.text':
'The type <strong>{{schemaType}}</strong> has <code>liveEdit</code> enabled, but a draft version of this document exists. Publish or discard the draft in order to continue live editing it.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,11 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
const isLocked = editState.transactionSyncLock?.enabled
// in cases where the document has drafts but the schema is live edit,
// there is a risk of data loss, so we disable editing in this case
const isLiveEditAndDraft = Boolean(liveEdit && editState.draft)
const isSystemPerspectiveApplied = perspective && typeof bundlePerspective === 'undefined'
const isLiveEditAndDraftPerspective = liveEdit && !perspective
const isLiveEditAndPublishedPerspective = liveEdit && perspective === 'published'

const isSystemPerspectiveApplied =
isLiveEditAndPublishedPerspective || (perspective ? perspective && bundlePerspective : true)

const isReleaseLocked =
typeof currentGlobalBundle === 'object' && 'state' in currentGlobalBundle
Expand All @@ -607,7 +610,7 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {

return (
(bundlePerspective && !existsInBundle) ||
isSystemPerspectiveApplied ||
!isSystemPerspectiveApplied ||
!ready ||
revTime !== null ||
hasNoPermission ||
Expand All @@ -617,7 +620,7 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
isLocked ||
isDeleting ||
isDeleted ||
isLiveEditAndDraft ||
isLiveEditAndDraftPerspective ||
isCreateLinked ||
isReleaseLocked
)
Expand All @@ -628,7 +631,6 @@ export const DocumentPaneProvider = memo((props: DocumentPaneProviderProps) => {
isNonExistent,
connectionState,
editState.transactionSyncLock?.enabled,
editState.draft,
liveEdit,
perspective,
bundlePerspective,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
type ObjectSchemaType,
Translate,
useDocumentOperation,
usePerspective,
useTranslation,
} from 'sanity'

Expand All @@ -30,6 +31,8 @@ export function DraftLiveEditBanner({
const {t} = useTranslation(structureLocaleNamespace)
const [isPublishing, setPublishing] = useState(false)
const [isDiscarding, setDiscarding] = useState(false)
const {perspective} = usePerspective()

const telemetry = useTelemetry()

const {publish, discardChanges} = useDocumentOperation(documentId, displayed?._type || '')
Expand All @@ -53,34 +56,42 @@ export function DraftLiveEditBanner({
}
})

if (displayed && displayed._id && !isDraftId(displayed._id)) {
const hasDraft = displayed && displayed._id && isDraftId(displayed._id)
if (perspective && !hasDraft) {
return null
}

return (
<Banner
content={
<Flex align="center" justify="space-between" gap={1}>
<Text size={1} weight="medium">
<Translate
t={t}
i18nKey={'banners.live-edit-draft-banner.text'}
i18nKey={
hasDraft
? 'banners.live-edit-draft-banner.text'
: 'banners.live-edit-draft-banner.draft-perspective'
}
values={{schemaType: schemaType.title}}
/>
</Text>
<Button
onClick={handlePublish}
text={t('action.publish.live-edit.label')}
tooltipProps={{content: t('banners.live-edit-draft-banner.publish.tooltip')}}
loading={isPublishing}
/>
{hasDraft && (
<>
<Button
onClick={handlePublish}
text={t('action.publish.live-edit.label')}
tooltipProps={{content: t('banners.live-edit-draft-banner.publish.tooltip')}}
loading={isPublishing}
/>

<Button
onClick={handleDiscard}
text={t('banners.live-edit-draft-banner.discard.tooltip')}
tooltipProps={{content: t('banners.live-edit-draft-banner.discard.tooltip')}}
loading={isDiscarding}
/>
<Button
onClick={handleDiscard}
text={t('banners.live-edit-draft-banner.discard.tooltip')}
tooltipProps={{content: t('banners.live-edit-draft-banner.discard.tooltip')}}
loading={isDiscarding}
/>
</>
)}
</Flex>
}
data-testid="live-edit-type-banner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const DocumentPerspectiveList = memo(function DocumentPerspectiveList() {
)}
</Text>
}
disabled={!editState?.published}
disabled={editState?.liveEdit ? false : !editState?.published}
onClick={handleBundleChange('published')}
selected={
/** the publish is selected when:
Expand Down
3 changes: 3 additions & 0 deletions test/e2e/tests/document-actions/liveEdit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ test(`liveEdited document can be created, edited, and deleted`, async ({
const name = 'Test Name'

await createDraftDocument('/test/content/playlist')
await page.getByText('select the publish document to edit it')
// Navigate to the published perspective
await page.getByRole('button', {name: 'Published'}).click()
await page.getByTestId('field-name').getByTestId('string-input').fill(name)

await page.getByTestId('action-menu-button').click()
Expand Down

0 comments on commit 7a4b7a3

Please sign in to comment.