Skip to content
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

Reusable blocks: Add UI for bulk deleting blocks #9588

Merged
merged 2 commits into from
Sep 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,12 @@ function gutenberg_add_edit_link_filters() {
* @return array Updated post actions.
*/
function gutenberg_add_edit_link( $actions, $post ) {
if ( 'wp_block' === $post->post_type ) {
unset( $actions['edit'] );
unset( $actions['inline hide-if-no-js'] );
return $actions;
}

if ( ! gutenberg_can_edit_post( $post ) ) {
return $actions;
}
Expand Down Expand Up @@ -292,16 +298,43 @@ function gutenberg_add_edit_link( $actions, $post ) {
return $actions;
}

/**
* Removes the Edit action from the reusable block list's Bulk Actions dropdown.
*
* @since 3.8.0
*
* @param array $actions Bulk actions.
*
* @return array Updated bulk actions.
*/
function gutenberg_block_bulk_actions( $actions ) {
unset( $actions['edit'] );
return $actions;
}
add_filter( 'bulk_actions-edit-wp_block', 'gutenberg_block_bulk_actions' );

/**
* Prints the JavaScript to replace the default "Add New" button.$_COOKIE
*
* @since 1.5.0
*/
function gutenberg_replace_default_add_new_button() {
global $typenow;

if ( 'wp_block' === $typenow ) {
?>
<style type="text/css">
.page-title-action {
display: none;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was chatting to @azaozz about this. In the medium term, we should patch Core to add a filter here:

https://github.com/WordPress/WordPress/blob/master/wp-admin/edit.php#L352

This would allow us to remove this hacky way of hiding the Add New button and improve how gutenberg_replace_default_add_new_button works.

}
</style>
<?php
}

if ( ! gutenberg_can_edit_post_type( $typenow ) ) {
return;
}

?>
<style type="text/css">
.split-page-title-action {
Expand Down
8 changes: 6 additions & 2 deletions lib/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,13 @@ function gutenberg_register_post_types() {
'wp_block',
array(
'labels' => array(
'name' => 'Blocks',
'singular_name' => 'Block',
'name' => __( 'Blocks', 'gutenberg' ),
'singular_name' => __( 'Block', 'gutenberg' ),
'search_items' => __( 'Search Blocks', 'gutenberg' ),
),
'public' => false,
'show_ui' => true,
'show_in_menu' => false,
'rewrite' => false,
'show_in_rest' => true,
'rest_base' => 'blocks',
Expand All @@ -476,6 +479,7 @@ function gutenberg_register_post_types() {
'create_posts' => 'create_blocks',
),
'map_meta_cap' => true,
'supports' => false,
)
);

Expand Down
12 changes: 8 additions & 4 deletions packages/editor/src/components/inserter/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ import scrollIntoView from 'dom-scroll-into-view';
*/
import { __ } from '@wordpress/i18n';
import { Component, findDOMNode, createRef } from '@wordpress/element';
import {
withSpokenMessages,
PanelBody,
} from '@wordpress/components';
import { withSpokenMessages, PanelBody, IconButton } from '@wordpress/components';
import { getCategories, isReusableBlock } from '@wordpress/blocks';
import { withDispatch, withSelect } from '@wordpress/data';
import { withInstanceId, compose, withSafeTimeout } from '@wordpress/compose';
Expand Down Expand Up @@ -281,13 +278,20 @@ export class InserterMenu extends Component {

{ !! reusableItems.length && (
<PanelBody
className="editor-inserter__reusable-blocks-panel"
title={ __( 'Reusable' ) }
opened={ isPanelOpen( 'reusable' ) }
onToggle={ this.onTogglePanel( 'reusable' ) }
icon="controls-repeat"
ref={ this.bindPanel( 'reusable' ) }
>
<BlockTypesList items={ reusableItems } onSelect={ onSelect } onHover={ this.onHover } />
<IconButton
className="editor-inserter__manage-reusable-blocks"
icon="admin-generic"
label={ __( 'Manage Blocks' ) }
href="edit.php?post_type=wp_block"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For a later PR. We use links to target WP Admin pages (here, revisions, I'm probably missing other links too). The thing is. These links only work in WP context. We need to find a way to add these links in an "augmented" manner. Keeping the packages WP links free.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, let's make sure we make an issue for this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/>
</PanelBody>
) }
{ isEmpty( suggestedItems ) && isEmpty( reusableItems ) && isEmpty( itemsPerCategory ) && (
Expand Down
10 changes: 10 additions & 0 deletions packages/editor/src/components/inserter/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ $block-inserter-search-height: 38px;
margin: 0 -8px;
}

.editor-inserter__reusable-blocks-panel {
position: relative;

.editor-inserter__manage-reusable-blocks {
bottom: 5px;
position: absolute;
right: 0;
}
}

.editor-inserter__no-results {
font-style: italic;
padding: 24px;
Expand Down