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

Site Editor: Add template check to 'setPage' action. #38656

Merged
merged 1 commit into from
Feb 14, 2022
Merged
Changes from all commits
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
8 changes: 7 additions & 1 deletion packages/edit-site/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,17 @@ export function* setPage( page ) {
// If the entity is undefined for some reason, path will resolve to "/"
page.path = getPathAndQueryString( entity?.link );
}
const { id: templateId, slug: templateSlug } = yield controls.resolveSelect(
const template = yield controls.resolveSelect(
coreStore,
'__experimentalGetTemplateForLink',
page.path
);

if ( ! template ) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be any kind of visible error for users if there's no template?

If so, perhaps a notice can be dispatched.

Copy link
Member Author

Choose a reason for hiding this comment

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

The editor will display a notice if the template doesn't exist:

{ templateResolved &&
! template &&
settings?.siteUrl &&
entityId && (
<Notice
status="warning"
isDismissible={
false
}
>
{ __(
"You attempted to edit an item that doesn't exist. Perhaps it was deleted?"
) }
</Notice>
) }

Copy link
Contributor

Choose a reason for hiding this comment

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

Great, in that case I've approved the PR.

}

const { id: templateId, slug: templateSlug } = template;
yield {
type: 'SET_PAGE',
page: ! templateSlug
Expand Down