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

Block Editor Tracking: Remove "wpcom_block_editor_close_click" from W button #53864

Merged
merged 15 commits into from
Jun 30, 2021

Conversation

david-szabo97
Copy link
Contributor

@david-szabo97 david-szabo97 commented Jun 21, 2021

Changes proposed in this Pull Request

This is a companion PR to #53500

wpcom_block_editor_close_click is used to track when the editor is closed. A few months ago a navigation sidebar was implemented for the post editor, that time the W button's behaviour changed. It opened the navigation sidebar rather than closing the editor. To make sure we are tracking the right behaviour, this PR changes the following:

  • Remove wpcom_block_editor_close_click from the WP button when it's supposed to open a navigation sidebar.

Testing instructions

  • Follow steps to enable tracking debugging at PCYsg-nrf-p2
  • Open post editor
  • Click on the W button to open the navigation sidebar.
  • Confirm "wpcom_block_editor_close_click" event is NOT triggered

E2E test will fail for Site Editor.

Related to #53500 #53410

@david-szabo97 david-szabo97 self-assigned this Jun 21, 2021
@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 Jun 21, 2021
@matticbot
Copy link
Contributor

matticbot commented Jun 21, 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
Copy link
Contributor

This PR modifies the release build for wpcom-block-editor

To test your changes on WordPress.com, run install-plugin.sh wpcom-block-editor update/wpcom-nav-sidebar-tracking on your sandbox.

To deploy your changes after merging, see the documentation: PCYsg-l4k-p2

Copy link
Contributor

@Addison-Stavlo Addison-Stavlo left a comment

Choose a reason for hiding this comment

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

This is working well in my testing!

