Skip to content

Commit 297e871

Browse files
jameskosterclaude
andcommitted
Quick edit: Show frequently edited fields inline
Opening the quick edit drawer is already the choice to edit, so Status, Password, Link, Author, Template and Excerpt now render their controls inline. Fields that are edited less often keep their panels, pinned to the bottom of the drawer above the buttons. - Status and Author use the UI SelectControl, with an icon per status and an avatar per author. - Password is a field of its own. - The Link field drops its description, Learn more link and permalink preview. - The parent explanation moves below the control as help text. Applies to the site editor and the extensible site editor. See #84391 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 21d4f36 commit 297e871

25 files changed

Lines changed: 677 additions & 285 deletions

‎package-lock.json‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/**
2+
* A user who can be assigned as the author of a post, with the fields the
3+
* author control and filter read.
4+
*/
5+
export interface Author {
6+
id: number;
7+
name: string;
8+
avatar_urls?: Record< string, string >;
9+
}
10+
11+
/**
12+
* The query for the users who can be assigned as authors. The filter elements
13+
* and the edit control share it, so they share one request.
14+
*/
15+
export const AUTHORS_QUERY = {
16+
per_page: -1,
17+
who: 'authors',
18+
_fields: 'id,name,avatar_urls',
19+
context: 'view',
20+
} as const;
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import clsx from 'clsx';
2+
import { useSelect } from '@wordpress/data';
3+
import { store as coreDataStore } from '@wordpress/core-data';
4+
import type { DataFormControlProps } from '@wordpress/dataviews';
5+
import { useMemo } from '@wordpress/element';
6+
import { commentAuthorAvatar as authorIcon } from '@wordpress/icons';
7+
import { Icon, SelectControl, Stack } from '@wordpress/ui';
8+
import { AUTHORS_QUERY, type Author } from './authors-query';
9+
import type { PostWithAuthor } from './types';
10+
import styles from '../../shared/author/style.module.css';
11+
12+
type AuthorItem = {
13+
value: string;
14+
label: string;
15+
avatar?: string;
16+
};
17+
18+
function AuthorLabel( { item }: { item: AuthorItem } ) {
19+
return (
20+
<Stack direction="row" align="center">
21+
{ item.avatar ? (
22+
<div className={ clsx( styles.avatar, styles[ 'is-loaded' ] ) }>
23+
<img alt="" src={ item.avatar } />
24+
</div>
25+
) : (
26+
<div className={ styles.icon }>
27+
<Icon icon={ authorIcon } />
28+
</div>
29+
) }
30+
<span className={ styles.name }>{ item.label }</span>
31+
</Stack>
32+
);
33+
}
34+
35+
/*
36+
* The author control, built with `SelectControl` from `@wordpress/ui` to show
37+
* each author's avatar next to their name.
38+
*/
39+
export default function AuthorEdit( {
40+
data,
41+
field,
42+
onChange,
43+
hideLabelFromVision,
44+
}: DataFormControlProps< PostWithAuthor > ) {
45+
const authors = useSelect(
46+
( select ) =>
47+
select( coreDataStore ).getEntityRecords< Author >(
48+
'root',
49+
'user',
50+
AUTHORS_QUERY
51+
),
52+
[]
53+
);
54+
const value = field.getValue( { item: data } );
55+
const items = useMemo( () => {
56+
const authorItems: AuthorItem[] = ( authors ?? [] ).map(
57+
( author ) => ( {
58+
value: String( author.id ),
59+
label: author.name,
60+
avatar: author.avatar_urls?.[ 48 ],
61+
} )
62+
);
63+
// The current author may not be listed yet, or at all, so fall back
64+
// on the author embedded in the record.
65+
const embeddedAuthor = data?._embedded?.author?.[ 0 ];
66+
if (
67+
embeddedAuthor &&
68+
embeddedAuthor.id === value &&
69+
! authorItems.some( ( item ) => item.value === String( value ) )
70+
) {
71+
authorItems.unshift( {
72+
value: String( embeddedAuthor.id ),
73+
label: embeddedAuthor.name,
74+
avatar: embeddedAuthor.avatar_urls?.[ 48 ],
75+
} );
76+
}
77+
return authorItems;
78+
}, [ authors, data, value ] );
79+
const selectedItem =
80+
items.find( ( item ) => item.value === String( value ) ) ?? null;
81+
82+
return (
83+
<SelectControl
84+
label={ field.label }
85+
hideLabelFromVision={ hideLabelFromVision }
86+
items={ items }
87+
value={ selectedItem }
88+
onValueChange={ ( item ) => {
89+
if ( item?.value ) {
90+
onChange(
91+
field.setValue( { item: data, value: item.value } )
92+
);
93+
}
94+
} }
95+
disabled={ field.isDisabled( { item: data, field } ) }
96+
// Without a value (a bulk edit), the default trigger shows the
97+
// placeholder.
98+
trigger={
99+
selectedItem ? (
100+
<SelectControl.Trigger>
101+
<AuthorLabel item={ selectedItem } />
102+
</SelectControl.Trigger>
103+
) : undefined
104+
}
105+
>
106+
{ items.map( ( item ) => (
107+
<SelectControl.Item
108+
key={ item.value }
109+
value={ item }
110+
label={ item.label }
111+
>
112+
<SelectControl.ItemLabel>
113+
<AuthorLabel item={ item } />
114+
</SelectControl.ItemLabel>
115+
</SelectControl.Item>
116+
) ) }
117+
</SelectControl>
118+
);
119+
}

