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

Refactor: Replace postId with id in navigation calls across components #67455

Closed

Conversation

yogeshbhutkar
Copy link
Contributor

@yogeshbhutkar yogeshbhutkar commented Dec 2, 2024

Fixes: #67443

What?

This PR resolves a bug in the onNavigateToEntityRecord, where the id parameter was incorrectly referenced as postId. This mismatch caused the "Edit" and "Edit Original" buttons to generate URLs containing undefined, resulting in broken links for editing individual template parts or patterns.

How?

The issue was resolved by updating all instances of onNavigateToEntityRecord to correctly use the id parameter instead of postId. This change ensures that valid URLs are generated for editing actions.

Testing Instructions

  1. Activate a block theme.
  2. Activate Gutenberg trunk
  3. Go to Appearance > Editor. Select a template to edit.
  4. Locate or insert any template part in the template.
  5. With the template part selected, locate and click on the "Edit" option in the block toolbar.
  6. Observe the individual level editing opens up as expected, earlier, it used to produce a warning message.

Screenshots or screencast

Screen.Recording.2024-12-02.at.11.43.04.AM.mov

@yogeshbhutkar yogeshbhutkar marked this pull request as ready for review December 2, 2024 06:14
Copy link

github-actions bot commented Dec 2, 2024

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Type-related labels to choose from: [Type] Automated Testing, [Type] Breaking Change, [Type] Bug, [Type] Build Tooling, [Type] Code Quality, [Type] Copy, [Type] Developer Documentation, [Type] Enhancement, [Type] Experimental, [Type] Feature, [Type] New API, [Type] Task, [Type] Technical Prototype, [Type] Performance, [Type] Project Management, [Type] Regression, [Type] Security, [Type] WP Core Ticket, Backport from WordPress Core, Gutenberg Plugin.
  • Labels found: .

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Copy link

github-actions bot commented Dec 2, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: yogeshbhutkar <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: carolinan <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@yogeshbhutkar
Copy link
Contributor Author

This PR is undergoing some changes, will update here once done. Thanks!

@yogeshbhutkar
Copy link
Contributor Author

Update: A bug was identified where using id universally caused issues. While the Patterns and Template Parts function correctly within Appearance → Editor, this approach breaks functionality on Post/Page screens. The discrepancy arises because the site editor's URL structure relies on id, whereas Posts and Pages adhere to the standard postId usage, governed by the following code:

export default function useNavigateToEntityRecord() {
	const history = useHistory();

	const onNavigateToEntityRecord = useCallback(
		( params ) => {
			history.navigate(
				`/${ params.postType }/${ params.id }?canvas=edit&focusMode=true`
			);
		},
		[ history ]
	);

	return onNavigateToEntityRecord;
}

Using params.postId appears to resolve the issue as well. I will await confirmation from the reviewers to proceed with the change in useNavigateToEntityRecord.

The PR is now ready to be reviewed.

@youknowriad
Copy link
Contributor

Opened an alternative PR here #67458

@yogeshbhutkar
Copy link
Contributor Author

Yes @youknowriad, it's just more effective to update the function useNavigateToEntityRecord to standardize the usage to use postId.

@carolinan carolinan closed this Dec 2, 2024
@carolinan
Copy link
Contributor

Thank you for working on this.

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