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

editor tracks - fix replace blocks flow not triggering insert event #54415

Merged
merged 1 commit into from
Jul 9, 2021

Conversation

Addison-Stavlo
Copy link
Contributor

@Addison-Stavlo Addison-Stavlo commented Jul 9, 2021

Changes proposed in this Pull Request

Cleans up a bug introduced in #53592.

In the above PR, an event was tracked via a selector but had extra conditions used to determine the proper context if the event should fire:

const item = target.querySelector( '.components-menu-item__item' );
if ( item?.innerText === __( 'Detach blocks from template part' ) ) {

A subscriber was also added to this event, but its function did not contain the same extra conditions to determine proper context as the original event. Therefore other actions taking place that match this selector ('.components-menu-item__button' such as replacing a block's type via the block toolbar), are unintentionally triggering the subscriber function for the event. Here we have added the extra conditions to the subscriber function to prevent it from firing in the wrong circumstances.

Screen Shot 2021-07-09 at 12 16 04 PM

Testing instructions

  • Follow steps to enable tracking debugging at PCYsg-nrf-p2
  • Insert a paragraph block in the editor, enter some text.
  • Using the block toolbar, transform this into a heading block
  • verify the 'wpcom_block_pick_block_inserted' event is sent as expected.

Related to #53410

@Addison-Stavlo Addison-Stavlo self-assigned this Jul 9, 2021
@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jul 9, 2021
@Addison-Stavlo Addison-Stavlo requested a review from a team July 9, 2021 16:05
@Addison-Stavlo Addison-Stavlo merged commit d912d71 into trunk Jul 9, 2021
@Addison-Stavlo Addison-Stavlo deleted the fix/tracks-replace-blocks-inserted-event branch July 9, 2021 16:20
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jul 9, 2021
@a8ci18n
Copy link

a8ci18n commented Jul 9, 2021

This Pull Request is now available for translation here: https://translate.wordpress.com/deliverables/6166903

Thank you @Addison-Stavlo for including a screenshot in the description! This is really helpful for our translators.

ignoreNextReplaceBlocksAction = true;
( mapping, event, target ) => {
const item = target.querySelector( '.components-menu-item__item' );
if ( item?.innerText === __( 'Detach blocks from template part' ) ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@Automattic/i18n will this work, matching a translated string from Core? ^

Copy link
Member

Choose a reason for hiding this comment

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

@creativecoder, Seems like it's using the global @wordpress/i18n instance in the same context as the block editor, so they are sharing the same locale data and the results of the __ translate call in the menu item and in the condition should be matching.

@a8ci18n
Copy link

a8ci18n commented Jul 15, 2021

Translation for this Pull Request has now been finished.

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.

6 participants