Repository navigation
Media editor: Lock the editing tools while a save is running #82417
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
Changes from 3 commits
ad9ea05
262896a
da755ce
879a934
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,12 +116,15 @@ interface MediaEditorSidebarProps { | |
| /** The open panel's id. Always one of `tabs`. */ | ||
| activeTab: string; | ||
| onSelectTab: ( tab: string ) => void; | ||
| /** Freeze the open panel while the edit is saving. */ | ||
| disabled?: boolean; | ||
| } | ||
|
|
||
| function MediaEditorSidebar( { | ||
| tabs, | ||
| activeTab, | ||
| onSelectTab, | ||
| disabled = false, | ||
| }: MediaEditorSidebarProps ) { | ||
| return ( | ||
| <NavigableRegion | ||
|
|
@@ -146,7 +149,11 @@ function MediaEditorSidebar( { | |
| <div className="media-editor__tablist"> | ||
| <Tabs.List variant="minimal"> | ||
| { tabs.map( ( tab ) => ( | ||
| <Tabs.Tab key={ tab.id } value={ tab.id }> | ||
| <Tabs.Tab | ||
| key={ tab.id } | ||
| value={ tab.id } | ||
| disabled={ disabled } | ||
| > | ||
| { tab.title } | ||
| </Tabs.Tab> | ||
| ) ) } | ||
|
|
@@ -320,6 +327,9 @@ function HistoryActions() { | |
| redoCrop(); | ||
| }; | ||
| const handleReset = () => { | ||
| if ( isUndoRedoDisabled ) { | ||
| return; | ||
| } | ||
| beginGesture(); | ||
| reset(); | ||
| onReset(); | ||
|
|
@@ -334,7 +344,7 @@ function HistoryActions() { | |
| <Button | ||
| size="compact" | ||
| variant="tertiary" | ||
| disabled={ ! isDirty } | ||
| disabled={ isUndoRedoDisabled || ! isDirty } | ||
| accessibleWhenDisabled | ||
| onClick={ handleReset } | ||
| > | ||
|
|
@@ -600,6 +610,14 @@ function MediaEditorContent( { | |
| } ); | ||
|
|
||
| const handleChange = ( updates: Partial< Media > ) => { | ||
| // A save reads the pending edits once and then waits. An edit | ||
| // arriving after that read misses the request, and a crop save | ||
| // then clears the edits for this id, so it would be lost rather | ||
| // than merely late. It would also land on the attachment being | ||
| // replaced, not the new one the modal moves to. | ||
| if ( isSaving ) { | ||
| return; | ||
| } | ||
| editEntityRecord( 'postType', 'attachment', id, updates ); | ||
| }; | ||
|
|
||
|
|
@@ -634,7 +652,7 @@ function MediaEditorContent( { | |
| ! target.closest( `[${ CROP_CONTROL_ATTR }]` ); | ||
| if ( ! isMetadataField ) { | ||
| event.preventDefault(); | ||
| if ( isCropInteractionActive ) { | ||
| if ( isCropInteractionActive || isSaving ) { | ||
| return; | ||
| } | ||
| if ( isRedoShortcut ) { | ||
|
|
@@ -677,6 +695,7 @@ function MediaEditorContent( { | |
| <MediaEditorImageControls | ||
| showAspectRatioControl | ||
| aspectRatioPresets={ aspectRatioPresets } | ||
| disabled={ isSaving } | ||
| /> | ||
| ) : null; | ||
|
|
||
|
|
@@ -694,6 +713,7 @@ function MediaEditorContent( { | |
| aspectRatioValue={ aspectRatioValue } | ||
| onAspectRatioChange={ setAspectRatioValue } | ||
| aspectRatioOptions={ aspectRatioOptions } | ||
| disabled={ isSaving } | ||
| /> | ||
| ), | ||
| }, | ||
|
|
@@ -709,14 +729,24 @@ function MediaEditorContent( { | |
| const ruler = isImage ? ( | ||
| <MediaEditorFineRotation | ||
| onPlacementControlInteraction={ signalPlacementControlInteraction } | ||
| disabled={ isSaving } | ||
| /> | ||
| ) : null; | ||
|
|
||
| const children = ( | ||
| <MediaEditorProvider | ||
| value={ media ?? undefined } | ||
| onChange={ handleChange } | ||
| settings={ { fields } } | ||
| settings={ { | ||
| // Show the fields as read-only while saving, so the guard | ||
| // in `handleChange` is not silently swallowing typing. | ||
| fields: isSaving | ||
| ? fields.map( ( field ) => ( { | ||
| ...field, | ||
| readOnly: true, | ||
|
Contributor
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. If we're going to mutate the fields while saving, I think we should probably is
Member
Author
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. You bet. Thanks for reviewing. Much better idea |
||
| } ) ) | ||
| : fields, | ||
| } } | ||
| > | ||
| <div className="media-editor"> | ||
| { ! media ? ( | ||
|
|
@@ -745,6 +775,7 @@ function MediaEditorContent( { | |
| handleCanvasGestureStart | ||
| } | ||
| onGestureEnd={ handleCanvasGestureEnd } | ||
| disabled={ isSaving } | ||
| /> | ||
| ) : ( | ||
| <MediaPreview /> | ||
|
|
@@ -773,6 +804,7 @@ function MediaEditorContent( { | |
| : DETAILS_PANEL | ||
| } | ||
| onSelectTab={ selectPanel } | ||
| disabled={ isSaving } | ||
| /> | ||
| ) } | ||
| </div> | ||
|
|
@@ -805,7 +837,10 @@ function MediaEditorContent( { | |
| isSaving, | ||
| hasMedia: !! media, | ||
| hasChanges, | ||
| isUndoRedoDisabled: isCropInteractionActive, | ||
| // Saving freezes the whole edit surface: `save()` reads the | ||
| // modifiers once and then awaits, so anything changed after that | ||
| // would be silently dropped when the save resolves. | ||
| isUndoRedoDisabled: isCropInteractionActive || isSaving, | ||
|
coderabbitai[bot] marked this conversation as resolved.
Resolved
|
||
| aspectRatioPresets, | ||
| isWide, | ||
| activePanel, | ||
|
|
||
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.
So the thing can be disabled at a higher level, by consumers