Skip to content

Commit

Permalink
fix(core): Fix Title in "Untitled was published" toast (#7473)
Browse files Browse the repository at this point in the history
* fix(core): Fix Title in "Untitled was published" toast

* PR feedback: refactor to useMemo
  • Loading branch information
ryanbonial authored Sep 6, 2024
1 parent 9547093 commit 7a0813b
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {useToast} from '@sanity/ui'
import {memo, useEffect, useRef} from 'react'
import {memo, useEffect, useMemo, useRef} from 'react'
import {Translate, useDocumentOperationEvent, useTranslation} from 'sanity'

import {usePaneRouter} from '../../components'
Expand All @@ -11,13 +11,27 @@ const IGNORE_OPS = ['patch', 'commit']

export const DocumentOperationResults = memo(function DocumentOperationResults() {
const {push: pushToast} = useToast()
const {documentId, documentType} = useDocumentPane()
const {title} = useDocumentTitle()
const {documentId, documentType, value: documentPaneValue} = useDocumentPane()
const documentTitleInfo = useDocumentTitle()
const titleError = documentTitleInfo.error
const event: any = useDocumentOperationEvent(documentId, documentType)
const prevEvent = useRef(event)
const paneRouter = usePaneRouter()
const {t} = useTranslation(structureLocaleNamespace)

const title = useMemo(() => {
// If title isn't set from document preview, use the title from the document pane value
if (
!documentTitleInfo.title &&
!titleError &&
!IGNORE_OPS.includes(event?.op) &&
typeof documentPaneValue.title === 'string' &&
event?.type === 'success'
) {
return documentPaneValue.title
}
return documentTitleInfo.title
}, [documentTitleInfo.title, titleError, event, documentPaneValue.title])
//Truncate the document title and add "..." if it is over 25 characters
const documentTitleBase = title || t('panes.document-operation-results.operation-undefined-title')
const documentTitle =
Expand Down

0 comments on commit 7a0813b

Please sign in to comment.