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

Site editor: Fix opening of save panel when using the save shortcut #59647

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 10 additions & 4 deletions packages/edit-site/src/components/keyboard-shortcuts/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { useShortcut } from '@wordpress/keyboard-shortcuts';
import { useDispatch, useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { store as editorStore } from '@wordpress/editor';

/**
* Internal dependencies
Expand All @@ -13,20 +14,25 @@ import { store as editSiteStore } from '../../store';
function KeyboardShortcutsGlobal() {
const { __experimentalGetDirtyEntityRecords, isSavingEntityRecord } =
useSelect( coreStore );
const { hasNonPostEntityChanges } = useSelect( editorStore );
const { setIsSaveViewOpened } = useDispatch( editSiteStore );

useShortcut( 'core/edit-site/save', ( event ) => {
event.preventDefault();

const dirtyEntityRecords = __experimentalGetDirtyEntityRecords();
const isDirty = !! dirtyEntityRecords.length;
const hasDirtyEntities = !! dirtyEntityRecords.length;
const isSaving = dirtyEntityRecords.some( ( record ) =>
isSavingEntityRecord( record.kind, record.name, record.key )
);

if ( ! isSaving && isDirty ) {
setIsSaveViewOpened( true );
const _hasNonPostEntityChanges = hasNonPostEntityChanges();
if ( ! hasDirtyEntities || ! _hasNonPostEntityChanges || isSaving ) {
return;
}
// At this point, we know that there are dirty entities, other than
// the edited post, and we're not in the process of saving, so open
// save view.
setIsSaveViewOpened( true );
} );

return null;
Expand Down