-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QuickEdit: Add Parent field #66527
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for documenting it (README) :)
getValue: ( { item } ) => item.parent, | ||
Edit: ParentEdit, | ||
render: ParentView, | ||
enableSorting: false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why disabling sorting? The endpoint we take the data from supports sorting by parent
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with c7f30b9
return <>{ getTitleWithFallbackName( parent ) }</>; | ||
} | ||
|
||
return <>{ __( 'None' ) }</>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, nice, it makes more sense then.
*/ | ||
import type { BasePost } from '../../types'; | ||
|
||
export function getTitleWithFallbackName( post: BasePost ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a getItemTitle
utilility in actions. Can we reuse that one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed with 4526f96
} ) { | ||
const [ fieldValue, setFieldValue ] = useState< null | string >( null ); | ||
|
||
const pageId = data.parent; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
though I wouldn't mind consolidating into a single one either
I agree with you! Improved with af5dec2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left some comments, but they're a bit minor so I wanted to pre-approve for you to merge when ready.
This works well and it is a well-scoped PR, thanks!
* 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 <[email protected]> Co-authored-by: oandregal <[email protected]>
What?
This PR adds the
Parent
field.Related issue #64519.
Testing Instructions
Ensure that
Quick Edit in DataViews
andQuick Edit in DataViews
are enabled.None
Testing Instructions for Keyboard
Screenshots or screencast
Screen.Capture.on.2024-10-28.at.17-24-05.mp4