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

DataViews: add new page button in Pages #57685

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Changes from all commits
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
38 changes: 38 additions & 0 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import {
__experimentalView as View,
__experimentalVStack as VStack,
Button,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useEntityRecords, store as coreStore } from '@wordpress/core-data';
Expand Down Expand Up @@ -42,6 +43,7 @@ import {
useEditPostAction,
} from '../actions';
import PostPreview from '../post-preview';
import AddNewPageModal from '../add-new-page';
import Media from '../media';
import { unlock } from '../../lock-unlock';
const { useLocation, useHistory } = unlock( routerPrivateApis );
Expand Down Expand Up @@ -323,6 +325,29 @@ export default function PagePages() {
[ view.type, setView ]
);

const [ showAddPageModal, setShowAddPageModal ] = useState( false );
const openModal = useCallback( () => {
if ( ! showAddPageModal ) {
setShowAddPageModal( true );
}
}, [ showAddPageModal ] );
const closeModal = useCallback( () => {
if ( showAddPageModal ) {
setShowAddPageModal( false );
}
}, [ showAddPageModal ] );
const handleNewPage = useCallback(
( { type, id } ) => {
history.push( {
postId: id,
postType: type,
canvas: 'edit',
} );
closeModal();
},
[ history ]
);

// TODO: we need to handle properly `data={ data || EMPTY_ARRAY }` for when `isLoading`.
return (
<>
Expand All @@ -333,6 +358,19 @@ export default function PagePages() {
: null
}
title={ __( 'Pages' ) }
actions={
<>
<Button variant="primary" onClick={ openModal }>
{ __( 'Add new page' ) }
</Button>
{ showAddPageModal && (
<AddNewPageModal
onSave={ handleNewPage }
onClose={ closeModal }
/>
) }
</>
}
>
<DataViews
paginationInfo={ paginationInfo }
Expand Down