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 all commits
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
4 changes: 2 additions & 2 deletions packages/components/src/icon-button/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
position: relative;
overflow: hidden;
text-indent: 4px;
border-radius: $radius-round-rectangle;
Copy link
Member

@aduth aduth Sep 7, 2018

Choose a reason for hiding this comment

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

Does this change make the following line redundant now (for .edit-post-header .components-button selector)?

border-radius: $radius-round-rectangle;

Copy link
Member

Choose a reason for hiding this comment

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

Also, I don't understand why it's IconButton which applies hover and active button styles (and the associated border radius), rather than the underlying Button ?

See related comment at #7534 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that makes this rule redundant.

And I don't have a good answer to your question, other than this is how we got to where we are today.

I very much appreciate the effort you are putting in #9702 — would you like help with that? Do you want to remove the redundant rule in the header as part of that PR, or would you like me to create a quick fixup here?

Copy link
Member

Choose a reason for hiding this comment

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

There doesn't appear to be great consensus around #9702 / #7534, so if the change can happen separately, it's probably better.

Copy link
Contributor

Choose a reason for hiding this comment

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

Created PR here: #10021


.dashicon {
display: inline-block;
flex: 0 0 auto;
}

// Ensure that even SVG icons that don't include the .dashicon class are colored
// Ensure that even SVG icons that don't include the .dashicon class are colored.
svg {
fill: currentColor;
outline: none;
Expand All @@ -33,5 +34,4 @@
&:disabled:focus {
box-shadow: none;
}

}
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 All Reusable 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