-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Posts DataViews: Refactor the router to use route registration (#67160)
Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: ntsekouras <ntsekouras@git.wordpress.org>
- Loading branch information
1 parent
ec4b881
commit 0c32e9e
Showing
9 changed files
with
282 additions
and
70 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
packages/edit-site/src/components/posts-app-routes/home.js
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,36 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import Editor from '../editor'; | ||
import SidebarNavigationScreenMain from '../sidebar-navigation-screen-main'; | ||
import { unlock } from '../../lock-unlock'; | ||
|
||
const { useLocation } = unlock( routerPrivateApis ); | ||
|
||
function HomeMobileView() { | ||
const { params = {} } = useLocation(); | ||
const { canvas = 'view' } = params; | ||
|
||
return canvas === 'edit' ? ( | ||
<Editor isPostsList /> | ||
) : ( | ||
<SidebarNavigationScreenMain /> | ||
); | ||
} | ||
|
||
export const homeRoute = { | ||
name: 'home', | ||
match: () => { | ||
return true; | ||
}, | ||
areas: { | ||
sidebar: <SidebarNavigationScreenMain />, | ||
preview: <Editor isPostsList />, | ||
mobile: HomeMobileView, | ||
}, | ||
}; |
36 changes: 36 additions & 0 deletions
36
packages/edit-site/src/components/posts-app-routes/index.js
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,36 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRegistry, useDispatch } from '@wordpress/data'; | ||
import { useEffect } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../lock-unlock'; | ||
import { store as siteEditorStore } from '../../store'; | ||
import { homeRoute } from './home'; | ||
import { postsListViewQuickEditRoute } from './posts-list-view-quick-edit'; | ||
import { postsListViewRoute } from './posts-list-view'; | ||
import { postsViewQuickEditRoute } from './posts-view-quick-edit'; | ||
import { postsViewRoute } from './posts-view'; | ||
import { postsEditRoute } from './posts-edit'; | ||
|
||
const routes = [ | ||
postsListViewQuickEditRoute, | ||
postsListViewRoute, | ||
postsViewQuickEditRoute, | ||
postsViewRoute, | ||
postsEditRoute, | ||
homeRoute, | ||
]; | ||
|
||
export function useRegisterPostsAppRoutes() { | ||
const registry = useRegistry(); | ||
const { registerRoute } = unlock( useDispatch( siteEditorStore ) ); | ||
useEffect( () => { | ||
registry.batch( () => { | ||
routes.forEach( registerRoute ); | ||
} ); | ||
}, [ registry, registerRoute ] ); | ||
} |
31 changes: 31 additions & 0 deletions
31
packages/edit-site/src/components/posts-app-routes/posts-edit.js
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,31 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PostList from '../post-list'; | ||
import DataViewsSidebarContent from '../sidebar-dataviews'; | ||
import SidebarNavigationScreen from '../sidebar-navigation-screen'; | ||
import Editor from '../editor'; | ||
|
||
export const postsEditRoute = { | ||
name: 'posts-edit', | ||
match: ( params ) => { | ||
return params.postType === 'post' && params.canvas === 'edit'; | ||
}, | ||
areas: { | ||
sidebar: ( | ||
<SidebarNavigationScreen | ||
title={ __( 'Posts' ) } | ||
isRoot | ||
content={ <DataViewsSidebarContent /> } | ||
/> | ||
), | ||
content: <PostList postType="post" />, | ||
mobile: <Editor isPostsList />, | ||
preview: <Editor isPostsList />, | ||
}, | ||
}; |
52 changes: 52 additions & 0 deletions
52
packages/edit-site/src/components/posts-app-routes/posts-list-view-quick-edit.js
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,52 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PostList from '../post-list'; | ||
import DataViewsSidebarContent from '../sidebar-dataviews'; | ||
import SidebarNavigationScreen from '../sidebar-navigation-screen'; | ||
import { unlock } from '../../lock-unlock'; | ||
import { PostEdit } from '../post-edit'; | ||
import Editor from '../editor'; | ||
|
||
const { useLocation } = unlock( routerPrivateApis ); | ||
|
||
function PostQuickEdit() { | ||
const { params } = useLocation(); | ||
return <PostEdit postType="post" postId={ params.postId } />; | ||
} | ||
|
||
export const postsListViewQuickEditRoute = { | ||
name: 'posts-list-view-quick-edit', | ||
match: ( params ) => { | ||
return ( | ||
params.isCustom !== 'true' && | ||
( params.layout ?? 'list' ) === 'list' && | ||
!! params.quickEdit && | ||
params.postType === 'post' && | ||
params.canvas !== 'edit' | ||
); | ||
}, | ||
areas: { | ||
sidebar: ( | ||
<SidebarNavigationScreen | ||
title={ __( 'Posts' ) } | ||
isRoot | ||
content={ <DataViewsSidebarContent /> } | ||
/> | ||
), | ||
content: <PostList postType="post" />, | ||
mobile: <PostList postType="post" />, | ||
preview: <Editor />, | ||
edit: <PostQuickEdit />, | ||
}, | ||
widths: { | ||
content: 380, | ||
edit: 380, | ||
}, | ||
}; |
40 changes: 40 additions & 0 deletions
40
packages/edit-site/src/components/posts-app-routes/posts-list-view.js
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,40 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PostList from '../post-list'; | ||
import DataViewsSidebarContent from '../sidebar-dataviews'; | ||
import SidebarNavigationScreen from '../sidebar-navigation-screen'; | ||
import Editor from '../editor'; | ||
|
||
export const postsListViewRoute = { | ||
name: 'posts-list-view', | ||
match: ( params ) => { | ||
return ( | ||
params.isCustom !== 'true' && | ||
( params.layout ?? 'list' ) === 'list' && | ||
! params.quickEdit && | ||
params.postType === 'post' && | ||
params.canvas !== 'edit' | ||
); | ||
}, | ||
areas: { | ||
sidebar: ( | ||
<SidebarNavigationScreen | ||
title={ __( 'Posts' ) } | ||
isRoot | ||
content={ <DataViewsSidebarContent /> } | ||
/> | ||
), | ||
content: <PostList postType="post" />, | ||
preview: <Editor isPostsList />, | ||
mobile: <PostList postType="post" />, | ||
}, | ||
widths: { | ||
content: 380, | ||
}, | ||
}; |
49 changes: 49 additions & 0 deletions
49
packages/edit-site/src/components/posts-app-routes/posts-view-quick-edit.js
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,49 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import { privateApis as routerPrivateApis } from '@wordpress/router'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PostList from '../post-list'; | ||
import DataViewsSidebarContent from '../sidebar-dataviews'; | ||
import SidebarNavigationScreen from '../sidebar-navigation-screen'; | ||
import { unlock } from '../../lock-unlock'; | ||
import { PostEdit } from '../post-edit'; | ||
|
||
const { useLocation } = unlock( routerPrivateApis ); | ||
|
||
function PostQuickEdit() { | ||
const { params } = useLocation(); | ||
return <PostEdit postType="post" postId={ params.postId } />; | ||
} | ||
|
||
export const postsViewQuickEditRoute = { | ||
name: 'posts-view-quick-edit', | ||
match: ( params ) => { | ||
return ( | ||
( params.isCustom === 'true' || | ||
( params.layout ?? 'list' ) !== 'list' ) && | ||
!! params.quickEdit && | ||
params.postType === 'post' && | ||
params.canvas !== 'edit' | ||
); | ||
}, | ||
areas: { | ||
sidebar: ( | ||
<SidebarNavigationScreen | ||
title={ __( 'Posts' ) } | ||
isRoot | ||
content={ <DataViewsSidebarContent /> } | ||
/> | ||
), | ||
content: <PostList postType="post" />, | ||
mobile: <PostList postType="post" />, | ||
edit: <PostQuickEdit />, | ||
}, | ||
widths: { | ||
edit: 380, | ||
}, | ||
}; |
35 changes: 35 additions & 0 deletions
35
packages/edit-site/src/components/posts-app-routes/posts-view.js
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,35 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import PostList from '../post-list'; | ||
import DataViewsSidebarContent from '../sidebar-dataviews'; | ||
import SidebarNavigationScreen from '../sidebar-navigation-screen'; | ||
|
||
export const postsViewRoute = { | ||
name: 'posts-view', | ||
match: ( params ) => { | ||
return ( | ||
( params.isCustom === 'true' || | ||
( params.layout ?? 'list' ) !== 'list' ) && | ||
! params.quickEdit && | ||
params.postType === 'post' && | ||
params.canvas !== 'edit' | ||
); | ||
}, | ||
areas: { | ||
sidebar: ( | ||
<SidebarNavigationScreen | ||
title={ __( 'Posts' ) } | ||
isRoot | ||
content={ <DataViewsSidebarContent /> } | ||
/> | ||
), | ||
content: <PostList postType="post" />, | ||
mobile: <PostList postType="post" />, | ||
}, | ||
}; |
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 was deleted.
Oops, something went wrong.