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

Button Block: Add parent-child syncing mechanism #15931

Merged
merged 1 commit into from
Jun 11, 2020

Conversation

Copons
Copy link
Contributor

@Copons Copons commented May 26, 2020

Changes proposed in this Pull Request:

  • Add a passthroughAttributes attribute to the Button block, to map parent attribute values to child (Button) attributes.

In some cases, we might want the Button block to use a parent attribute.
For example, the parent block might have a link that we want to use for the button as well.

Inner blocks templates don't update after mount, so we need another way to keep them in sync.

The passthroughAttributes is an object that indicates which parent attributes we want to sync to which child attributes.
E.g. { childAttribute: 'parentAttribute' }

The usePassthroughAttributes hook retrieves the parent attributes values and sets them to the Button attributes, effectively keeping them in sync.

See also: #15370 (comment)

Notes
  • This is a one-way sync (hence the "passthrough" term), so it's should only be used for Button attributes that aren't supposed to be modified manually.
    For example, the url attribute is fine, but the text (used in the testing instructions below) not really.
  • I've created some docs for this block in Button Block: Add documentation #15934. It already includes this change.
Example scenario

The Calendly block as a url attribute that stores a Calendly link, which is then used to either embed a Calendly widget, or as the href of a Button link.

We can create the Button like this:

<InnerBlocks template={ [ [
  'jetpack/button', {
    element: 'a',
    text: 'Submit',
    passthroughAttributes: {
      url: 'url', // buttonBlockUrl: 'calendlyBlockUrl'
    },
  },
] ] } />

Does this pull request change what data or activity we track or use?

No

Testing instructions:

Since this block is not used anywhere yet, an easy test would be to manually update the Revue edit.js to fake a sync between the parent's revueUsername and the Button's text.

<InnerBlocks
	template={ [
		[
			innerButtonBlock.name,
			{
				...innerButtonBlock.attributes,
				passthroughAttributes: {
					text: 'revueUsername',
				},
			},
		],
	] }
	templateLock="all"
/>
  • Insert a Revue block, and add a name (a random string will do).
  • Make sure the button text is that name.
  • Open the Revue block sidebar, and change the name.
  • Make sure the button text updates accordingly.

Proposed changelog entry for your changes:

  • Button block: Add mechanism to sync attributes with the parent block.

@Copons Copons added [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it [Status] In Progress [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack [Block] Button labels May 26, 2020
@Copons Copons self-assigned this May 26, 2020
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello Copons! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D43949-code before merging this PR. Thank you!
This revision will be updated with each commit to this PR

@jetpackbot
Copy link

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-15931

Scheduled Jetpack release: June 2, 2020.
Scheduled code freeze: May 26, 2020

Generated by 🚫 dangerJS against 2ee1b9b

@Copons Copons requested review from 0nko and a team and removed request for 0nko May 26, 2020 16:36
Copy link
Contributor

@aaronrobertshaw aaronrobertshaw left a comment

Choose a reason for hiding this comment

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

@Copons Works great!

Looking forward to using it.

@Copons Copons added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Team Review labels May 27, 2020
@jeherve jeherve added this to the 8.7 milestone May 29, 2020
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Jun 10, 2020
@Copons
Copy link
Contributor Author

Copons commented Jun 11, 2020

r208889-wpcom

@Copons Copons merged commit 72a9014 into master Jun 11, 2020
@Copons Copons deleted the update/button-passthrough-attributes branch June 11, 2020 14:28
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Button [Focus] Blocks Issues related to the block editor, aka Gutenberg, and its extensions developed in Jetpack Touches WP.com Files [Type] Enhancement Changes to an existing feature — removing, adding, or changing parts of it
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants