Skip to content

Commit

Permalink
DataViews: fix issue with irrelevant statuses (#55967)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal authored Nov 8, 2023
1 parent e50aabe commit dded3a7
Showing 1 changed file with 19 additions and 28 deletions.
47 changes: 19 additions & 28 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ const defaultConfigPerViewType = {
},
};

// DEFAULT_STATUSES is intentionally sorted. Items do not have spaces in between them.
// The reason for that is to match the default statuses coming from the endpoint (entity request).
export const DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All statuses but 'trash'.

function useView( type ) {
const {
params: { activeView = 'all', isCustom = 'false' },
Expand Down Expand Up @@ -104,21 +100,22 @@ function useView( type ) {
return [ DEFAULT_VIEWS[ type ][ 0 ].view, setView ];
}

// See https://github.com/WordPress/gutenberg/issues/55886
// We do not support custom statutes at the moment.
const STATUSES = [
{ value: 'draft', label: __( 'Draft' ) },
{ value: 'future', label: __( 'Scheduled' ) },
{ value: 'pending', label: __( 'Pending Review' ) },
{ value: 'private', label: __( 'Private' ) },
{ value: 'publish', label: __( 'Published' ) },
{ value: 'trash', label: __( 'Trash' ) },
];
const DEFAULT_STATUSES = 'draft,future,pending,private,publish'; // All but 'trash'.

export default function PagePages() {
const postType = 'page';
const [ view, setView ] = useView( postType );
const [ selection, setSelection ] = useState( [] );
const { records: statuses, isResolving: isLoadingStatus } =
useEntityRecords( 'root', 'status' );
const defaultStatuses = useMemo( () => {
return statuses === null
? DEFAULT_STATUSES
: statuses
.filter( ( { slug } ) => slug !== 'trash' )
.map( ( { slug } ) => slug )
.sort()
.join();
}, [ statuses ] );

const queryArgs = useMemo( () => {
const filters = {};
Expand All @@ -133,7 +130,7 @@ export default function PagePages() {
// We want to provide a different default item for the status filter
// than the REST API provides.
if ( ! filters.status || filters.status === '' ) {
filters.status = defaultStatuses;
filters.status = DEFAULT_STATUSES;
}

return {
Expand All @@ -145,7 +142,7 @@ export default function PagePages() {
search: view.search,
...filters,
};
}, [ view, defaultStatuses ] );
}, [ view ] );
const {
records: pages,
isResolving: isLoadingPages,
Expand Down Expand Up @@ -242,14 +239,10 @@ export default function PagePages() {
header: __( 'Status' ),
id: 'status',
getValue: ( { item } ) =>
statuses?.find( ( { slug } ) => slug === item.status )
?.name ?? item.status,
STATUSES.find( ( { value } ) => value === item.status )
?.label ?? item.status,
filters: [ 'in' ],
elements:
statuses?.map( ( { slug, name } ) => ( {
value: slug,
label: name,
} ) ) || [],
elements: STATUSES,
enableSorting: false,
},
{
Expand All @@ -265,7 +258,7 @@ export default function PagePages() {
},
},
],
[ statuses, authors ]
[ authors ]
);

const trashPostAction = useTrashPostAction();
Expand Down Expand Up @@ -317,9 +310,7 @@ export default function PagePages() {
fields={ fields }
actions={ actions }
data={ pages || EMPTY_ARRAY }
isLoading={
isLoadingPages || isLoadingStatus || isLoadingAuthors
}
isLoading={ isLoadingPages || isLoadingAuthors }
view={ view }
onChangeView={ onChangeView }
/>
Expand Down

1 comment on commit dded3a7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in dded3a7.
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/6800497405
📝 Reported issues:

Please sign in to comment.