Repository navigation
QuickEdit: Add Parent field - #66527
Conversation
|
Size Change: +1.09 kB (+0.06%) Total Size: 1.81 MB
ℹ️ View Unchanged
|
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Thanks for adding the labels! The current setup requires at least one label to be of the Also, for the PR title: we use this to auto-generate the changelog that is published as part of the release. I understand the package name ( |
Thanks!
Sounds great! Thanks for fixing both 🙇 |
| enableSorting: false, | ||
| }; | ||
|
|
||
| /** |
There was a problem hiding this comment.
Thanks for documenting it (README) :)
| getValue: ( { item } ) => item.parent, | ||
| Edit: ParentEdit, | ||
| render: ParentView, | ||
| enableSorting: false, |
There was a problem hiding this comment.
Why disabling sorting? The endpoint we take the data from supports sorting by parent.
| return <>{ getTitleWithFallbackName( parent ) }</>; | ||
| } | ||
|
|
||
| return <>{ __( 'None' ) }</>; |
There was a problem hiding this comment.
This works for me: we could land as it is and then gather feedback from folks. Though I wonder if there's a better default for this because None could be an actual title, so it may be confusing. Perhaps — like wp-admin uses in some places?
There was a problem hiding this comment.
Oh, nice, it makes more sense then.
| */ | ||
| import type { BasePost } from '../../types'; | ||
|
|
||
| export function getTitleWithFallbackName( post: BasePost ) { |
There was a problem hiding this comment.
There's a getItemTitle utilility in actions. Can we reuse that one?
There was a problem hiding this comment.
Interestingly, it appears that every usage of decodeEntities in the fields package can be replaced by just calling that utility?
In some situations, we are running it twice:
decodeEntities( decodeEntities( '...' ) );There was a problem hiding this comment.
What do you think about?
export function getTitleWithFallbackName( post: BasePost ) {
const title = getTitle(post)
return title.length > 0 ? title : `#${ post?.id } (${ __( 'no title' ) })`;
There was a problem hiding this comment.
I guess my point was that we didn't need getTitleWithFallbackName and we could reuse getItemTitle, unless I'm missing something?
There was a problem hiding this comment.
There was a problem hiding this comment.
I guess what I don't understand is why we have different ways to get the title from a Post across the app. Anyway, don't feel this PR should be blocked by this comment. This can be looked at separately.
| const flatTermsWithParentAndChildren = flatTerms.map( ( term ) => { | ||
| return { | ||
| children: [], | ||
| ...term, |
There was a problem hiding this comment.
Interesting how using TypeScript here forced us to declare the Term API (parent obligatory), making the prop redundant here compared to the original that used:
{
children: [],
parent: null,
...term,
}| label={ __( 'Parent' ) } | ||
| help={ __( 'Choose a parent page.' ) } | ||
| value={ parentPostId?.toString() } | ||
| options={ parentOptions.map( ( option ) => ( { |
There was a problem hiding this comment.
It doesn't seem parentOptions is used anywhere else, so can we make this part of the useMemo above? Otherwise, this is creating a new set of options in every render.
| } ) { | ||
| const [ fieldValue, setFieldValue ] = useState< null | string >( null ); | ||
|
|
||
| const pageId = data.parent; |
There was a problem hiding this comment.
It's a bit weird to bind data.parent to two different variables here, but I understand why you did it: to make the useSelect below as similar as possible to the original. I think it works nicely for this use case, though I wouldn't mind consolidating into a single one either — whatever you feel is right. Though, if you want to keep it like this, it'd be good to add a comment to explain the why so other readers don't have to discover it themselves.
There was a problem hiding this comment.
though I wouldn't mind consolidating into a single one either
I agree with you! Improved with af5dec2
* Data Views: Add Parent field * add comment * improve documentation * fix preview * use number type * enable sorting * move logic in the useMemo function * consolidate data.parent in one variable Co-authored-by: gigitux <gigitux@git.wordpress.org> Co-authored-by: oandregal <oandregal@git.wordpress.org>


What?
This PR adds the
Parentfield.Related issue #64519.
Testing Instructions
Ensure that
Quick Edit in DataViewsandQuick Edit in DataViewsare enabled.NoneTesting Instructions for Keyboard
Screenshots or screencast
Screen.Capture.on.2024-10-28.at.17-24-05.mp4