Skip to content

Commit

Permalink
Try/table view (WordPress#50766)
Browse files Browse the repository at this point in the history
* add page component

* hooked up filtering and table

* clean up and add new to page component

* style updates to templates page

* templates page title

* template parts using new page component

* change page header size

* remove tanstack table

* remove filter bar for now and simplify code

* update package lock

* revert package lock

* mobile styles for table view

* Fix page header z-index

* Don't show description wrapper if description is empty

Fixes vertical alignment for custom templates

* Adjust alignment of last item in each row

* fix table padding and scroll

---------

Co-authored-by: James Koster <[email protected]>
  • Loading branch information
2 people authored and sethrubenstein committed Jul 13, 2023
1 parent 41bdf7a commit 97f65a0
Show file tree
Hide file tree
Showing 12 changed files with 471 additions and 55 deletions.
1 change: 1 addition & 0 deletions packages/base-styles/_z-index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ $z-layers: (
// Site editor layout
".edit-site-layout__hub": 3,
".edit-site-layout__header": 2,
".edit-site-page-header": 2,
".edit-site-layout__canvas-container": 2,
".edit-site-layout__sidebar": 1,
".edit-site-layout__canvas-container.is-resizing::after": 100,
Expand Down
115 changes: 60 additions & 55 deletions packages/edit-site/src/components/layout/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import { privateApis as coreCommandsPrivateApis } from '@wordpress/core-commands
*/
import Sidebar from '../sidebar';
import Editor from '../editor';
import ListPage from '../list';
import ErrorBoundary from '../error-boundary';
import { store as editSiteStore } from '../../store';
import getIsListPage from '../../utils/get-is-list-page';
Expand All @@ -48,6 +47,7 @@ import SavePanel from '../save-panel';
import KeyboardShortcutsRegister from '../keyboard-shortcuts/register';
import KeyboardShortcutsGlobal from '../keyboard-shortcuts/global';
import { useEditModeCommands } from '../../hooks/commands/use-edit-mode-commands';
import PageMain from '../page-main';
import { useIsSiteEditorLoading } from './hooks';

const { useCommands } = unlock( coreCommandsPrivateApis );
Expand Down Expand Up @@ -201,63 +201,68 @@ export default function Layout() {
<SavePanel />

{ showCanvas && (
<div
className={ classnames(
'edit-site-layout__canvas-container',
{
'is-resizing': isResizing,
}
) }
>
{ canvasResizer }
{ !! canvasSize.width && (
<motion.div
whileHover={
isEditorPage && canvasMode === 'view'
? {
scale: 1.005,
transition: {
duration:
disableMotion ||
isResizing
? 0
: 0.5,
ease: 'easeOut',
},
}
: {}
}
initial={ false }
layout="position"
className="edit-site-layout__canvas"
transition={ {
type: 'tween',
duration:
disableMotion || isResizing
? 0
: ANIMATION_DURATION,
ease: 'easeOut',
} }
<>
{ isListPage && <PageMain /> }
{ isEditorPage && (
<div
className={ classnames(
'edit-site-layout__canvas-container',
{
'is-resizing': isResizing,
}
) }
>
<ErrorBoundary>
{ isEditorPage && (
<ResizableFrame
isReady={ ! isEditorLoading }
isFullWidth={ isEditing }
oversizedClassName="edit-site-layout__resizable-frame-oversized"
>
<Editor
isLoading={
isEditorLoading
{ canvasResizer }
{ !! canvasSize.width && (
<motion.div
whileHover={
isEditorPage &&
canvasMode === 'view'
? {
scale: 1.005,
transition: {
duration:
disableMotion ||
isResizing
? 0
: 0.5,
ease: 'easeOut',
},
}
: {}
}
initial={ false }
layout="position"
className="edit-site-layout__canvas"
transition={ {
type: 'tween',
duration:
disableMotion || isResizing
? 0
: ANIMATION_DURATION,
ease: 'easeOut',
} }
>
<ErrorBoundary>
<ResizableFrame
isReady={
! isEditorLoading
}
/>
</ResizableFrame>
) }
{ isListPage && <ListPage /> }
</ErrorBoundary>
</motion.div>
isFullWidth={ isEditing }
oversizedClassName="edit-site-layout__resizable-frame-oversized"
>
<Editor
isLoading={
isEditorLoading
}
/>
</ResizableFrame>
</ErrorBoundary>
</motion.div>
) }
</div>
) }
</div>
</>
) }
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions packages/edit-site/src/components/layout/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@
}
}

.edit-site-layout__main {
flex-grow: 1;
overflow: hidden;
display: flex;
flex-direction: column;
}

.edit-site-layout__canvas-container {
position: relative;
flex-grow: 1;
Expand Down
104 changes: 104 additions & 0 deletions packages/edit-site/src/components/page-library/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* WordPress dependencies
*/
import {
VisuallyHidden,
__experimentalHeading as Heading,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore, useEntityRecords } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import Page from '../page';
import Table from '../table';
import Link from '../routes/link';
import AddedBy from '../list/added-by';
import TemplateActions from '../template-actions';
import AddNewTemplate from '../add-new-template';
import { store as editSiteStore } from '../../store';

export default function PageTemplates() {
const { records: templateParts } = useEntityRecords(
'postType',
'wp_template_part',
{
per_page: -1,
}
);

const { canCreate } = useSelect( ( select ) => {
const { supportsTemplatePartsMode } =
select( editSiteStore ).getSettings();
return {
postType: select( coreStore ).getPostType( 'wp_template_part' ),
canCreate: ! supportsTemplatePartsMode,
};
} );

const columns = [
{
header: __( 'Template Part' ),
cell: ( templatePart ) => (
<VStack>
<Heading level={ 5 }>
<Link
params={ {
postId: templatePart.id,
postType: templatePart.type,
canvas: 'edit',
} }
>
{ decodeEntities(
templatePart.title?.rendered ||
templatePart.slug
) }
</Link>
</Heading>
</VStack>
),
maxWidth: 400,
},
{
header: __( 'Added by' ),
cell: ( templatePart ) => (
<AddedBy
postType={ templatePart.type }
postId={ templatePart.id }
/>
),
},
{
header: <VisuallyHidden>{ __( 'Actions' ) }</VisuallyHidden>,
cell: ( templatePart ) => (
<TemplateActions
postType={ templatePart.type }
postId={ templatePart.id }
/>
),
},
];

return (
<Page
title={ __( 'Template Parts' ) }
actions={
canCreate && (
<AddNewTemplate
templateType={ 'wp_template_part' }
showIcon={ false }
toggleProps={ { variant: 'primary' } }
/>
)
}
>
{ templateParts && (
<Table data={ templateParts } columns={ columns } />
) }
</Page>
);
}
27 changes: 27 additions & 0 deletions packages/edit-site/src/components/page-main/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* WordPress dependencies
*/
import { privateApis as routerPrivateApis } from '@wordpress/router';

/**
* Internal dependencies
*/
import PageTemplates from '../page-templates';
import PageLibrary from '../page-library';
import { unlock } from '../../private-apis';

const { useLocation } = unlock( routerPrivateApis );

export default function PageMain() {
const {
params: { path },
} = useLocation();

if ( path === '/wp_template/all' ) {
return <PageTemplates />;
} else if ( path === '/wp_template_part/all' ) {
return <PageLibrary />;
}

return null;
}
104 changes: 104 additions & 0 deletions packages/edit-site/src/components/page-templates/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* WordPress dependencies
*/
import {
VisuallyHidden,
__experimentalHeading as Heading,
__experimentalText as Text,
__experimentalVStack as VStack,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { store as coreStore, useEntityRecords } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';

/**
* Internal dependencies
*/
import Page from '../page';
import Table from '../table';
import Link from '../routes/link';
import AddedBy from '../list/added-by';
import TemplateActions from '../template-actions';
import AddNewTemplate from '../add-new-template';
import { store as editSiteStore } from '../../store';

export default function PageTemplates() {
const { records: templates } = useEntityRecords(
'postType',
'wp_template',
{
per_page: -1,
}
);

const { canCreate } = useSelect( ( select ) => {
const { supportsTemplatePartsMode } =
select( editSiteStore ).getSettings();
return {
postType: select( coreStore ).getPostType( 'wp_template' ),
canCreate: ! supportsTemplatePartsMode,
};
} );

const columns = [
{
header: __( 'Template' ),
cell: ( template ) => (
<VStack>
<Heading level={ 5 }>
<Link
params={ {
postId: template.id,
postType: template.type,
canvas: 'edit',
} }
>
{ decodeEntities(
template.title?.rendered || template.slug
) }
</Link>
</Heading>
{ template.description && (
<Text variant="muted">
{ decodeEntities( template.description ) }
</Text>
) }
</VStack>
),
maxWidth: 400,
},
{
header: __( 'Added by' ),
cell: ( template ) => (
<AddedBy postType={ template.type } postId={ template.id } />
),
},
{
header: <VisuallyHidden>{ __( 'Actions' ) }</VisuallyHidden>,
cell: ( template ) => (
<TemplateActions
postType={ template.type }
postId={ template.id }
/>
),
},
];

return (
<Page
title={ __( 'Templates' ) }
actions={
canCreate && (
<AddNewTemplate
templateType={ 'wp_template' }
showIcon={ false }
toggleProps={ { variant: 'primary' } }
/>
)
}
>
{ templates && <Table data={ templates } columns={ columns } /> }
</Page>
);
}
Loading

0 comments on commit 97f65a0

Please sign in to comment.