-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Edit Site: Add template loading. (#19081)
* Edit Site: Add root template ID to editor settings. * Edit Site: Load root template in block editor. * Lib: Update demo block template. * Lib: Rename demo block template. * Edit Site: Serialize blocks on persistent changes. * Edit Site: Add multiple entity saving functionality.
- Loading branch information
Showing
10 changed files
with
142 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 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 |
---|---|---|
|
@@ -31,3 +31,7 @@ | |
font-size: 16px; | ||
padding: 0 20px; | ||
} | ||
|
||
.edit-site-header__actions { | ||
padding: 0 20px; | ||
} |
This file contains 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,56 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useEntityProp } from '@wordpress/core-data'; | ||
import { useEffect, useState, useCallback } from '@wordpress/element'; | ||
import { useSelect } from '@wordpress/data'; | ||
import { Button } from '@wordpress/components'; | ||
import { __ } from '@wordpress/i18n'; | ||
import { EntitiesSavedStates } from '@wordpress/editor'; | ||
|
||
export default function SaveButton() { | ||
const [ , setStatus ] = useEntityProp( 'postType', 'wp_template', 'status' ); | ||
// Publish template if not done yet. | ||
useEffect( () => setStatus( 'publish' ), [] ); | ||
|
||
const { isDirty, isSaving } = useSelect( ( select ) => { | ||
const { getEntityRecordChangesByRecord, isSavingEntityRecord } = select( | ||
'core' | ||
); | ||
const entityRecordChangesByRecord = getEntityRecordChangesByRecord(); | ||
const changedKinds = Object.keys( entityRecordChangesByRecord ); | ||
return { | ||
isDirty: changedKinds.length > 0, | ||
isSaving: changedKinds.some( ( changedKind ) => | ||
Object.keys( | ||
entityRecordChangesByRecord[ changedKind ] | ||
).some( ( changedName ) => | ||
Object.keys( | ||
entityRecordChangesByRecord[ changedKind ][ changedName ] | ||
).some( ( changedKey ) => | ||
isSavingEntityRecord( changedKind, changedName, changedKey ) | ||
) | ||
) | ||
), | ||
}; | ||
} ); | ||
const disabled = ! isDirty || isSaving; | ||
|
||
const [ isOpen, setIsOpen ] = useState( false ); | ||
const open = useCallback( setIsOpen.bind( null, true ), [] ); | ||
const close = useCallback( setIsOpen.bind( null, false ), [] ); | ||
return ( | ||
<> | ||
<Button | ||
isPrimary | ||
aria-disabled={ disabled } | ||
disabled={ disabled } | ||
isBusy={ isSaving } | ||
onClick={ disabled ? undefined : open } | ||
> | ||
{ __( 'Update' ) } | ||
</Button> | ||
<EntitiesSavedStates isOpen={ isOpen } onRequestClose={ close } /> | ||
</> | ||
); | ||
} |