diff --git a/packages/core-data/src/entities.js b/packages/core-data/src/entities.js index fde8cdba93717d..3fb3af96eb9ad0 100644 --- a/packages/core-data/src/entities.js +++ b/packages/core-data/src/entities.js @@ -223,6 +223,15 @@ export const rootEntitiesConfig = [ baseURLParams: { context: 'edit' }, key: 'plugin', }, + { + label: __( 'Post status' ), + name: 'status', + kind: 'root', + baseURL: '/wp/v2/statuses', + baseURLParams: { context: 'edit' }, + plural: 'postStatuses', + key: 'slug', + }, ]; export const additionalEntityConfigLoaders = [ diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index e7b8f913efe7ca..b767ad77adc6d9 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -22,6 +22,7 @@ import PageActions from '../page-actions'; import { DataViews, PAGE_SIZE_VALUES } from '../dataviews'; const EMPTY_ARRAY = []; +const EMPTY_OBJECT = {}; export default function PagePages() { const [ reset, setResetQuery ] = useState( ( v ) => ! v ); @@ -32,12 +33,14 @@ export default function PagePages() { pageSize: PAGE_SIZE_VALUES[ 0 ], } ); // Request post statuses to get the proper labels. - const [ postStatuses, setPostStatuses ] = useState( EMPTY_ARRAY ); - useEffect( () => { - apiFetch( { - path: '/wp/v2/statuses', - } ).then( setPostStatuses ); - }, [] ); + const { records: statuses } = useEntityRecords( 'root', 'status' ); + const postStatuses = + statuses === null + ? EMPTY_OBJECT + : statuses.reduce( ( acc, status ) => { + acc[ status.slug ] = status.name; + return acc; + }, EMPTY_OBJECT ); // TODO: probably memo other objects passed as state(ex:https://tanstack.com/table/v8/docs/examples/react/pagination-controlled). const pagination = useMemo( @@ -66,7 +69,7 @@ export default function PagePages() { reset, ] ); - const { records, isResolving: isLoading } = useEntityRecords( + const { records: pages, isResolving: isLoadingPages } = useEntityRecords( 'postType', 'page', queryArgs @@ -136,7 +139,8 @@ export default function PagePages() { header: 'Status', id: 'status', cell: ( props ) => - postStatuses[ props.row.original.status ]?.name, + postStatuses[ props.row.original.status ] ?? + props.row.original.status, }, { header: { __( 'Actions' ) }, @@ -161,8 +165,8 @@ export default function PagePages() {