Skip to content

Commit

Permalink
Add quick edit to any post type
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Nov 6, 2024
1 parent 452d3b0 commit f654ad6
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
3 changes: 1 addition & 2 deletions packages/edit-site/src/components/post-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ export default function PostList( { postType } ) {
defaultLayouts={ defaultLayouts }
header={
window.__experimentalQuickEditDataViews &&
view.type !== LAYOUT_LIST &&
postType === 'page' && (
view.type !== LAYOUT_LIST && (
<Button
size="compact"
isPressed={ quickEdit }
Expand Down
11 changes: 9 additions & 2 deletions packages/edit-site/src/components/posts-app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,18 @@ import SidebarNavigationScreen from '../sidebar-navigation-screen';
import SidebarNavigationScreenMain from '../sidebar-navigation-screen-main';
import DataViewsSidebarContent from '../sidebar-dataviews';
import PostList from '../post-list';
import { PostEdit } from '../post-edit';

const { useLocation } = unlock( routerPrivateApis );

function PostQuickEdit() {
const { params } = useLocation();
return <PostEdit postType={ params.postType } postId={ params.postId } />;
}

export default function useActiveRoute() {
const { params = {} } = useLocation();
const { postType, layout, canvas } = params;
const { postType, layout, canvas, quickEdit } = params;
const labels = useSelect(
( select ) => {
return select( coreStore ).getPostType( postType )?.labels;
Expand All @@ -28,7 +34,7 @@ export default function useActiveRoute() {
);

// Posts list.
if ( [ 'post' ].includes( postType ) ) {
if ( postType ) {
const isListLayout = layout === 'list' || ! layout;
return {
name: 'posts-list',
Expand All @@ -50,6 +56,7 @@ export default function useActiveRoute() {
) : (
<PostList postType={ postType } />
),
edit: quickEdit && <PostQuickEdit />,
},
widths: {
content: isListLayout ? 380 : undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const postTypesWithoutParentTemplate = [
PATTERN_TYPES.user,
];

const authorizedPostTypes = [ 'page', 'post' ];

function useResolveEditedEntityAndContext( { postId, postType } ) {
const { hasLoadedAllDependencies, homepageId, postsPageId } = useSelect(
( select ) => {
Expand Down Expand Up @@ -181,11 +179,7 @@ function useResolveEditedEntityAndContext( { postId, postType } ) {

// If we're rendering a specific page, we need to resolve its template.
// The site editor only supports pages for now, not other CPTs.
if (
postType &&
postId &&
authorizedPostTypes.includes( postType )
) {
if ( postType && postId ) {
return resolveTemplateForPostTypeAndId( postType, postId );
}

Expand All @@ -205,7 +199,7 @@ function useResolveEditedEntityAndContext( { postId, postType } ) {
return {};
}

if ( postType && postId && authorizedPostTypes.includes( postType ) ) {
if ( postType && postId ) {
return { postType, postId };
}
// TODO: for post types lists we should probably not render the front page, but maybe a placeholder
Expand Down

0 comments on commit f654ad6

Please sign in to comment.