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

Unify UnsavedChangesWarning's isDirty check #24719

Merged

Conversation

david-szabo97
Copy link
Member

Description

According to the discussion in this PR: #24659
We bundle the check into the component. Instead of isEditedPostDirty we use __experimentalGetDirtyEntityRecords to determine if there were any changes in the editor. Since we are using __experimentalGetDirtyEntityRecords, this component will work fine in both Post and Site editor.

How has this been tested?

  1. Open post editor
  2. Make changes
  3. Try to navigate away (like Settings or All posts)
  4. Should show an alert

Types of changes

Enhancement

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR.

const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();
return dirtyEntityRecords.length > 0;
},
} ) )( UnsavedChangesWarning );
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: There's an opportunity here to refactor the component as a function component + hooks.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, David and I have been discussing that! I was recommending doing that in a follow-up PR though.

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

Makes sense to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants