-
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
[core-data] Document and add types for dynamic actions and selectors. #67668
[core-data] Document and add types for dynamic actions and selectors. #67668
Conversation
…namic-actions-selectors-for-core-data
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. |
Size Change: 0 B Total Size: 1.84 MB ℹ️ View Unchanged
|
Flaky tests detected in 1af6f51. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/12607437688
|
Comment: ET.Comment< C >; | ||
Media: ET.Attachment< C >; | ||
Menu: ET.NavMenu< C >; | ||
MenuItem: ET.NavMenuItem< C >; | ||
MenuLocation: ET.MenuLocation< C >; | ||
Plugin: ET.Plugin< C >; | ||
PostType: ET.Type< C >; | ||
Revision: ET.PostRevision< C >; | ||
Sidebar: ET.Sidebar< C >; | ||
Site: ET.Settings< C >; | ||
Status: ET.PostStatusObject< C >; | ||
Taxonomy: ET.Taxonomy< C >; | ||
Theme: ET.Theme< C >; | ||
UnstableBase: ET.UnstableBase< C >; | ||
User: ET.User< C >; | ||
Widget: ET.Widget< C >; | ||
WidgetType: ET.WidgetType< C >; |
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.
Are these all the entity types? Looks like Global Styles are missing for some reason?
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.
Yeah, for some reason, Global Styles seems to be broken. It always returns 404.
await wp.data.resolveSelect('core').getGlobalStylesVariations()
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.
Added in 1f5bd67
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.
Not sure how the plural one is supposed to work 🤔 Return all entries from the wp_global_styles
post type? I'm not sure this will ever be needed. Maybe the plural just needs to be disabled?
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.
But that plural IS actually available on runtime.
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 have disabled that plural for now.
* - "status" to "statuses" | ||
*/ | ||
type PluralizeEntity< T extends string > = T extends 'GlobalStyles' | ||
? 'GlobalStylesVariations' |
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.
Let's document this one above as well.
* - "statuses" to "status" | ||
*/ | ||
type SingularizeEntity< T extends string > = T extends 'GlobalStylesVariations' | ||
? 'GlobalStyles' |
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.
Let's document this one above as well.
select( coreStore ).getEntityRecord< { | ||
default_template_part_areas: Array< TemplatePartArea >; | ||
default_template_part_areas: UnstableBase[ 'default_template_part_areas' ]; |
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.
Does it make sense to export TemplatePartArea
and use it directly?
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.
Done. Thanks
@@ -11,6 +11,8 @@ import type { NavMenuItem } from './nav-menu-item'; | |||
import type { Page } from './page'; | |||
import type { Plugin } from './plugin'; | |||
import type { Post } from './post'; | |||
import type { PostStatusObject } from './post-status'; | |||
import type { Base } from './base'; |
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.
Nit: might make sense to keep the alphabetic order here.
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.
Done. Thanks
| PostStatusObject< C > | ||
| PostRevision< C > |
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.
Same as above, with regards to keeping the alphabetic order
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.
Done. Thanks
/** | ||
* The title for the status. | ||
*/ | ||
name: string; |
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.
Aren't most (if not all) of these actually optional?
See:
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 the same for user object but those fields are actually present because those are actually present in the item schema.
export let dynamicActions: SaveActions & DeleteActions; | ||
|
||
export let dynamicSelectors: SingularGetters & PluralGetters; |
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.
Is a let
necessary for some reason? Can't we just use const
?
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.
For const
, you need to assign the value. Since the value is actually undefined and only the type is set, it's fine.
/** | ||
* GMT offset for the site. | ||
*/ | ||
gmt_offset: string | number; |
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.
Won't it always be a string
because it comes from a value of the the wp_options
table?
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.
Yeah, that is correct. I don't remember why I set it as a number in the first place.
/** | ||
* Site icon ID. | ||
*/ | ||
site_icon?: number; |
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.
Confirming that regardless of its wp_options
origin, this one is actually a number because it gets additional treatment.
/** | ||
* Site logo ID. | ||
*/ | ||
site_logo?: number; |
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.
Confirming that regardless of its wp_options
origin, this one is actually a number because it gets additional treatment.
Thank you for your review @tyxla. I have addressed your feedback. Please let me know if there is anything else to improve. |
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.
Nothing further from my end.
Looking great from my perspective, thank you for the great work @manzoorwanijk 🚀
@jsnajdr any final thoughts before we 🚢 ?
I am going to merge this PR in a few hours if there is no further feedback, to keep things moving. If there is anything after that, we can address it in follow up PRs. |
Fixes #56287 #67847
Related #67142
What?
Define the type declarations for dynamic selectors and actions for
core-data
package.Why?
The dynamic selectors cause errors when used in TypeScript because TS can't find those defined anywhere.
How?
The PR creates TS definition declarations for all the dynamic selectors and some useful actions
Testing Instructions
Example
Testing Instructions for Keyboard
Screenshots or screencast
We will now have auto-completions for entity selectors