‎packages/core-fields/src/post_type_supports/author/field.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22
/**
33
* The serializable part of the author field of the post types supporting
4-
* authors. Its JavaScript parts (`getElements`, `setValue`, `render`, and
5-
* `isVisible`) are in `field.tsx`, next to this file.
4+
* authors. Its JavaScript parts (`getElements`, `setValue`, `Edit`, `render`,
5+
* and `isVisible`) are in `field.tsx`, next to this file.
66
*
77
* @package WordPress
88
*/

‎packages/core-fields/src/post_type_supports/author/field.tsx‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { resolveSelect } from '@wordpress/data';
22
import { store as coreDataStore } from '@wordpress/core-data';
33
import type { FieldsScriptParts } from '../../types';
4+
import AuthorEdit from './edit';
45
import AuthorView from './view';
6+
import { AUTHORS_QUERY, type Author } from './authors-query';
57
import type { PostWithAuthor } from './types';
68

7-
interface Author {
8-
id: number;
9-
name: string;
10-
}
11-
129
/**
1310
* The JavaScript parts of the author field; its data is in `field.php`.
1411
*/
@@ -18,19 +15,15 @@ export const fieldExtensions: FieldsScriptParts< PostWithAuthor >[ string ] = {
1815
( await resolveSelect( coreDataStore ).getEntityRecords< Author >(
1916
'root',
2017
'user',
21-
{
22-
per_page: -1,
23-
who: 'authors',
24-
_fields: 'id,name',
25-
context: 'view',
26-
}
18+
AUTHORS_QUERY
2719
) ) ?? [];
2820
return authors.map( ( { id, name } ) => ( {
2921
value: id,
3022
label: name,
3123
} ) );
3224
},
3325
setValue: ( { value } ) => ( { author: Number( value ) } ),
26+
Edit: AuthorEdit,
3427
render: AuthorView,
3528
// A record without `_links` (a bulk edit form has no record) is
3629
// treated as allowed, so only an explicit absence of the action hides

‎packages/core-fields/src/post_type_supports/parent/edit.tsx‎

