-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Posts list powered by DataViews #62705
Changes from all commits
132f566
a014545
2bcfbd6
3796d57
52cc4ac
78f2b12
ec5c667
d66839a
a3cde6c
2b40bfc
8436156
5743405
f412dbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,22 +7,78 @@ | |
|
||
add_action( 'admin_menu', 'gutenberg_replace_posts_dashboard' ); | ||
|
||
// Default to is-fullscreen-mode to avoid jumps in the UI. | ||
add_filter( | ||
'admin_body_class', | ||
static function ( $classes ) { | ||
return "$classes is-fullscreen-mode"; | ||
} | ||
); | ||
|
||
/** | ||
* Renders the new posts dashboard page. | ||
*/ | ||
function gutenberg_posts_dashboard() { | ||
$block_editor_context = new WP_Block_Editor_Context( array( 'name' => 'core/edit-site' ) ); | ||
$custom_settings = array( | ||
'siteUrl' => site_url(), | ||
'styles' => get_block_editor_theme_styles(), | ||
'supportsLayout' => wp_theme_has_theme_json(), | ||
); | ||
|
||
$editor_settings = get_block_editor_settings( $custom_settings, $block_editor_context ); | ||
$active_global_styles_id = WP_Theme_JSON_Resolver::get_user_global_styles_post_id(); | ||
$active_theme = get_stylesheet(); | ||
|
||
$preload_paths = array( | ||
array( '/wp/v2/media', 'OPTIONS' ), | ||
'/wp/v2/types?context=view', | ||
'/wp/v2/global-styles/' . $active_global_styles_id . '?context=edit', | ||
'/wp/v2/global-styles/' . $active_global_styles_id, | ||
'/wp/v2/global-styles/themes/' . $active_theme, | ||
); | ||
block_editor_rest_api_preload( $preload_paths, $block_editor_context ); | ||
|
||
// Preload server-registered block schemas. | ||
wp_add_inline_script( | ||
'wp-blocks', | ||
'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( get_block_editor_server_block_settings() ) . ');' | ||
); | ||
|
||
/** This action is documented in wp-admin/edit-form-blocks.php */ | ||
do_action( 'enqueue_block_editor_assets' ); | ||
wp_register_style( | ||
'wp-gutenberg-posts-dashboard', | ||
gutenberg_url( 'build/edit-site/posts.css', __FILE__ ), | ||
array( 'wp-components', 'wp-commands' ) | ||
array( 'wp-components', 'wp-commands', 'wp-edit-site' ) | ||
); | ||
wp_enqueue_style( 'wp-gutenberg-posts-dashboard' ); | ||
wp_add_inline_script( 'wp-edit-site', 'window.wp.editSite.initializePostsDashboard( "gutenberg-posts-dashboard" );', 'after' ); | ||
wp_add_inline_script( | ||
'wp-edit-site', | ||
sprintf( | ||
'wp.domReady( function() { | ||
wp.editSite.initializePostsDashboard( "gutenberg-posts-dashboard", %s ); | ||
} );', | ||
wp_json_encode( $editor_settings ) | ||
) | ||
); | ||
wp_enqueue_script( 'wp-edit-site' ); | ||
|
||
wp_enqueue_media(); | ||
echo '<div id="gutenberg-posts-dashboard"></div>'; | ||
} | ||
|
||
/** | ||
* Redirects to the new posts dashboard page and adds the postType query arg. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of doing a redirect to include the post type. Could we assume a default post-type? e.g: if empty( $_GET['postType'] ) we assume it has the value post on our code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to have the param in the URL for the editor to resolve the current entities etc.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we could have a small js code on loading adding postType=post with history.push({postType:'post'}) if a postType is not set. |
||
*/ | ||
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. | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,12 +44,15 @@ import SiteEditorMoreMenu from '../more-menu'; | |
import SiteIcon from '../site-icon'; | ||
import useEditorIframeProps from '../block-editor/use-editor-iframe-props'; | ||
import useEditorTitle from './use-editor-title'; | ||
import { useIsSiteEditorLoading } from '../layout/hooks'; | ||
|
||
const { Editor, BackButton } = unlock( editorPrivateApis ); | ||
const { useHistory } = unlock( routerPrivateApis ); | ||
const { useHistory, useLocation } = unlock( routerPrivateApis ); | ||
const { BlockKeyboardShortcuts } = unlock( blockLibraryPrivateApis ); | ||
|
||
export default function EditSiteEditor( { isLoading } ) { | ||
export default function EditSiteEditor( { isPostsList = false } ) { | ||
const { params } = useLocation(); | ||
const isLoading = useIsSiteEditorLoading(); | ||
const { | ||
editedPostType, | ||
editedPostId, | ||
|
@@ -215,9 +218,20 @@ export default function EditSiteEditor( { isLoading } ) { | |
<Button | ||
label={ __( 'Open Navigation' ) } | ||
className="edit-site-layout__view-mode-toggle" | ||
onClick={ () => | ||
setCanvasMode( 'view' ) | ||
} | ||
onClick={ () => { | ||
setCanvasMode( 'view' ); | ||
// TODO: this is a temporary solution to navigate to the posts list if we are | ||
// come here through `posts list` and are in focus mode editing a template, template part etc.. | ||
if ( | ||
isPostsList && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that's fine but we should be careful about not using this variable in a lot of places. |
||
params?.focusMode | ||
) { | ||
history.push( { | ||
page: 'gutenberg-posts-dashboard', | ||
postType: 'post', | ||
} ); | ||
} | ||
} } | ||
> | ||
<SiteIcon className="edit-site-layout__view-mode-toggle-icon" /> | ||
</Button> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normally anonymous functions are not recommended in core, because they don't allow a third-party plugin to use remove_filter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what we do for site editor in core right now. I'll have to check if I can add the filter only in this new page though.. I didn't observe something weird so far though..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the current one for site editor, passed during a code review but as far as I know anonymous functions should be avoided, they work well the issue is if a plugin wants to remove the filter the plugin can not do it.