Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/fields/src/fields/status/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ const statusField: Field< BasePost > = {
id: 'status',
type: 'text',
elements: STATUSES,
// An auto-draft is a draft that hasn't been saved yet, so treat it as
// one for display, selection, and filtering.
getValue: ( { item } ) =>
item.status === 'auto-draft' ? 'draft' : item.status,
render: StatusView,
Edit: 'radio',
enableSorting: false,
Expand Down
8 changes: 5 additions & 3 deletions packages/fields/src/fields/status/status-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import {
__experimentalHStack as HStack,
Icon as WCIcon,
} from '@wordpress/components';
import type { DataViewRenderFieldProps } from '@wordpress/dataviews';

/**
* Internal dependencies
*/
import type { BasePost } from '../../types';
import STATUSES from './status-elements';

function StatusView( { item }: { item: BasePost } ) {
const status = STATUSES.find( ( { value } ) => value === item.status );
const label = status?.label || item.status;
function StatusView( { item, field }: DataViewRenderFieldProps< BasePost > ) {
const currentStatus = field.getValue( { item } );
const status = STATUSES.find( ( { value } ) => value === currentStatus );
const label = status?.label || currentStatus;
const icon = status?.icon;
return (
<HStack alignment="left" spacing={ 0 }>
Expand Down
26 changes: 26 additions & 0 deletions test/e2e/specs/editor/various/post-summary.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,4 +275,30 @@ test.describe( 'Post Summary', () => {
};
}
} );

test.describe( 'post status', () => {
test( 'shows Draft for a new post before it has been saved', async ( {
admin,
editor,
page,
} ) => {
await admin.createNewPost();
await editor.openDocumentSettingsSidebar();

const summary = page.locator( '.editor-post-summary' );
await expect( summary ).toBeVisible();

// A new post is an `auto-draft`, which should be presented as
// a Draft.
const editButton = summary.getByRole( 'button', {
name: 'Edit Status',
} );
await expect( editButton ).toHaveAccessibleDescription( 'Draft' );

await editButton.click();
await expect(
page.getByRole( 'radio', { name: 'Draft' } )
).toBeChecked();
} );
} );
} );
Loading