Skip to content

Commit

Permalink
Fix the posts dataviews
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Nov 21, 2024
1 parent ee6f8c1 commit b0c11e8
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 257 deletions.
12 changes: 0 additions & 12 deletions lib/experimental/posts/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,6 @@ function gutenberg_posts_dashboard() {
echo '<div id="gutenberg-posts-dashboard"></div>';
}

/**
* Redirects to the new posts dashboard page and adds the postType query arg.
*/
function gutenberg_add_post_type_arg() {
global $pagenow;
if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) && 'gutenberg-posts-dashboard' === $_GET['page'] && empty( $_GET['postType'] ) ) {
wp_redirect( admin_url( '/admin.php?page=gutenberg-posts-dashboard&postType=post' ) );
exit;
}
}
add_action( 'admin_init', 'gutenberg_add_post_type_arg' );

/**
* Replaces the default posts menu item with the new posts dashboard.
*/
Expand Down
26 changes: 25 additions & 1 deletion lib/experimental/site-editor-permalinks.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,16 @@
function gutenberg_rewrite_wp_admin_permalinks() {
add_rewrite_rule(
'^wp-admin/design/?(.*)?',
'wp-admin/site-editor.php?path=$1',
'wp-admin/site-editor.php?p=$1',
'top'
);

add_rewrite_rule(
'^wp-admin/post/?(.*)?',
'wp-admin/admin.php?page=gutenberg-posts-dashboard&p=$1',
'top'
);

flush_rewrite_rules();
}
add_action( 'init', 'gutenberg_rewrite_wp_admin_permalinks' );
Expand Down Expand Up @@ -119,3 +126,20 @@ function gutenberg_redirect_site_editor_to_design() {
exit;
}
add_action( 'admin_init', 'gutenberg_redirect_site_editor_to_design' );

function gutenberg_redirect_posts_dataviews_to_post() {
global $pagenow;
if (
'admin.php' !== $pagenow ||
! isset( $_REQUEST['page'] ) ||
'gutenberg-posts-dashboard' !== $_REQUEST['page'] ||
! strpos( $_SERVER['REQUEST_URI'], 'wp-admin/admin.php' )
) {
return;
}

wp_redirect( admin_url( '/post' ), 301 );
exit;
}

add_action( 'admin_init', 'gutenberg_redirect_posts_dataviews_to_post' );
3 changes: 3 additions & 0 deletions packages/edit-site/src/components/editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ function getListPathForPostType( postType ) {
return '/template';
case 'page':
return '/page';
case 'post':
return '/';
}
throw 'Unknown post type';
}
Expand All @@ -108,6 +110,7 @@ function getNavigationPath( location, postType ) {
'template-part-item',
'page-item',
'template-item',
'post-item',
].includes( name )
) {
return getListPathForPostType( postType );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export function useResolveEditedEntity() {
postType = TEMPLATE_POST_TYPE;
} else if ( name === 'page-item' || name === 'pages' ) {
postType = 'page';
} else if ( name === 'post-item' || name === 'posts' ) {
postType = 'post';
}

const homePage = useSelect( ( select ) => {
Expand Down
36 changes: 0 additions & 36 deletions packages/edit-site/src/components/posts-app-routes/home.js

This file was deleted.

17 changes: 3 additions & 14 deletions packages/edit-site/src/components/posts-app-routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,10 @@ import { useEffect } from '@wordpress/element';
*/
import { unlock } from '../../lock-unlock';
import { store as siteEditorStore } from '../../store';
import { homeRoute } from './home';
import { postsListViewQuickEditRoute } from './posts-list-view-quick-edit';
import { postsListViewRoute } from './posts-list-view';
import { postsViewQuickEditRoute } from './posts-view-quick-edit';
import { postsViewRoute } from './posts-view';
import { postsEditRoute } from './posts-edit';
import { postsRoute } from './posts';
import { postItemRoute } from './post-item';

const routes = [
postsListViewQuickEditRoute,
postsListViewRoute,
postsViewQuickEditRoute,
postsViewRoute,
postsEditRoute,
homeRoute,
];
const routes = [ postItemRoute, postsRoute ];

export function useRegisterPostsAppRoutes() {
const registry = useRegistry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,21 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import PostList from '../post-list';
import Editor from '../editor';
import DataViewsSidebarContent from '../sidebar-dataviews';
import SidebarNavigationScreen from '../sidebar-navigation-screen';
import Editor from '../editor';

export const postsEditRoute = {
name: 'posts-edit',
match: ( params ) => {
return params.postType === 'post' && params.canvas === 'edit';
},
export const postItemRoute = {
name: 'post-item',
path: '/post/:postId',
areas: {
sidebar: (
<SidebarNavigationScreen
title={ __( 'Posts' ) }
isRoot
content={ <DataViewsSidebarContent /> }
content={ <DataViewsSidebarContent postType="post" /> }
/>
),
content: <PostList postType="post" />,
mobile: <Editor isPostsList />,
preview: <Editor isPostsList />,
},
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

35 changes: 0 additions & 35 deletions packages/edit-site/src/components/posts-app-routes/posts-view.js

This file was deleted.

Loading

0 comments on commit b0c11e8

Please sign in to comment.