-
Notifications
You must be signed in to change notification settings - Fork 13
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
Auto-slug block and field names, make Repeater work #51
Conversation
Maybe revisit some of this if there are bugs, but a lot of this is for the block editor, not for an editor that doesn't use blocks.
Sometimes, ref.current doesn't have an ownerDocument property. Then, it's not possible to get its properties.
Needed to import an NPM package.
Like how the previous editor worked, so the user will enter the field name right away.
On editing the field label for a new field, auto-slug the field name.
Even on blurring, allow autoslugging the next time there's a change
There's no need for a rerender on changing this. So don't call useState().
getFieldIcon() gets the icon, with a filter.
We might have to use <FieldsGrid> in another component, so move the parts that won't be needed in the new one.
This allows passing a parentName, which will mark this as a sub_field. So on clicking a sub_field, it will set a name of the sub_field, and a parentName of the parent field.
Add a warning on trying to exit with unsaved changes.
There's still a lot of work needed for sub_fields, though.
return; | ||
} | ||
|
||
// A hack to remove blocks from the edited entity. |
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.
The forked <EditorProvider>
removes the need for this hack.
> | ||
<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.
This diff is mainly from indentation.
return []; | ||
} | ||
|
||
return block.keywords.filter( ( keyword ) => Boolean( keyword ) ); |
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.
* @param {LocationButtonProps} props | ||
* @return {React.ReactElement} The location buttons. | ||
*/ | ||
const LocationButtons = ( { |
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.
It looks like this didn't pass anything that was needed.
? control.settings.map( ( setting, index ) => { | ||
if ( field.hasOwnProperty( 'parent' ) && 'location' === setting.name ) { |
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.
@@ -189,7 +189,7 @@ protected function register_block( $block_name, $block ) { | |||
$block_name = str_replace( '_', '-', $block_name ); | |||
|
|||
// register_block_type doesn't allow slugs starting with a number. | |||
if ( is_numeric( $block_name[0] ) ) { | |||
if ( isset( $block_name[0] ) && is_numeric( $block_name[0] ) ) { |
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.
Not related, but found a PHP warning or error when testing.
A type should ideally only be defined in one place, and other files should import them.
} } | ||
onBlur={ () => { | ||
if ( didAutoSlug.current ) { | ||
setIsNewField( false ); |
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.
On blurring this <input>
, it should prevent auto-slugging again.
</div> | ||
{ null === parentField && 'repeater' === field.control | ||
? ( | ||
<FieldsGrid |
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.
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.
This is more of a UI and frontend test than a deep code dive, but everything was working well in my experiments.
- Focus on title works with new block creation
- Auto-slug on block and field name works
- New settings (help, min/max rows) showing on repeater field
- Adding and deleting repeater fields works as expected
- Resizing repeater fields wasn't working initially, but there was no console error. I did a rebuild and they do work now. Seems to work well with no console errors.
Great work, @kienstra! I'm loving these improvements.
@mikemcalister, |
Updated December 16th
Tickets
GF-2518: Auto-slug for block name
GF-2519: Auto-slug for field names
GF-2507: Settings for Repeater
GF-2508: Add / Remove Sub-fields
GF-2509: Move / Resize Sub-fields
GF-2510: Sub-field JSON data
GF-2511: Save sub-field data
Changes
sub_fields
Testing instructions