From 4ad20f0fce5c3922981614354e64c8bc97b0c90d Mon Sep 17 00:00:00 2001 From: Ryan Bonial Date: Fri, 6 Sep 2024 12:21:45 -0600 Subject: [PATCH 1/2] fix(core): Fix Title in "Untitled was published" toast --- .../panes/document/DocumentOperationResults.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/sanity/src/structure/panes/document/DocumentOperationResults.tsx b/packages/sanity/src/structure/panes/document/DocumentOperationResults.tsx index c0660bcecca..4a6a1c88920 100644 --- a/packages/sanity/src/structure/panes/document/DocumentOperationResults.tsx +++ b/packages/sanity/src/structure/panes/document/DocumentOperationResults.tsx @@ -11,13 +11,25 @@ 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() + let title = documentTitleInfo.title + const titleError = documentTitleInfo.error const event: any = useDocumentOperationEvent(documentId, documentType) const prevEvent = useRef(event) const paneRouter = usePaneRouter() const {t} = useTranslation(structureLocaleNamespace) + if ( + !title && + !titleError && + !IGNORE_OPS.includes(event?.op) && + typeof documentPaneValue.title === 'string' && + event?.type === 'success' + ) { + // If title isn't be set from document preview, use the title from the document pane value + title = 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 = From 5018446ede518889eb48bf0646d96c60b450eaea Mon Sep 17 00:00:00 2001 From: Ryan Bonial Date: Fri, 6 Sep 2024 12:56:05 -0600 Subject: [PATCH 2/2] PR feedback: refactor to useMemo --- .../document/DocumentOperationResults.tsx | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/packages/sanity/src/structure/panes/document/DocumentOperationResults.tsx b/packages/sanity/src/structure/panes/document/DocumentOperationResults.tsx index 4a6a1c88920..b1ab82ae85b 100644 --- a/packages/sanity/src/structure/panes/document/DocumentOperationResults.tsx +++ b/packages/sanity/src/structure/panes/document/DocumentOperationResults.tsx @@ -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' @@ -13,23 +13,25 @@ export const DocumentOperationResults = memo(function DocumentOperationResults() const {push: pushToast} = useToast() const {documentId, documentType, value: documentPaneValue} = useDocumentPane() const documentTitleInfo = useDocumentTitle() - let title = documentTitleInfo.title const titleError = documentTitleInfo.error const event: any = useDocumentOperationEvent(documentId, documentType) const prevEvent = useRef(event) const paneRouter = usePaneRouter() const {t} = useTranslation(structureLocaleNamespace) - if ( - !title && - !titleError && - !IGNORE_OPS.includes(event?.op) && - typeof documentPaneValue.title === 'string' && - event?.type === 'success' - ) { - // If title isn't be set from document preview, use the title from the document pane value - title = documentPaneValue.title - } + 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 =