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

Conversation

ryanbonial
Copy link
Member

Description

This PR fixes a bug where a success message shows "Untitled was published" when publishing (and unpublishing) a document with a title. This is especially prevalent on documents with an image field.

It adds an additional check for a title in the current document title when the title is not available on the document preview title.

What to review

Ensure that the using the document pane value directly as a last resort for a title is a safe approach.

Testing

  • Create a new document with an image field
  • Add a title and then publish the document
  • Ensure that the success toast includes the title that you typed and not "Untitled was published"
  • Unpublish the document
  • Ensure that the success toast includes the title that you typed and not "Untitled was unpublished"

Notes for release

  • Fixes the "Untitled was published" success toast issue

@ryanbonial ryanbonial self-assigned this Sep 6, 2024
@ryanbonial ryanbonial requested a review from a team as a code owner September 6, 2024 18:35
@ryanbonial ryanbonial requested review from cngonzalez and removed request for a team September 6, 2024 18:35
Copy link

vercel bot commented Sep 6, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
page-building-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 6, 2024 7:07pm
performance-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 6, 2024 7:07pm
test-compiled-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 6, 2024 7:07pm
test-next-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 6, 2024 7:07pm
test-studio ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 6, 2024 7:07pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
studio-workshop ⬜️ Ignored (Inspect) Visit Preview Sep 6, 2024 7:07pm

Copy link
Contributor

github-actions bot commented Sep 6, 2024

No changes to documentation

ricokahler
ricokahler previously approved these changes Sep 6, 2024
Copy link
Contributor

@ricokahler ricokahler left a comment

Choose a reason for hiding this comment

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

looks good. left a comment on react conventions but nothing blocking

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.

Copy link
Contributor

github-actions bot commented Sep 6, 2024

Component Testing Report Updated Sep 6, 2024 7:11 PM (UTC)

✅ All Tests Passed -- expand for details
File Status Duration Passed Skipped Failed
comments/CommentInput.spec.tsx ✅ Passed (Inspect) 43s 15 0 0
formBuilder/ArrayInput.spec.tsx ✅ Passed (Inspect) 9s 3 0 0
formBuilder/inputs/PortableText/Annotations.spec.tsx ✅ Passed (Inspect) 31s 6 0 0
formBuilder/inputs/PortableText/copyPaste/CopyPaste.spec.tsx ✅ Passed (Inspect) 37s 11 7 0
formBuilder/inputs/PortableText/copyPaste/CopyPasteFields.spec.tsx ✅ Passed (Inspect) 0s 0 12 0
formBuilder/inputs/PortableText/Decorators.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/DisableFocusAndUnset.spec.tsx ✅ Passed (Inspect) 10s 3 0 0
formBuilder/inputs/PortableText/DragAndDrop.spec.tsx ✅ Passed (Inspect) 3m 0s 0 0 0
formBuilder/inputs/PortableText/FocusTracking.spec.tsx ✅ Passed (Inspect) 45s 15 0 0
formBuilder/inputs/PortableText/Input.spec.tsx ✅ Passed (Inspect) 1m 49s 21 0 0
formBuilder/inputs/PortableText/ObjectBlock.spec.tsx ✅ Passed (Inspect) 1m 17s 18 0 0
formBuilder/inputs/PortableText/PresenceCursors.spec.tsx ✅ Passed (Inspect) 8s 3 9 0
formBuilder/inputs/PortableText/RangeDecoration.spec.tsx ✅ Passed (Inspect) 26s 9 0 0
formBuilder/inputs/PortableText/Styles.spec.tsx ✅ Passed (Inspect) 18s 6 0 0
formBuilder/inputs/PortableText/Toolbar.spec.tsx ✅ Passed (Inspect) 36s 12 0 0
formBuilder/tree-editing/TreeEditing.spec.tsx ✅ Passed (Inspect) 0s 0 3 0
formBuilder/tree-editing/TreeEditingNestedObjects.spec.tsx ✅ Passed (Inspect) 0s 0 3 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants