-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Migrate post editor feature preferences to use new preferences package #39115
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -14,7 +14,7 @@ import { toggleMoreMenu } from './toggle-more-menu'; | |||||||||||||
|
||||||||||||||
const SELECTORS = { | ||||||||||||||
postEditorMenuContainer: | ||||||||||||||
'//*[contains(concat(" ", @class, " "), " edit-post-more-menu__content ")]', | ||||||||||||||
'//*[contains(concat(" ", @class, " "), " interface-more-menu-dropdown__content ")]', | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we target using something that's user oriented e.g. ARIA label? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be tricky as the block toolbar has an identical label for its settings menu. I would like to get rid of this logic that uses a different class name for the site editor: gutenberg/packages/e2e-test-utils/src/click-on-more-menu-item.js Lines 15 to 20 in 11ae04c
I'll be able to remove that once I've done the migration for the site editor, so at that point I'll loop back and improve this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my experience user-facing labels change more often than classnames 😅 |
||||||||||||||
siteEditorMenuContainer: | ||||||||||||||
'//*[contains(concat(" ", @class, " "), " edit-site-more-menu__content ")]', | ||||||||||||||
}; | ||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,16 +11,16 @@ describe( 'popovers', () => { | |
describe( 'dropdown', () => { | ||
it( 'toggles via click', async () => { | ||
const isMoreMenuOpen = async () => | ||
!! ( await page.$( '.edit-post-more-menu__content' ) ); | ||
!! ( await page.$( '.interface-more-menu-dropdown__content' ) ); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same again here. Could be a good opportunity to make these tests less dependent on implementation details such as class name. |
||
|
||
expect( await isMoreMenuOpen() ).toBe( false ); | ||
|
||
// Toggle opened. | ||
await page.click( '.edit-post-more-menu > button' ); | ||
await page.click( '.interface-more-menu-dropdown > button' ); | ||
expect( await isMoreMenuOpen() ).toBe( true ); | ||
|
||
// Toggle closed. | ||
await page.click( '.edit-post-more-menu > button' ); | ||
await page.click( '.interface-more-menu-dropdown > button' ); | ||
expect( await isMoreMenuOpen() ).toBe( false ); | ||
} ); | ||
} ); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,8 @@ | |
import { __ } from '@wordpress/i18n'; | ||
import { MenuGroup } from '@wordpress/components'; | ||
import { | ||
ActionItem, | ||
MoreMenuDropdown, | ||
ActionItem, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was this an accident? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seems like it. I'll switch it back as I like alphabetical order. |
||
PinnedItems, | ||
} from '@wordpress/interface'; | ||
import { useViewportMatch } from '@wordpress/compose'; | ||
|
@@ -18,17 +18,11 @@ import PreferencesMenuItem from '../preferences-menu-item'; | |
import ToolsMoreMenuGroup from '../tools-more-menu-group'; | ||
import WritingMenu from '../writing-menu'; | ||
|
||
const POPOVER_PROPS = { | ||
className: 'edit-post-more-menu__content', | ||
}; | ||
|
||
const MoreMenu = ( { showIconLabels } ) => { | ||
const isLargeViewport = useViewportMatch( 'large' ); | ||
|
||
return ( | ||
<MoreMenuDropdown | ||
className="edit-post-more-menu" | ||
popoverProps={ POPOVER_PROPS } | ||
toggleProps={ { | ||
showTooltip: ! showIconLabels, | ||
...( showIconLabels && { variant: 'tertiary' } ), | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,8 +8,9 @@ import { castArray, reduce } from 'lodash'; | |
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import apiFetch from '@wordpress/api-fetch'; | ||
import { speak } from '@wordpress/a11y'; | ||
import { store as interfaceStore } from '@wordpress/interface'; | ||
import { store as preferencesStore } from '@wordpress/preferences'; | ||
import { speak } from '@wordpress/a11y'; | ||
import { store as noticesStore } from '@wordpress/notices'; | ||
import { store as coreStore } from '@wordpress/core-data'; | ||
import { store as blockEditorStore } from '@wordpress/block-editor'; | ||
|
@@ -147,10 +148,13 @@ export function removeEditorPanel( panelName ) { | |
* @param {string} feature Feature name. | ||
*/ | ||
export const toggleFeature = ( feature ) => ( { registry } ) => | ||
registry | ||
.dispatch( interfaceStore ) | ||
.toggleFeature( 'core/edit-post', feature ); | ||
registry.dispatch( preferencesStore ).toggle( 'core/edit-post', feature ); | ||
Comment on lines
150
to
+151
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is the option of deprecating the existing actions and selectors in There's quite a lot of usage across the codebase (and possibly in plugins too), so I haven't done that. I'd be happy to address that in a follow-up if reviewers feel a deprecation is best. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I think we should deprecate it. Otherwise future devs will mistakenly use this one. Since it is a method that made it into Core, we can't remove the method, but that's okay. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What form could that deprecation take? I'm thinking we could add some sort of message in the actions and selectors but we might never be able to remove them altogether without risk of breaking things for plugins. It would be good to update usage in this codebase anyway, to make sure we're setting the right example (definitely a follow-up job though!) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes because it shipped in Core we have to follow the Core deprecation policy which is to call |
||
|
||
/** | ||
* Triggers an action used to switch editor mode. | ||
* | ||
* @param {string} mode The editor mode. | ||
*/ | ||
export const switchEditorMode = ( mode ) => ( { dispatch, registry } ) => { | ||
dispatch( { | ||
type: 'SWITCH_MODE', | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few lines above this we have a comment about WordPress 6.0. What's up with that? I imagine this stuff needs to stay around forever, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I don't know what the policy is, that note is definitely outdated though, I'll remove it for now. There were some previous very old migrations in the past that had a note to remove them, so I did that. Was that a bad idea? 😄
Maybe it's worth being a bit more careful now that there are a few preferences that affect accessibility.
Previously the functionality tied to this was fairly minor (fullscreen mode, top toolbar).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It depends what the migrations did 😀
If e.g. WordPress 5.0 stored something in
localStorage
in an old format then WordPress 6.0 needs to be able to migrate that.If it was only ever in the Gutenberg plugin then we can safely delete the migration after a few versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Mind you, "needs" is a strong word, it's not very impactful when migration doesn't work as localStorage tends to be cleared by the user periodically anyway.)