Skip to content

Commit

Permalink
Take status labels from entity
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Oct 5, 2023
1 parent 96a0feb commit 86c8b42
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import {
__experimentalVStack as VStack,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { useEntityRecords, store as coreStore } from '@wordpress/core-data';
import { useEntityRecords } from '@wordpress/core-data';
import { decodeEntities } from '@wordpress/html-entities';
import { useState, useEffect, useMemo } from '@wordpress/element';

Expand All @@ -23,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 );
Expand All @@ -33,11 +33,14 @@ export default function PagePages() {
pageSize: PAGE_SIZE_VALUES[ 0 ],
} );
// Request post statuses to get the proper labels.
// TODO: we should probably use `useEntityRecords` here.
const postStatuses = useSelect( ( select ) => {
const { getPostStatuses } = select( coreStore );
return getPostStatuses();
}, [] );
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(
Expand Down Expand Up @@ -135,8 +138,7 @@ export default function PagePages() {
{
header: 'Status',
id: 'status',
cell: ( props ) =>
postStatuses[ props.row.original.status ]?.name,
cell: ( props ) => postStatuses[ props.row.original.status ],
},
{
header: <VisuallyHidden>{ __( 'Actions' ) }</VisuallyHidden>,
Expand Down

0 comments on commit 86c8b42

Please sign in to comment.