Lines changed: 46 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import removeAccents from 'remove-accents';
2+
import type { ReactNode } from 'react';
23
import { ComboboxControl } from '@wordpress/components';
34
import { useSelect } from '@wordpress/data';
45
import {
@@ -15,7 +16,6 @@ import { Link } from '@wordpress/ui';
1516
import { filterURLForDisplay } from '@wordpress/url';
1617
import type { PostWithParent } from './types';
1718
import { getTitleWithFallbackName } from './utils';
18-
import styles from './style.module.css';
1919

2020
type TreeBase = {
2121
id: number;
@@ -99,9 +99,11 @@ export const getItemPriority = ( name: string, searchValue: string ) => {
9999
export function PageAttributesParent( {
100100
data,
101101
onChangeControl,
102+
help = __( 'Choose a parent page.' ),
102103
}: {
103104
data: PostWithParent;
104105
onChangeControl: ( newValue: number ) => void;
106+
help?: ReactNode;
105107
} ) {
106108
const [ fieldValue, setFieldValue ] = useState< string >( '' );
107109

@@ -251,7 +253,7 @@ export function PageAttributesParent( {
251253
return (
252254
<ComboboxControl
253255
label={ __( 'Parent' ) }
254-
help={ __( 'Choose a parent page.' ) }
256+
help={ help }
255257
value={ pageId?.toString() }
256258
options={ parentOptions }
257259
onFilterValueChange={ debounce(
@@ -265,8 +267,8 @@ export function PageAttributesParent( {
265267
}
266268

267269
/*
268-
* The parent control, linking to the documentation with `Link` from `@wordpress/ui` and styled with a CSS
269-
* module.
270+
* The parent control, explaining child pages and linking to the documentation
271+
* with `Link` from `@wordpress/ui` in its help text.
270272
*/
271273
export const ParentEdit = ( {
272274
data,
@@ -293,46 +295,46 @@ export const ParentEdit = ( {
293295
[ id, onChange ]
294296
);
295297

296-
return (
297-
<fieldset className={ styles.parent }>
298-
<div>
299-
{ createInterpolateElement(
300-
sprintf(
301-
/* translators: %1$s The home URL of the WordPress installation without the scheme. */
302-
__(
303-
'Child pages inherit characteristics from their parent, such as URL structure. For instance, if "Pricing" is a child of "Services", its URL would be %1$s<wbr />/services<wbr />/pricing.'
304-
),
305-
filterURLForDisplay( homeUrl ).replace(
306-
/([/.])/g,
307-
'<wbr />$1'
308-
)
298+
const help = (
299+
<>
300+
{ createInterpolateElement(
301+
sprintf(
302+
/* translators: %1$s The home URL of the WordPress installation without the scheme. */
303+
__(
304+
'Child pages inherit characteristics from their parent, such as URL structure. For instance, if "Pricing" is a child of "Services", its URL would be %1$s<wbr />/services<wbr />/pricing.'
305+
),
306+
filterURLForDisplay( homeUrl ).replace(
307+
/([/.])/g,
308+
'<wbr />$1'
309+
)
310+
),
311+
{
312+
wbr: <wbr />,
313+
}
314+
) }{ ' ' }
315+
{ createInterpolateElement(
316+
__(
317+
'They also show up as sub-items in the default navigation menu. <a>Learn more.</a>'
318+
),
319+
{
320+
a: (
321+
<Link
322+
href={ __(
323+
'https://wordpress.org/documentation/article/page-post-settings-sidebar/#page-attributes'
324+
) }
325+
openInNewTab
326+
/>
309327
),
310-
{
311-
wbr: <wbr />,
312-
}
313-
) }
314-
<p>
315-
{ createInterpolateElement(
316-
__(
317-
'They also show up as sub-items in the default navigation menu. <a>Learn more.</a>'
318-
),
319-
{
320-
a: (
321-
<Link
322-
href={ __(
323-
'https://wordpress.org/documentation/article/page-post-settings-sidebar/#page-attributes'
324-
) }
325-
openInNewTab
326-
/>
327-
),
328-
}
329-
) }
330-
</p>
331-
<PageAttributesParent
332-
data={ data }
333-
onChangeControl={ onChangeControl }
334-
/>
335-
</div>
336-
</fieldset>
328+
}
329+
) }
330+
</>
331+
);
332+
333+
return (
334+
<PageAttributesParent
335+
data={ data }
336+
onChangeControl={ onChangeControl }
337+
help={ help }
338+
/>
337339
);
338340
};

‎packages/core-fields/src/post_type_supports/parent/style.module.css‎

Lines changed: 0 additions & 6 deletions
This file was deleted.

0 commit comments

Comments
 (0)