-
Notifications
You must be signed in to change notification settings - Fork 4.7k
DataViews: Add types to the ViewGrid component #61667
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
Conversation
|
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. |
| className="dataviews-view-grid__title-actions" | ||
| > | ||
| <SingleSelectionCheckbox | ||
| id={ id } |
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 found that this prop was useless thanks to the types.
| spacing={ 2 } | ||
| wrap | ||
| align="top" | ||
| alignment="top" |
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 think this was a bug also discovered thanks to the types.
|
Size Change: -2 B (0%) Total Size: 1.75 MB
ℹ️ View Unchanged
|
aac185b to
7ae829d
Compare
sirreal
left a comment
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 makes sense 👍
| /** | ||
| * The fields to use as columns. | ||
| */ | ||
| columnFields: 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.
This is strictly informational - no changes requested.
I like to use the readonly types where they make sense, for example:
| columnFields: string[]; | |
| columnFields: ReadonlyArray< string >; |
It's largely the same, except it clearly indicates the array isn't intended to be modified, so things like columnFields.pop() wouldn't be allowed.
I don't know how much that makes sense here, but much of our code avoids mutation and this is a way to clearly express (and enforce!) that.
Note that it's probably most helpful on function parameters (or constants):
// This function accepts regular and readonly arrays. Regular arrays satisfy readonly.
// it's easy to use and we know it won't modify the array internally
function sum(ns: ReadonlyArray<number>): number { return ns.reduce((a, b) => a + b, 0); }
// This function is trickier, we probably shouldn't care about returning readonly.
// Callers should be able to do what they want!
function split(s: string): ReadonlyArray<string> { return s.split(''); }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 me I'd prefer to avoid this here because it will create inconsistencies. Most of the types are should be "Readonly" types.
Related #55083
Follow-up to #61185
What?
The DataViews package is a types heavy package. There's a lot of structures that need to be documented properly. So this continues the effort to add explicit types to the package. This PR focuses on typing the ViewGrid component.
Testing instructions
There's no functional change, it's essentially a code quality + documentation change.