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

Keep the Link Control settings drawer persistent #47989

Draft
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

abhi3315
Copy link
Contributor

@abhi3315 abhi3315 commented Feb 11, 2023

What?

This PR will keep the Link Control setting open if it is opened or closed if it was closed earlier.
By default, the setting drawer will be closed.

Why?

#47821
#47821 (comment)

How?

  • Get the state of the setting drawer from the preferences store.
  • Add a useEffect to set the preference whenever the setting drawer is opened/closed.

Testing Instructions

  • Go to the Gutenberg Editor.
  • Open/close the setting drawer of Link Control.
  • Check if the setting drawer is keeping the state.

Testing Instructions for Keyboard

Screenshots or screencast

GIF Recording 2023-02-11 at 2 54 04 PM

@github-actions github-actions bot added the First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository label Feb 11, 2023
@github-actions
Copy link

👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @abhi3315! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other.

If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information.

@getdave
Copy link
Contributor

getdave commented Feb 13, 2023

The tests are failing because of the toggle setting state because in each test setting drawer is supposed to be closed by default. But now the setting drawer state of LinkControl is persistent and will depend on the previous component state.

You could make a new hook (separate file) to get the preference and then mock the hook in the tests so you can control it.

For the existing tests we should set it to always return false (i.e. always closed by default) but we should try adding a test for the case when it returns true to assert the drawer behaves as we expect.

See edit/test/navigation-menu-selector.js for an example of this.

@getdave getdave added the [Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) label Feb 13, 2023
@getdave
Copy link
Contributor

getdave commented Feb 13, 2023

Minor: we tend to favour rebasing against trunk rather than merge commits.

@abhi3315 abhi3315 force-pushed the feat/link-control-setting-open branch from de13764 to 78a4f34 Compare February 23, 2023 03:52
Comment on lines +204 to +211
useEffect( () => {
dispatch( preferencesStore ).set(
'core/editor',
'linkControlSettingsOpen',
settingsOpen
);
}, [ settingsOpen ] );

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@getdave As per the comment you made on my earlier PR #47930 (comment)

I should not query the store in the component itself. So I might have to refactor the code.

@draganescu draganescu changed the title Keep the Link Control settings drawer persistant Keep the Link Control settings drawer persistent Feb 23, 2023
@getdave
Copy link
Contributor

getdave commented Feb 23, 2023

@draganescu I think you were envisaging some kind of heuristic here to determine when the drawer setting should be toggled?

Perhaps

if the user has toggled the drawer open/closed 3 or more times then set it to always be open/closed

If we do that I guess we'd need to store the temp "how many times toggled" state in Session Storage and then clear it once the preference is set?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Link Editing Link components (LinkControl, URLInput) and integrations (RichText link formatting) First-time Contributor Pull request opened by a first-time contributor to Gutenberg repository
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants