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: Check whether the data is loaded. If the data is loaded and the template is still unknown, give appropriate feedback #30664

Merged
merged 3 commits into from
Apr 30, 2021
Merged
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
*/
import { useEffect, useState, useMemo, useCallback } from '@wordpress/element';
import { AsyncModeProvider, useSelect, useDispatch } from '@wordpress/data';
import { SlotFillProvider, Popover, Button } from '@wordpress/components';
import {
SlotFillProvider,
Popover,
Button,
Notice,
} from '@wordpress/components';
import { EntityProvider, store as coreStore } from '@wordpress/core-data';
import { BlockContextProvider, BlockBreadcrumb } from '@wordpress/block-editor';
import {
Expand Down Expand Up @@ -217,6 +222,20 @@ function Editor( { initialSettings } ) {
}
/>
) }
{ ! template &&
settings?.siteUrl &&
entityId && (
<Notice
status="warning"
isDismissible={
false
}
>
{ __(
"You attempted to edit an item that doesn't exist. Perhaps it was deleted?"
) }
</Notice>
) }
<KeyboardShortcuts />
</>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@ function useSecondaryText() {
* @param {string} props.entityLabel A label to use for entity-related options.
* E.g. "template" would be used for "edit
* template" and "show template details".
* @param {boolean} props.isLoaded Whether the data is available.
* @param {Function} props.children React component to use for the
* information dropdown area. Should be a
* function which accepts dropdown props.
*/
export default function DocumentActions( {
entityTitle,
entityLabel,
isLoaded,
children: dropdownContent,
} ) {
const { label } = useSecondaryText();
Expand All @@ -73,14 +75,23 @@ export default function DocumentActions( {
const titleRef = useRef();

// Return a simple loading indicator until we have information to show.
if ( ! entityTitle ) {
if ( ! isLoaded ) {
return (
<div className="edit-site-document-actions">
{ __( 'Loading…' ) }
</div>
);
}

// Return feedback that the template does not seem to exist.
if ( ! entityTitle ) {
return (
<div className="edit-site-document-actions">
{ __( 'Template not found' ) }
</div>
);
}

return (
<div
className={ classnames( 'edit-site-document-actions', {
Expand Down
5 changes: 5 additions & 0 deletions packages/edit-site/src/components/header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export default function Header( {
isInserterOpen,
isListViewOpen,
listViewShortcut,
isLoaded,
} = useSelect( ( select ) => {
const {
__experimentalGetPreviewDeviceType,
Expand All @@ -64,10 +65,12 @@ export default function Header( {
'wp_template' === postType
? getTemplateInfo( record ).title
: record?.slug;
const _isLoaded = !! postId;

return {
deviceType: __experimentalGetPreviewDeviceType(),
entityTitle: _entityTitle,
isLoaded: _isLoaded,
hasFixedToolbar: isFeatureActive( 'fixedToolbar' ),
template: record,
templateType: postType,
Expand Down Expand Up @@ -146,6 +149,7 @@ export default function Header( {
<DocumentActions
entityTitle={ entityTitle }
entityLabel="template"
isLoaded={ isLoaded }
>
{ ( { onClose } ) => (
<TemplateDetails
Expand All @@ -159,6 +163,7 @@ export default function Header( {
<DocumentActions
entityTitle={ entityTitle }
entityLabel="template part"
isLoaded={ isLoaded }
/>
) }
</div>
Expand Down