-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Phase 2: Capture Suggest-mode edits as an in-memory overlay #77404
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
Open
adamsilverstein
wants to merge
13
commits into
suggest-mode-phase-1
Choose a base branch
from
suggest-mode-phase-2
base: suggest-mode-phase-1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3ccc3be
Editor: Capture Suggest-mode edits as an in-memory overlay
adamsilverstein b09c96d
Editor: Harden overlay HOC and add pass-through + re-edit tests
adamsilverstein e97c901
Update lib/compat/wordpress-6.9/block-comments.php
adamsilverstein 7f23a40
Suggestions: Capture store-level mutations and harden equality checks
adamsilverstein a6507aa
Merge branch 'suggest-mode-phase-1' into suggest-mode-phase-2
adamsilverstein b5a9936
Suggestions: Preserve metadata.noteId linkage through the store inter…
adamsilverstein 5423ada
Merge phase-1 to pick up connectors e2e capability fix (#77857)
adamsilverstein fae1bd7
Suggestion mode: fix invalid notice status on submit success
adamsilverstein c20ac75
Merge phase-1 doc updates into phase-2
adamsilverstein 1071c8e
Suggestions: Add module headers explaining overlay and interceptor de…
adamsilverstein dfd1801
Merge remote-tracking branch 'origin/suggest-mode-phase-1' into sugge…
adamsilverstein b436847
Suggestions: Suppress new react-hooks lint errors for overlay HOC
adamsilverstein 9d144ea
Merge branch 'suggest-mode-phase-1' into suggest-mode-phase-2
adamsilverstein File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
packages/editor/src/components/suggestion-mode/commit-bar.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /** | ||
| * WordPress dependencies | ||
| */ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { | ||
| BlockControls, | ||
| store as blockEditorStore, | ||
| } from '@wordpress/block-editor'; | ||
| import { ToolbarGroup, ToolbarButton } from '@wordpress/components'; | ||
| import { useSelect } from '@wordpress/data'; | ||
| import { useCallback, useState } from '@wordpress/element'; | ||
|
|
||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { useSuggestionOverlay } from './overlay-context'; | ||
| import { operationsFromOverlay, useSuggestionsProvider } from './provider'; | ||
| import { EDITOR_STORE_NAME } from './constants'; | ||
|
|
||
| /** | ||
| * Block toolbar group that surfaces Submit / Discard controls whenever the | ||
| * currently selected block has a pending suggestion overlay. | ||
| * | ||
| * The bar is a shared singleton — mounted once per editor provider rather | ||
| * than once per block — because the block-editor's `BlockControls` fill | ||
| * automatically targets the selected block's toolbar slot. | ||
| * | ||
| * @return {React.ReactNode|null} Toolbar markup, or null if nothing pending. | ||
| */ | ||
| export default function SuggestionCommitBar() { | ||
| const { entries, clearOverlay } = useSuggestionOverlay(); | ||
| const { createSuggestion } = useSuggestionsProvider(); | ||
|
|
||
| const { selectedClientId, isSuggestMode } = useSelect( ( select ) => { | ||
| return { | ||
| selectedClientId: | ||
| select( blockEditorStore ).getSelectedBlockClientId(), | ||
| isSuggestMode: | ||
| select( EDITOR_STORE_NAME ).getEditorIntent?.() === 'suggest', | ||
| }; | ||
| }, [] ); | ||
|
|
||
| const [ isSubmitting, setIsSubmitting ] = useState( false ); | ||
| const entry = selectedClientId ? entries[ selectedClientId ] : null; | ||
| const hasOverlay = | ||
| !! entry && Object.keys( entry.overlayAttributes ).length > 0; | ||
|
|
||
| const onSubmit = useCallback( async () => { | ||
| if ( ! entry || isSubmitting ) { | ||
| return; | ||
| } | ||
| const operations = operationsFromOverlay( | ||
| entry.baselineAttributes, | ||
| entry.overlayAttributes | ||
| ); | ||
| if ( operations.length === 0 ) { | ||
| clearOverlay( selectedClientId ); | ||
| return; | ||
| } | ||
| setIsSubmitting( true ); | ||
| try { | ||
| await createSuggestion( { | ||
| clientId: selectedClientId, | ||
| blockName: entry.blockName, | ||
| operations, | ||
| } ); | ||
| clearOverlay( selectedClientId ); | ||
| } catch { | ||
| // Notice surfaced by the provider. | ||
| } finally { | ||
| setIsSubmitting( false ); | ||
| } | ||
| }, [ | ||
| entry, | ||
| isSubmitting, | ||
| selectedClientId, | ||
| clearOverlay, | ||
| createSuggestion, | ||
| ] ); | ||
|
|
||
| const onDiscard = useCallback( () => { | ||
| if ( selectedClientId ) { | ||
| clearOverlay( selectedClientId ); | ||
| } | ||
| }, [ selectedClientId, clearOverlay ] ); | ||
|
|
||
| if ( ! isSuggestMode || ! hasOverlay ) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <BlockControls group="other"> | ||
| <ToolbarGroup> | ||
| <ToolbarButton | ||
| variant="primary" | ||
| onClick={ onSubmit } | ||
| disabled={ isSubmitting } | ||
| > | ||
| { isSubmitting | ||
| ? __( 'Submitting…' ) | ||
| : __( 'Submit suggestion' ) } | ||
| </ToolbarButton> | ||
| <ToolbarButton onClick={ onDiscard } disabled={ isSubmitting }> | ||
| { __( 'Discard' ) } | ||
| </ToolbarButton> | ||
| </ToolbarGroup> | ||
| </BlockControls> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /** | ||
| * The editor store is referenced by its registered name rather than being | ||
| * imported directly to avoid a module cycle between the suggestion-mode | ||
| * subsystem, the editor store, and the editor provider (which mounts | ||
| * `SuggestionOverlayProvider`). | ||
| */ | ||
| export const EDITOR_STORE_NAME = 'core/editor'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export { | ||
| SuggestionOverlayProvider, | ||
| useSuggestionOverlay, | ||
| overlayReducer, | ||
| } from './overlay-context'; | ||
| export { | ||
| default as withSuggestionOverlay, | ||
| registerSuggestionOverlayFilter, | ||
| } from './with-suggestion-overlay'; | ||
| export { default as SuggestionCommitBar } from './commit-bar'; | ||
| export { | ||
| useSuggestionsProvider, | ||
| operationsFromOverlay, | ||
| SCHEMA_VERSION, | ||
| } from './provider'; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.