-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Patterns: add option to set sync status when adding from wp-admin patterns list #52352
Conversation
Size Change: +205 B (0%) Total Size: 1.43 MB
ℹ️ View Unchanged
|
Flaky tests detected in 46b3c29. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/5516265431
|
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.
Thanks for addressing this issue @glendaviesnz 👍
I'm running into a few issues when testing this.
- When first visiting the editor via Add New, the modal didn't show. I had to find that the summary panel was collapsed. After expanding that, the modal displayed.
- When I selected synced status, then hit Publish, I got an error: "Publishing failed. The wp_pattern_sync_status property has an invalid stored value, and cannot be updated to null"
Screen.Recording.2023-07-06.at.1.26.46.pm.mp4
Just gave this a quick test and can confirm the modal doesn't display if the Settings sidebar is collapsed. |
<ReusableBlocksRenameHint /> | ||
<ToggleControl | ||
label={ __( 'Synced' ) } | ||
help={ __( |
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.
Maybe change the help text to match the state depending on syncType
?
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.
According to @SaxonF the toggle control standard is to always/only show the positive state help text
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.
Fair enough, makes sense 👍🏻 I guess it can be seen as a checkbox in that regard. Cheers!
editPost( { | ||
meta: { | ||
wp_pattern_sync_status: | ||
syncType === 'unsynced' ? 'unsynced' : null, |
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.
This isn't working quite right for me, and I'm not sure it's doing anything.
I opt into creating a an unsynced pattern, then publish it. But when I use it in a post it is synced.
In fact all patterns created in this flow are synced by default with or without this callback. I assume it's a default value of the wp_pattern_sync_status
property of the WP_Block
class/type.
Therefore wp_pattern_sync_status
is always null
despite this editPost()
call - and possibly why I'm seeing an error when I try to publish a synced pattern? That is, setting null
to what's already null
??
I don't know.
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.
should have been set to undefined
instead of null
I think I have fixed the issues noted, so should be ready for a retest. |
Could you confirm if what I'm seeing is right? I've selected a non-synced pattern, but after save it's "Fully synced" 2023-07-11.10.31.52.mp4 |
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.
I'm still seeing unsynced patterns convert to synced onSave.
Very likely it's me (?)
export function PostSyncStatusModal() { | ||
const { editPost } = useDispatch( editorStore ); | ||
const [ isModalOpen, setIsModalOpen ] = useState( false ); | ||
const [ syncType, setSyncType ] = useState( 'fully' ); |
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.
Do we need 'fully'
? To me it introduces an extra, needles state.
Could we use what the meta understands instead? E.g., 'unsynced'
or undefined
.
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.
yeh, good point, I have simplified it so synced === undefined everywhere
aba7b36
to
81ddf49
Compare
@ramonjd seems like a rebase as resolved the issue running against 6.3 beta |
const currentSyncStatus = | ||
meta.wp_pattern_sync_status === 'unsynced' ? 'unsynced' : syncStatus; |
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.
Is meta
always an object? Just wondering if we need optional chaining here... feel free to ignore if it is always an object! 🙂
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.
In all my testing the entity always seems to have meta
set as an object, even if it doesn't have any postmeta fields configured.
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.
Excellent. Thanks for confirming!
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.
actually, to be 100% correct after double checking, sometimes it is actually an empty array, in which case it still won't fail with an undefined error as never seems to be undefined so I don't think optional chaining is needed - but let me know if you have any concerns about that
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.
I updated to meta?.wp_pattern_sync_status === 'unsynced' ? 'unsynced' : syncStatus
Can't hurt, right?
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.
Thanks! Probably good to be on the safe side if a call to a selector doesn't necessarily guarantee that an object is returned. From a quick look up from getEditedPostAttribute
, it winds up calling getCurrentPostAttribute
, which internally calls getCurrentPost
. If for some reason getCurrentPost
returns its default empty object, then getCurrentPostAttribute
could potentially return undefined around these lines:
gutenberg/packages/editor/src/store/selectors.js
Lines 280 to 283 in 81ddf49
default: | |
const post = getCurrentPost( state ); | |
if ( ! post.hasOwnProperty( attributeName ) ) { | |
break; |
In practice, I doubt that'll ever be hit because (in theory) there'll always be a post object of some kind around, but this hardens the logic a little.
Cheers! 🍻
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.
Nice digging! We just might thank ourselves later 😄
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.
Testing on top of the changes in #52494
This works as advertised.
The modal doesn't appear in the site editor when creating a pattern, and I can now create unsynced patterns in the editor for new wp_block posts.
Thanks for sticking with this!
…terns list (#52352) * Show a modal to set sync status if adding pattern from pattern list page * Make sure the modal loads if post settings panel not open * don't load modal component at all if not new post * Simplify the sync status so undefined always = synced * Update packages/editor/src/components/post-sync-status/index.js --------- Co-authored-by: Ramon <ramonjd@users.noreply.github.com>
Was this backported to WP6.3beta4? |
Thanks for testing @bvlgn. It just missed the deadline I think but will be in the next build. |
* Site Editor: Restore quick inserter 'Browse all' button (#52529) * Site Editor: Restore quick inserter 'Browse all' button * Remove leftover comment * Patterns: update the title of Pattern block in the block inspector card (#52010) * Site Editor Pages: load the appropriate template if posts page set (#52266) * This commit: - links the posts page to the homepage template when a post page is set - abstracts logic to get page item props * The Posts Page resolves to display the Home or Index template only. Adding a check to skip the Front Page * Showing homepage settings for posts pages that are set as the post page in reading settings * Post pages that have been set to display posts will redirect to first the home template, then the index template. The fallback is the post id of the page. * Reverted refactor of packages/edit-site/src/components/sidebar-navigation-screen-page/index.js Will do it in a follow up * Allow editing existing footnote from formats toolbar (#52506) * Block Editor: Display variation icon in the 'BlockDraggable' component (#52502) * Patterns: add option to set sync status when adding from wp-admin patterns list (#52352) * Show a modal to set sync status if adding pattern from pattern list page * Make sure the modal loads if post settings panel not open * don't load modal component at all if not new post * Simplify the sync status so undefined always = synced * Update packages/editor/src/components/post-sync-status/index.js --------- Co-authored-by: Ramon <ramonjd@users.noreply.github.com> * Revise LinkControl suggestions UI to use MenuItem (#50978) * Use "link" instead of "URL" for URL_TYPE * Use MenuItem for search create button * Use sentence case for "Create page" * Use a MenuGroup for search results * Use MenuItem for search item * Refactoring styles (WIP) * Preserve whitespace in results text * Reinstate result item information including permalink * Remove debugging CSS code * Reinstate CSS to control size of rich previews favicon * Remove other commented out CSS code * Reinstate selected styles * Remove more redundant CSS * Add some basic results hover/focus styling. Needs improving * Improve icon alignment * Update tests to handle wording changes * Remove inconsistent hover/focus style MenuItem already has hover/focus styles * Reinstate is-selected visual state * Update test to make sense in context of #51011 See #51011 * Fix locator for result text --------- Co-authored-by: Dave Smith <getdavemail@gmail.com> * Fix LinkControl mark highlight to bold (#52517) * Add 'reusable' keyword to Pattern blocks (#52543) * Fix missing Add Template Part button in Template Parts page (#52542) * Tweak copy for the reusable block rename hint (#52581) * Trim footnote anchors from excerpts (#52518) * Trim footnote anchors from excerpts * Add comments, fix spacing, appease linter * Site Editor: Reset device preview type when exiting the editing mode (#52566) * Make "My patterns" permanently visible (#52531) * Hide site hub when resizing frame upwards to avoid overlap (#52180) * Fix "Manage all patterns" link appearance (#52532) * Fix "Manage all patterns" link * Update focus style * Update navigation menu title size & weight in detail panels (#52477) * Update menu title size * Adjust font weight * Site Editor Patterns: Ensure sidebar does not shrink when long pattern titles are used (#52547) * Edit Site: Select templateType from the store inside the useSiteEditorSettings hook (#52503) * Add width to ensure ellipsis is applied (#52575) * Cover Block: Fix block deprecation when fixed background is enabled (#51612) * ResizableFrame: Make keyboard accessible (#52443) * ResizableFrame: Make keyboard accessible * Fix outline in Safari * Use proper CSS modifier * Add aria-label to button * Keep handle enlarged when resizing (Safari) * Add back visually hidden help text * Don't switch to edit mode * Make the handle a role="separator" * Revert to `button` * Switch description text to `div hidden` * Prevent keydown event default when right/left arrow * Change minimum frame width to 320px * Mention shift key in description text * Only render resize handle when in View mode * Fix importing classic menus (#52573) * use the same create hook for classic import * Remove redundant arg to hook --------- Co-authored-by: Dave Smith <getdavemail@gmail.com> * Site Editor: Fix navigation menu sidebar actions order and label (#52592) * Avoid errors in Dimension visualizers when switching between iframed and non-iframed editors (#52588) * Patterns: Add client side pagination to patterns list (#52538) Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com> * Site Editor: Make sidebar back button go *back* instead of *up* if possible (#52456) * Navigator: Add replace option to goTo() and goToParent() * Site Editor: Make sidebar back button go back instead of up if possible * Adapt template part hint copy (#52527) * Try "panel" instead of "page" * Update template-part-hint.js --------- Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com> Co-authored-by: Glen Davies <glendaviesnz@users.noreply.github.com> Co-authored-by: Ramon <ramonjd@users.noreply.github.com> Co-authored-by: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Co-authored-by: Rich Tabor <hi@richtabor.com> Co-authored-by: Dave Smith <getdavemail@gmail.com> Co-authored-by: Robert Anderson <robert@noisysocks.com> Co-authored-by: James Koster <james@jameskoster.co.uk> Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Co-authored-by: arthur791004 <arthur.chu@automattic.com> Co-authored-by: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Co-authored-by: Lena Morita <lena@jaguchi.com> Co-authored-by: Andrei Draganescu <me@andreidraganescu.info> Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
What?
Adds option to set sync status when adding from wp-admin patterns list.
Why?
Currently adding patterns from this page will always create synced patterns.
Fixes: #52329
How?
Shows a modal to set sync status for new patterns.
Testing Instructions
/wp-admin/edit.php?post_type=wp_block
and clickAdd new
buttonScreenshots or screencast
set-sync.mp4