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

Add the 'Block Settings' panel #43

Merged
merged 32 commits into from
Nov 23, 2020
Merged

Conversation

kienstra
Copy link
Contributor

@kienstra kienstra commented Nov 10, 2020

Changes

  • Uses Rob's markup and CSS
  • Adds a 'Block Settings' panel:
    hetb-lock-pa

Testing instructions

  1. composer install && npm ci && npm run dev

  2. wp post create --post_type='genesis_custom_block' --post_title='Test UI' --post_excerpt='' --post_content='{"genesis-custom-blocks\/test-ui":{"name":"test-ui","title":"Test UI","excluded":[],"icon":"genesis_custom_blocks","category":{"slug":"common","title":"Common Blocks","icon":null},"keywords":["baz"],"fields":{"text":{"name":"text","label":"Text","control":"text","type":"string","order":0,"location":"editor","width":"100","help":"","default":"","placeholder":"","maxlength":null}}}}'

  3. It should say something like Success! Created post 8

  4. Go to the URL for that post: https://your-wp-local/wp-admin/post.php?post=8&action=edit

  5. Expected: It should initially look like this:
    initial-display

  6. Expected: you can edit, undo, and save the 'Slug', 'Icon', 'Category', and 'Keywords', and 'Post Types':
    het-block-tess

  7. The scope of this PR is mainly the 'Block Settings' panel. There is still a lot of work needed in the editor.

Using Rob's HTML and CSS,
begin this panel
and add a component test for it.
The PHPUnit test jobs
failed with a message that the GD extension
is not available.
From doing:
composer install --dev ext-gd
For now at least,
enqueue the 'wp-components'
stylesheet.
Eventually, it'd be good
to import it from node_modules,
so we know exactly what version
is used.
https://github.com/WordPress/gutenberg/blob/f152a28c5331d56230b716ee8b948b9a56590929/packages/components/README.md
On adding a new category,
display it in the <select>.
@kienstra
Copy link
Contributor Author

Here's the current display:

the-iu

@@ -0,0 +1,25 @@
/**
Copy link
Contributor Author

@kienstra kienstra Nov 12, 2020

Choose a reason for hiding this comment

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

All of these files in common/icons/ are just ported from assets/icons.json. There's no intended change.

This is working, but it
needs a lot of styling,
some of which can be ported over.
@kienstra
Copy link
Contributor Author

You can now change icons:
we-can-change-icon

Of course, I need to style this. Some of the styling from the previous editor should help.

@kienstra
Copy link
Contributor Author

kienstra commented Nov 12, 2020

Icon UI

Hi @RobStino and @lukecarbis,
Do you think the icon UI should be mainly the same as the previous one?

previous-icon-ui

The new UI mainly looks like that, I just need to add styling.

I think the previous UI is good 😄

They use contexts,
so they don't need to be
as JSX in the same component.
I had used something a little
different, making the <button>
lower in the tree.
Using Tailwind utility classes,
instead of custom classes.
The icons will only
be available via JavaScript.
return (
<>
<GcbInspector blockProps={ blockProps } block={ block } />
<div className={ className } key={ `form-controls-${ block.name }` } >
{ isSelected ? (
<div className="block-form">
<h3 dangerouslySetInnerHTML={ { __html: icons[ block.icon ] + ' ' + block.title } } />
<FormControls blockProps={ blockProps } block={ block } />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

<FormControls> was just a wrapper for <Fields>, so this simply uses <Fields>

*/
const Fields = ( { fields, parentBlock, parentBlockProps, rowIndex } ) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This diff is mainly from indenting one level more, there's very little changed.

if ( ! fullBlock[ blockNameWithNamespace ].fields ) {
fullBlock[ blockNameWithNamespace ].fields = [];
}
const { controls, field, changeControl, changeFieldSetting } = useField();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These deletions are mainly moved to the useField hook.

This will be true initially,
so it should be easier to grasp.
{ __( 'Field', 'genesis-custom-blocks' ) }
</button>
</div>
<FieldPanel />
{ displayFieldPanel ? <FieldPanel /> : <BlockPanel /> }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the <Side> component:

the-panels-expl

{ __( 'Field', 'genesis-custom-blocks' ) }
</button>
</div>
<FieldPanel />
{ displayBlockPanel ? <BlockPanel /> : <FieldPanel /> }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here's the <Side> component:

the-panels-expl

*
* @param array $icons The available icons.
*/
return apply_filters( 'genesis_custom_blocks_icons', $icons );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Todo: update the documentation for this removed filter when this is released.

These are the post types
where the block will display.
It is actually a slug,
so this is more semantic.
display: block;
margin-top: 0.5rem;
.components-form-token-field__label {
font-size: .875rem;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from Gutenberg, for the 'Keywords' section

@@ -1,121 +0,0 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has all of the GCB block icons:
block-icons

It worked fine as a .json file before, but now that we have a React-based editor, these are all moved to their own React component files.

*/
const FormControls = ( { blockProps, block } ) => {
return (
<Fields
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is deleted because it's not really needed, it's just a wrapper for <Fields>

They all have the same markup
in <svg>, so no need to
copy it every time.
@@ -402,7 +402,7 @@ public function save_draft_button() {
public function render_properties_meta_box() {
$post = get_post();
$block = new Block( $post->ID );
$icons = genesis_custom_blocks()->get_icons();
$icons = [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Most of this file will be deleted when this editor redesign is done. It mainly renders the editor and handles its data.

@kienstra
Copy link
Contributor Author

kienstra commented Nov 13, 2020

Hi @johnstonphilip, @BMO-tech, and @mikemcalister,
Could you please review this PR for GF-2532?

Most of the 173 changed files are <svg> elements ported to their own files 😄

The main scope of this is the Block Settings panel.

No hurry reviewing this, it's Friday 🤣

Thanks!

@kienstra kienstra marked this pull request as ready for review November 13, 2020 20:23
This was referenced Nov 13, 2020
Copy link
Contributor

@dreamwhisper dreamwhisper left a comment

Choose a reason for hiding this comment

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

Expected: you can edit, undo, and save the 'Slug', 'Icon', 'Category', and 'Keywords', and 'Post Types':

This is all working perfectly for me.

@kienstra
Copy link
Contributor Author

This is all working perfectly for me.

Nice, thanks so much for testing this!

@kienstra kienstra merged commit 3354100 into feature/react-ui Nov 23, 2020
@kienstra kienstra deleted the add/ui-block-settings branch November 23, 2020 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants