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(core): Fix Title in "Untitled was published" toast #7473

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Changes from 1 commit
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 @@ -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 (
Copy link
Contributor

Choose a reason for hiding this comment

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

this may be more react-esque if it was calculated. e.g.

  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])

Copy link
Member Author

Choose a reason for hiding this comment

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

👍 Thanks for that suggestion, I was going back and forth on the decision to memoize it.

Copy link
Contributor

Choose a reason for hiding this comment

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

its not too important to memoize it since the value isn't an object reference and is cheap to calculate but it kinda feels better to useMemo than to have an IIFE e.g. const title = (() => {})() do the same thing. mutating the variable is the thing to avoid in react renders

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I like the memo approach better. I went ahead and made that change.

!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 =
Expand Down
Loading