Comment on lines 172 to 175
const editorCloseClickNotFired =
eventsStack.filter( ( [ eventName ] ) => eventName === 'wpcom_block_editor_close_click' )
.length === 0;
assert.strictEqual(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a second test to ensure this fires as expected on < All Pages / < All Posts / < Dashboard ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any idea how to tackle this? I've the tests written (locally) but clicking on the button closes the editor. Which removes the E2E events stack.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh good point. Im not quite sure the best way to handle that. Maybe a simple way would be to define the selector for this tracks event as a constant, use that import in both the test and the tracks event, and have the test just verify that selector is present where we would expect it to be? It wouldn't technically test that the event is firing, but it would at least notify us if the selector that event is tied to is no longer present 🤔 .

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@WunderBart Any idea? Is there a way to disable/prevent navigations? Googled it but no luck 😞

Copy link
Member

@WunderBart WunderBart Jun 23, 2021

Choose a reason for hiding this comment

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

Not sure I understand the issue here, could you elaborate please?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, should we even test it here? Isn't that something we should do in ETK?

} else {
await driverHelper.clickWhenClickable(
this.driver,
By.css( '.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button' )
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this selector works for toggling regardless of open/close state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It doesn't work. The button is not visible so Selenium can't click on it. That's why we need to use the button in the sidebar.

Copy link
Member

Choose a reason for hiding this comment

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

I think if you let CSS select the first available element it should toggle the sidebar alright:

const dismissSidebarButtonSelector =  '.wpcom-block-editor-nav-sidebar-nav-sidebar__dismiss-sidebar-button';
const toggleSidebarButtonSelector = '.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button';

async toggleNavigationSidebar() {
	return await driverHelper.clickWhenClickable(
		this.driver,
		By.css( toggleSidebarButtonSelector + ', ' + dismissSidebarButtonSelector );
	);
}

...assuming those selectors are correct 😉

Copy link
Member

Choose a reason for hiding this comment

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

Just checked those out in Gutenberg, and it seems we can use aria attributes as selectors. It's generally a better practice to use user-facing attributes as selectors as they're less likely to change and break the test. Notice also the rename to toggleBlockEditorSidebar as it seems to be the UI component name. Here's the updated version of the above toggle method:

async toggleBlockEditorSidebar() {
	const dismissSidebarButtonSelector =  'button[aria-label="Block editor sidebar"][aria-expanded="false"]';
	const toggleSidebarButtonSelector = 'button[aria-label="Close block editor sidebar"]';

	return await driverHelper.clickWhenClickable(
		this.driver,
		By.css( toggleSidebarButtonSelector + ', ' + dismissSidebarButtonSelector );
	);
}

Copy link
Contributor

@Addison-Stavlo Addison-Stavlo left a comment

Choose a reason for hiding this comment

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

Im noticing there are calypso_editor_sidebar_* events set up in the editing toolkit for the opening the panel and closing the editor via the dotcom sidebar version. It seems like some of this in the post editor might be redundant.

Comment on lines 11 to 18
export default () => ( {
id: 'wpcom-block-editor-nav-sidebar-open',
selector:
'.edit-post-header .wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button[aria-expanded="false"]',
type: 'click',
capture: true,
handler: () => tracksRecordEvent( 'wpcom_block_editor_nav_sidebar_open' ),
} );
Copy link
Contributor

@Addison-Stavlo Addison-Stavlo Jun 21, 2021

Choose a reason for hiding this comment

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

Looking more, I don't think we need to add this for the post-editor. It is already tracking calypso_editor_sidebar_open:

We don't easily see it in our logs since that comes from editing-toolkit and not wpcom-block-editor, but looking at t.gif under network requests should show it happening.

Comment on lines 11 to 15
export default () => ( {
id: 'wpcom-block-editor-close-click',
selector: '.edit-post-header .edit-post-fullscreen-mode-close',
selector:
'.edit-post-header .edit-post-fullscreen-mode-close:not(.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button), .wpcom-block-editor-nav-sidebar-nav-sidebar__home-button',
type: 'click',
Copy link
Contributor

Choose a reason for hiding this comment

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

Im starting to second guess our decision on this now. Looking further there is also a calypso_editor_sidebar_editor_close set up:

Although, I am not seeing this one firing when I use this close button for some reason. 🤔 I see it in recent tracks history though, there must be some inconsistency with the conditional, maybe it needs to record the event regardless of that condition.

@david-szabo97
Copy link
Contributor Author

That's a nice find @Addison-Stavlo ! Since the ETK is tracking open, dismiss and editor close, I guess we can just scope this down to removing the wpcom_block_editor_close_click event.

@david-szabo97 david-szabo97 changed the title Block Editor Tracking: Track "sidebar open" and "editor close" properly Block Editor Tracking: Remove "wpcom_block_editor_close_click" from W button Jun 22, 2021
async toggleNavigationSidebar() {
const isOpen = await driverHelper.isElementLocated(
this.driver,
By.css( '.wpcom-block-editor-nav-sidebar-nav-sidebar__click-guard' )
Copy link
Member

Choose a reason for hiding this comment

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

Is this nav-sidebar-nav-sidebar part intended here?

} else {
await driverHelper.clickWhenClickable(
this.driver,
By.css( '.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button' )
Copy link
Member

Choose a reason for hiding this comment

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

I think if you let CSS select the first available element it should toggle the sidebar alright:

const dismissSidebarButtonSelector =  '.wpcom-block-editor-nav-sidebar-nav-sidebar__dismiss-sidebar-button';
const toggleSidebarButtonSelector = '.wpcom-block-editor-nav-sidebar-toggle-sidebar-button__button';

async toggleNavigationSidebar() {
	return await driverHelper.clickWhenClickable(
		this.driver,
		By.css( toggleSidebarButtonSelector + ', ' + dismissSidebarButtonSelector );
	);
}

...assuming those selectors are correct 😉

const editor = await EditorComponent.Expect( this.driver, gutenbergEditorType );

await editor.toggleNavigationSidebar();
await editor.toggleNavigationSidebar();
Copy link
Member

Choose a reason for hiding this comment

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

Why a double call here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To make sure we don't leave it open for the next test. And it's also to make sure the event isn't triggered for both open and close action.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, gotcha. A short explanation comment would be nice then! 🙏

Comment on lines 171 to 175
assert.strictEqual(
editorCloseClickNotFired,
true,
'"wpcom_block_editor_close_click" editor tracking event fired'
);
Copy link
Member

@WunderBart WunderBart Jun 22, 2021

Choose a reason for hiding this comment

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

IMO this would be a cleaner way for this kind of assertions:

Suggested change
assert.strictEqual(
editorCloseClickNotFired,
true,
'"wpcom_block_editor_close_click" editor tracking event fired'
);
assert( editorCloseClickNotFired, '"wpcom_block_editor_close_click" editor tracking event fired' );

Comment on lines 169 to 170
eventsStack.filter( ( [ eventName ] ) => eventName === 'wpcom_block_editor_close_click' )
.length === 0;
Copy link
Member

@WunderBart WunderBart Jun 22, 2021

Choose a reason for hiding this comment

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

Suggested change
eventsStack.filter( ( [ eventName ] ) => eventName === 'wpcom_block_editor_close_click' )
.length === 0;
! eventsStack.some( ( [ eventName ] ) => eventName === 'wpcom_block_editor_close_click' );

@matticbot
Copy link
Contributor

This PR modifies the release build for editing-toolkit

To test your changes on WordPress.com, run install-plugin.sh editing-toolkit update/wpcom-nav-sidebar-tracking on your sandbox.

To deploy your changes after merging, see the documentation: PCYsg-mMA-p2

@david-szabo97
Copy link
Contributor Author

Thanks @WunderBart ! Made some changes according to your suggestions.

Comment on lines 167 to 172
/**
* Alias for `toggleNavigationSidebar`.
* We need to have the same function names in both
* this and gutenberg editor component to
* make sure general tests are working as expected.
*/
Copy link
Member

Choose a reason for hiding this comment

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

tip: If you're using VSCode, there's a neat extension that wraps the comments automatically for you: https://marketplace.visualstudio.com/items?itemName=stkb.rewrap. I've set it up to wrap at 100th column as it's what we've set for Prettier.

Copy link
Contributor

@Addison-Stavlo Addison-Stavlo Jun 24, 2021

Choose a reason for hiding this comment

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

I just installed this per your suggestion and its great!

@@ -158,6 +158,22 @@ export function createGeneralTests( { it, editorType, postType } ) {
);
} );

it( `W button should not trigger the "wpcom_block_editor_close_click" event when it's connected to a sidebar`, async function () {
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain how this test ensures that the W button is not triggering this event? I don't see that button being pressed anywhere... 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Ah, scratch that. I thought is's about a W key, like in WSAD 😅. Anyway, what that W button actually is on the page? 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right! We don't really have an offical name for the button. Either W Button, WP Button or Site Icon Button

Copy link
Member

Choose a reason for hiding this comment

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

Ah, makes sense! Although we did name it in the toggleBlockEditorSidebar as the sidebarButton, no? 😄 I think we can keep the "Block editor sidebar button" name for clarity, as it's what is displayed as the element's title:

Screenshot 2021-06-24 at 15 51 51

@matticbot
Copy link
Contributor

This PR modifies the release build for notifications

To test your changes on WordPress.com, run install-plugin.sh notifications update/wpcom-nav-sidebar-tracking on your sandbox.

To deploy your changes after merging, see the documentation: PCYsg-elI-p2

Copy link
Contributor

@Addison-Stavlo Addison-Stavlo left a comment

Choose a reason for hiding this comment

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

This looks good and works well on my end.

@david-szabo97 david-szabo97 merged commit ca585df into trunk Jun 30, 2021
@david-szabo97 david-szabo97 deleted the update/wpcom-nav-sidebar-tracking branch June 30, 2021 17:44
@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 Jun 30, 2021
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.

4 participants