-
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.
DataViews: Bootstrap Quick Edit (#63600)
Co-authored-by: youknowriad <[email protected]> Co-authored-by: ntsekouras <[email protected]> Co-authored-by: oandregal <[email protected]> Co-authored-by: jameskoster <[email protected]>
- Loading branch information
1 parent
bced5e0
commit 859d48b
Showing
11 changed files
with
531 additions
and
335 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
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import clsx from 'clsx'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { DataForm } from '@wordpress/dataviews'; | ||
import { useDispatch, useSelect } from '@wordpress/data'; | ||
import { store as coreDataStore } from '@wordpress/core-data'; | ||
import { Button } from '@wordpress/components'; | ||
import { useState, useMemo } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Page from '../page'; | ||
import usePostFields from '../post-fields'; | ||
|
||
function PostEditForm( { postType, postId } ) { | ||
const { item } = useSelect( | ||
( select ) => { | ||
return { | ||
item: select( coreDataStore ).getEntityRecord( | ||
'postType', | ||
postType, | ||
postId | ||
), | ||
}; | ||
}, | ||
[ postType, postId ] | ||
); | ||
const { saveEntityRecord } = useDispatch( coreDataStore ); | ||
const { fields } = usePostFields(); | ||
const form = { | ||
visibleFields: [ 'title' ], | ||
}; | ||
const [ edits, setEdits ] = useState( {} ); | ||
const itemWithEdits = useMemo( () => { | ||
return { | ||
...item, | ||
...edits, | ||
}; | ||
}, [ item, edits ] ); | ||
const onSubmit = ( event ) => { | ||
event.preventDefault(); | ||
saveEntityRecord( 'postType', postType, itemWithEdits ); | ||
setEdits( {} ); | ||
}; | ||
|
||
if ( ! item ) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<form onSubmit={ onSubmit }> | ||
<DataForm | ||
data={ itemWithEdits } | ||
fields={ fields } | ||
form={ form } | ||
onChange={ setEdits } | ||
/> | ||
<Button variant="primary" type="submit"> | ||
{ __( 'Update' ) } | ||
</Button> | ||
</form> | ||
); | ||
} | ||
|
||
export function PostEdit( { postType, postId } ) { | ||
return ( | ||
<Page | ||
className={ clsx( 'edit-site-post-edit', { | ||
'is-empty': ! postId, | ||
} ) } | ||
label={ __( 'Post Edit' ) } | ||
> | ||
{ postId && ( | ||
<PostEditForm postType={ postType } postId={ postId } /> | ||
) } | ||
{ ! postId && <p>{ __( 'Select a page to edit' ) }</p> } | ||
</Page> | ||
); | ||
} |
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,9 @@ | ||
.edit-site-post-edit { | ||
padding: $grid-unit-30; | ||
|
||
&.is-empty .edit-site-page-content { | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
} | ||
} |
Oops, something went wrong.
859d48b
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.
Flaky tests detected in 859d48b.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.
🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/10044621696
📝 Reported issues:
/test/e2e/specs/site-editor/dataviews-list-layout-keyboard.spec.js