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

Plugins: Ensure sidebar plugins do not get auto-closed when opened on… #17712

Merged
merged 5 commits into from
Oct 3, 2019

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Oct 2, 2019

… small screens

Description

Fixes #17623.

GIF:

ipad

Note how the Yoast pinned plugin sidebar is visible in the toolbar, but not clickable.

Even the item in the ellipsis menu doesn't invoke the sidebar.

As a reminder, pinned items are not visible on mobile (up to the 600px breakpoint), so all plugin sidebars should have a menu item so you can invoke them from there.

At the iPad breakpoint, the pinned item SHOULD be visible and SHOULD function, even if it opens the sidebar as a fullscreen modal interface.

I figured out what caused regression here:

This forces the sidebar to get closed on small screens immediately after it gets opened.

Related PR which introduced the regression: #15444

@gziolo gziolo added [Type] Bug An existing feature does not function as intended [Feature] Plugins API Extending the Gutenberg project with plugins via the Plugins API [Type] Regression Related to a regression in the latest release labels Oct 2, 2019
@gziolo gziolo requested a review from nerrad October 2, 2019 12:45
@gziolo gziolo requested a review from talldan as a code owner October 2, 2019 12:45
@gziolo gziolo self-assigned this Oct 2, 2019
@gziolo gziolo requested review from ajitbohra and ntwb as code owners October 2, 2019 13:16
@gziolo
Copy link
Member Author

gziolo commented Oct 2, 2019

I added a new e2e test which covers the case when you open the plugin sidebar on medium screens.

There are 2 unit tests failing which still need to be investigated. See:

https://travis-ci.com/WordPress/gutenberg/jobs/241095619#L5659

FAIL packages/edit-post/src/components/editor-initialization/test/listener-hooks.js
  ● listener hook tests › useAdjustSidebarListener › closes sidebar if viewport is small and there is an active sidebar name available
    expect(jest.fn()).toHaveBeenCalledTimes(1)
    Expected mock function to have been called one time, but it was called zero times.
      150 | 			expect(
      151 | 				getSpyedFunction( STORE_KEY, 'closeGeneralSidebar' )
    > 152 | 			).toHaveBeenCalledTimes( 1 );
          | 			  ^
      153 | 		} );
      154 | 		it( 'opens sidebar if viewport is not small, and there is a cached sidebar to ' +
      155 | 			'reopen on expand', () => {
      at Object.toHaveBeenCalledTimes (packages/edit-post/src/components/editor-initialization/test/listener-hooks.js:152:6)
  ● listener hook tests › useAdjustSidebarListener › opens sidebar if viewport is not small, and there is a cached sidebar to reopen on expand
    expect(jest.fn()).toHaveBeenCalledWith(expected)
    Expected mock function to have been called with:
      ["foo"]
    But it was not called.
      165 | 			expect(
      166 | 				getSpyedFunction( STORE_KEY, 'openGeneralSidebar' )
    > 167 | 			).toHaveBeenCalledWith( 'foo' );
          | 			  ^
      168 | 			expect(
      169 | 				getSpyedFunction( STORE_KEY, 'openGeneralSidebar' )
      170 | 			).toHaveBeenCalledTimes( 1 );
      at Object.toHaveBeenCalledWith (packages/edit-post/src/components/editor-initialization/test/listener-hooks.js:167:6)

With the fix implemented in the tested hook, expecations for initial state of the hook changes since the effect bails early when the current state of `isSmall` from the viewport store matches the previous state stored on the ref.

On initial render, this hook will always bail early.

I also added some inline comments to help explain what is happening in the test and what is expected.
@nerrad
Copy link
Contributor

nerrad commented Oct 2, 2019

I've updated the existing jest unit tests due to new expectations with the changes in this pull.

With the fix implemented in the tested hook, expectations for initial state of the hook changes since the effect bails early when the current state of isSmall from the viewport store matches the previous state stored on the ref.

On initial render, this hook will always bail early.

I also added some inline comments to help explain what is happening in the test and what is expected.

Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

I added a few commits:

  • fixing unit tests
  • fixing a minor code style issue
  • updating the changelog for the edit-post package.

Once tests pass this should be good to go.

@gziolo
Copy link
Member Author

gziolo commented Oct 2, 2019

Thank you for all the help with fixing this regression. Great team work ❤️

Does it mean that I managed to tweak those refs and hooks properly? It’s something which felt a bit like a hack but I couldn’t think of s better way. I only know that refs are popular in this context.

@nerrad
Copy link
Contributor

nerrad commented Oct 3, 2019

Does it mean that I managed to tweak those refs and hooks properly?

Looks fine to me 👍

@gziolo gziolo merged commit 8c0c7b7 into master Oct 3, 2019
@gziolo gziolo deleted the fix/17623-sidebar-plugins-closed-small-screens branch October 3, 2019 07:53
@youknowriad youknowriad added this to the Gutenberg 6.7 milestone Oct 14, 2019
gziolo added a commit that referenced this pull request Oct 15, 2019
#17712)

* Plugins: Ensure sidebar plugins do not get auto-closed when opened on small screens

* Tests: Add e2e test which ensures that the plugin sidebar gets operned on medium screens

* update tests due to new expectations.

With the fix implemented in the tested hook, expecations for initial state of the hook changes since the effect bails early when the current state of `isSmall` from the viewport store matches the previous state stored on the ref.

On initial render, this hook will always bail early.

I also added some inline comments to help explain what is happening in the test and what is expected.

* fix code style issue

* Add changelog entry for edit-post package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Plugins API Extending the Gutenberg project with plugins via the Plugins API [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Pinned plugin sidebars are visible in iPad portrait, but not clickable
3 participants