Skip to content

Commit

Permalink
update end to end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Mar 18, 2024
1 parent 61dff11 commit 265ce8a
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 193 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ import {
PostExcerptPanel,
PostLastRevisionPanel,
PostTaxonomiesPanel,
privateApis as editorPrivateApis,
} from '@wordpress/editor';

/**
* Internal dependencies
*/
import SettingsHeader from '../settings-header';
import PostStatus from '../post-status';
import PostInitialSidebar from '../post-initial-panel';
import MetaBoxes from '../../meta-boxes';
import PluginDocumentSettingPanel from '../plugin-document-setting-panel';
import PluginSidebarEditPost from '../plugin-sidebar';
Expand All @@ -40,6 +40,8 @@ import { store as editPostStore } from '../../../store';
import { privateApis as componentsPrivateApis } from '@wordpress/components';
import { unlock } from '../../../lock-unlock';

const { PostCardPanel } = unlock( editorPrivateApis );

const { Tabs } = unlock( componentsPrivateApis );

const SIDEBAR_ACTIVE_BY_DEFAULT = Platform.select( {
Expand Down Expand Up @@ -113,7 +115,7 @@ const SidebarContent = ( {
<Tabs.TabPanel tabId={ sidebars.document } focusable={ false }>
{ ! isEditingTemplate && (
<>
<PostInitialSidebar />
<PostCardPanel />
<PostStatus />
<PluginDocumentSettingPanel.Slot />
<PostLastRevisionPanel />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
/**
* WordPress dependencies
*/
import {
PanelBody,
__experimentalText as Text,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { page as pageIcon } from '@wordpress/icons';
import { __, sprintf } from '@wordpress/i18n';
import { humanTimeDiff } from '@wordpress/date';
import { PanelBody } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import {
PageAttributesPanel,
PostDiscussionPanel,
Expand All @@ -30,66 +23,39 @@ import PageContent from './page-content';
import PageSummary from './page-summary';
import { unlock } from '../../../lock-unlock';

const { PostSidebarCard } = unlock( editorPrivateApis );
const { PostCardPanel } = unlock( editorPrivateApis );

export default function PagePanels() {
const {
id,
type,
hasResolved,
status,
date,
password,
title,
modified,
renderingMode,
} = useSelect( ( select ) => {
const { getEditedPostContext } = select( editSiteStore );
const { getEditedEntityRecord, hasFinishedResolution } =
select( coreStore );
const { getRenderingMode } = select( editorStore );
const context = getEditedPostContext();
const queryArgs = [ 'postType', context.postType, context.postId ];
const page = getEditedEntityRecord( ...queryArgs );
return {
hasResolved: hasFinishedResolution(
'getEditedEntityRecord',
queryArgs
),
title: page?.title,
id: page?.id,
type: page?.type,
status: page?.status,
date: page?.date,
password: page?.password,
modified: page?.modified,
renderingMode: getRenderingMode(),
};
}, [] );
const { id, type, hasResolved, status, date, password, renderingMode } =
useSelect( ( select ) => {
const { getEditedPostContext } = select( editSiteStore );
const { getEditedEntityRecord, hasFinishedResolution } =
select( coreStore );
const { getRenderingMode } = select( editorStore );
const context = getEditedPostContext();
const queryArgs = [ 'postType', context.postType, context.postId ];
const page = getEditedEntityRecord( ...queryArgs );
return {
hasResolved: hasFinishedResolution(
'getEditedEntityRecord',
queryArgs
),
id: page?.id,
type: page?.type,
status: page?.status,
date: page?.date,
password: page?.password,
renderingMode: getRenderingMode(),
};
}, [] );

if ( ! hasResolved ) {
return null;
}

return (
<>
<PanelBody>
<PostSidebarCard
title={ decodeEntities( title ) }
icon={ pageIcon }
description={
<VStack>
<Text>
{ sprintf(
// translators: %s: Human-readable time difference, e.g. "2 days ago".
__( 'Last edited %s' ),
humanTimeDiff( modified )
) }
</Text>
</VStack>
}
/>
</PanelBody>
<PostCardPanel />
<PanelBody title={ __( 'Summary' ) }>
<PageSummary
status={ status }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
privateApis as editorPrivateApis,
} from '@wordpress/editor';
import { store as coreStore } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { navigation, symbol } from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { useAsyncList } from '@wordpress/compose';
import { serialize } from '@wordpress/blocks';
Expand All @@ -31,15 +29,10 @@ import { useAvailablePatterns } from './hooks';
import { TEMPLATE_PART_POST_TYPE } from '../../../utils/constants';
import { unlock } from '../../../lock-unlock';

const { PostSidebarCard } = unlock( editorPrivateApis );
const { PostCardPanel } = unlock( editorPrivateApis );

const { useHistory } = unlock( routerPrivateApis );

const CARD_ICONS = {
wp_block: symbol,
wp_navigation: navigation,
};

function TemplatesList( { availableTemplates, onSelect } ) {
const shownTemplates = useAsyncList( availableTemplates );
if ( ! availableTemplates || availableTemplates?.length === 0 ) {
Expand All @@ -63,7 +56,7 @@ const POST_TYPE_PATH = {
};

export default function TemplatePanel() {
const { title, description, icon, record, postType, postId } = useSelect(
const { title, description, record, postType, postId } = useSelect(
( select ) => {
const { getEditedPostType, getEditedPostId } =
select( editSiteStore );
Expand Down Expand Up @@ -104,29 +97,24 @@ export default function TemplatePanel() {

return (
<>
<PanelBody>
<PostSidebarCard
className="edit-site-template-card"
title={ decodeEntities( title ) }
icon={ CARD_ICONS[ record?.type ] ?? icon }
description={ decodeEntities( description ) }
actions={
<TemplateActions
postType={ postType }
postId={ postId }
className="edit-site-template-card__actions"
toggleProps={ { size: 'small' } }
onRemove={ () => {
history.push( {
path: POST_TYPE_PATH[ postType ],
} );
} }
/>
}
>
<TemplateAreas />
</PostSidebarCard>
</PanelBody>
<PostCardPanel
className="edit-site-template-card"
actions={
<TemplateActions
postType={ postType }
postId={ postId }
className="edit-site-template-card__actions"
toggleProps={ { size: 'small' } }
onRemove={ () => {
history.push( {
path: POST_TYPE_PATH[ postType ],
} );
} }
/>
}
>
<TemplateAreas />
</PostCardPanel>
{ availablePatterns?.length > 0 && (
<PanelBody
title={ __( 'Transform into:' ) }
Expand Down
97 changes: 97 additions & 0 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/**
* External dependencies
*/
import classnames from 'classnames';

/**
* WordPress dependencies
*/
import {
Icon,
__experimentalHStack as HStack,
__experimentalVStack as VStack,
__experimentalText as Text,
PanelBody,
} from '@wordpress/components';
import { page as pageIcon, navigation, symbol } from '@wordpress/icons';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { __, sprintf } from '@wordpress/i18n';
import { humanTimeDiff } from '@wordpress/date';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';

const CARD_ICONS = {
wp_block: symbol,
wp_navigation: navigation,
};

export default function PostCardPanel( { className, actions, children } ) {
const { modified, title, type, templateInfo } = useSelect( ( select ) => {
const {
getEditedPostAttribute,
getCurrentPostType,
getCurrentPostId,
__experimentalGetTemplateInfo,
} = select( editorStore );
const { getEditedEntityRecord } = select( coreStore );
const _type = getCurrentPostType();
const _id = getCurrentPostId();
let _templateInfo;
if ( _type === 'wp_template' || _type === 'wp_template_part' ) {
const _record = getEditedEntityRecord( 'postType', _type, _id );
_templateInfo = __experimentalGetTemplateInfo( _record );
}
return {
title: _templateInfo?.title || getEditedPostAttribute( 'title' ),
modified: getEditedPostAttribute( 'modified' ),
id: _id,
type: _type,
templateInfo: _templateInfo,
};
} );
const description =
type === 'wp_template' || type === 'wp_template_part'
? templateInfo?.description
: sprintf(
// translators: %s: Human-readable time difference, e.g. "2 days ago".
__( 'Last edited %s' ),
humanTimeDiff( modified )
);
const icon = CARD_ICONS[ type ] || templateInfo?.icon || pageIcon;
return (
<PanelBody>
<div
className={ classnames( 'editor-post-card-panel', className ) }
>
<HStack
spacing={ 3 }
className="editor-post-card-panel__header"
>
<Icon
className="editor-post-card-panel__icon"
icon={ icon }
/>
<h2 className="editor-post-card-panel__title">
{ decodeEntities( title ) }
</h2>
{ actions }
</HStack>
<VStack className="editor-post-card-panel__content">
{ description && (
<div className="editor-post-card-panel__description">
<VStack>
<Text>{ description }</Text>
</VStack>
</div>
) }
{ children }
</VStack>
</div>
</PanelBody>
);
}
Loading

0 comments on commit 265ce8a

Please sign in to comment.