Skip to content
This repository was archived by the owner on Nov 6, 2022. It is now read-only.

Duplicate block field#438

Merged
lukecarbis merged 9 commits into
developfrom
feature/duplicate-field
Oct 28, 2019
Merged

Duplicate block field#438
lukecarbis merged 9 commits into
developfrom
feature/duplicate-field

Conversation

@lukecarbis
Copy link
Copy Markdown
Member

Wow! This was a lot more complicated than I thought it would be.

This isn't yet working for repeater fields (but it is for sub-fields).

This PR also includes a whole heap of JS coding standard fixes.

Closes #315.

@RobStino
Copy link
Copy Markdown
Collaborator

This is awesome!
Tested and the UX is great!

@kienstra
Copy link
Copy Markdown
Collaborator

kienstra commented Oct 2, 2019

Looks Good

Hi @lukecarbis,
This looks good, and duplication worked really well.

Initial Field

initial-text-field

Duplicate

dup-text

All of the fields that I tested had all of their values duplicated. Including Text, Post, and Checkbox.

Comment thread js/admin.block-post.js
*/

(function( $ ) {
/* global blockLab, jQuery */
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Wow, this is great. It looks like this now passes eslint!

What do you think of adding it to the eslint configuration?

diff --git a/package.json b/package.json
index c5cd510..6c7cf1a 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
     "dev": "cross-env BABEL_ENV=default webpack --watch",
     "build": "cross-env BABEL_ENV=default NODE_ENV=production webpack",
     "lint": "npm-run-all --parallel lint:*",
-    "lint:js": "eslint js/blocks",
+    "lint:js": "eslint js",
     "lint:js:fix": "eslint js/blocks --fix",
     "lint:php": "vendor/bin/phpcs",
     "lint:php:fix": "vendor/bin/phpcbf"

Also, creating an .eslintignore with the following will prevent it from running on the compiled files:

js/editor.blocks.js
js/scripts.js

@kienstra
Copy link
Copy Markdown
Collaborator

kienstra commented Oct 2, 2019

Side Note

We might consider refactoring this Edit Block UI in React at some point (though not necessarily re-designing it much):

ed-block-ui

js/admin.block-post.js had been long before, and is now 458 lines.

The DOM manipulation in that file gets really complex, and it's going to be hard to maintain. And that file's probably not going to get smaller 😄

@lukecarbis
Copy link
Copy Markdown
Member Author

@kienstra @RobStino Requesting a re-review. Some big changes made in the last couple of commits.

In particular, please review duplication repeater fields!

@RobStino
Copy link
Copy Markdown
Collaborator

Hey all,
Tested and this works really well!
My testing included:

  • Duplicating a field
  • Duplicating a whole repeater field with subfields
  • Duplicating a sub-field
  • Duplicating a duplicated sub-field within a duplicated repeater field :P
    Basically I tried all the variations of everything and noted that:
  • Duplications always worked
  • The generated field name was always unique

Great work @lukecarbis This is a really useful feature!

Copy link
Copy Markdown
Collaborator

@kienstra kienstra left a comment

Choose a reason for hiding this comment

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

Great work!

Hi @lukecarbis,
Wow, this works well, even duplicating entire repeaters.

Duplicating single fields and repeater rows also work well.

It might be good to refactor the 'Edit Block' screen with React soon.

admin.block-post.js is over 500 lines, and will only get harder to refactor. Though it's worked really well, very few bugs.

@lukecarbis lukecarbis changed the title [WIP] Duplicate block field Duplicate block field Oct 27, 2019
@lukecarbis
Copy link
Copy Markdown
Member Author

You guys. Thanks for testing, but you missed a critical bug!

Repeater child fields aren't saving. Will take a look at it asap.

@lukecarbis
Copy link
Copy Markdown
Member Author

The bug is occurring because we're assigning the sub-fields their parent's UID instead of their parent's slug.

Actually, this made me realise that saving sub-fields with the parents name is a bad idea! It surfaced a new bug: If you create a repeater, add sub fields, then go back and change the repeater's name, then the sub fields will be deleted on save.

I'm going to refactor the sub fields to use the parent UID instead of the parent slug / name.

@lukecarbis
Copy link
Copy Markdown
Member Author

@kienstra and @RobStino – please re-review? Especially testing:

  • Do sub-rows from pre-existing blocks still save without making changes?
  • Do sub-rows from pre-existing blocks still save with making changes?
  • Do new sub-rows still save?
  • Can you break the auto-incrementing field names by adding rows, sub rows, and duplicating things?

@RobStino
Copy link
Copy Markdown
Collaborator

Just testing this now, and looks like I hit a limit for the incremental numbering for duplicating fields.
image
Is this intentional?

@lukecarbis
Copy link
Copy Markdown
Member Author

@RobStino Great pickup. Fixed in a650df0.

@RobStino
Copy link
Copy Markdown
Collaborator

Yep, that fixes it.

@kienstra
Copy link
Copy Markdown
Collaborator

Do sub-rows from pre-existing blocks still save without making changes? yes
Do sub-rows from pre-existing blocks still save with making changes? yes
Do new sub-rows still save? yes

new-sub-row

I'm working on this:

Can you break the auto-incrementing field names by adding rows, sub rows, and duplicating things?

@kienstra
Copy link
Copy Markdown
Collaborator

Can you break the auto-incrementing field names by adding rows, sub rows, and duplicating things?

No, I haven't been able to break this 😄

@kienstra
Copy link
Copy Markdown
Collaborator

Pending any testing you'd like, I think the code is ready to merge.

@lukecarbis lukecarbis merged commit 2cc447a into develop Oct 28, 2019
@lukecarbis lukecarbis deleted the feature/duplicate-field branch October 28, 2019 03:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Copy" or "Duplicate" block field action

3 participants