-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[Data views]: Refactor to allow the rendering to be generated using a fields description #55444
Conversation
date: { | ||
view: ( { item, getValue } ) => <time>{ getValue( { item } ) }</time>, | ||
}, | ||
image: { |
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 WP images now, where we pass the attachment id. Later we could change name here and also add a field type that gets the src
or more props and renders just an img
tag.
Size Change: +72 B (0%) Total Size: 1.66 MB
ℹ️ View Unchanged
|
… fields description
1aaa890
to
8c8debe
Compare
9e58774
to
2f354f3
Compare
} | ||
/> | ||
) : null, | ||
...coreFieldTypes.image, |
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.
Could you clarify why we do this if featured-image
defines its own render
? (same for the other fields that end up overriding the default 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.
For now it doesn't do more, but the goal is to have more default things like edit
. Maybe it's makes more sense to try to see how the edit
would be here and evaluate again. I'll convert to draft.
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.
👍
); | ||
return <time>{ formattedDate }</time>; | ||
}, | ||
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.
enableSorting: false, |
return <time>{ formattedDate }</time>; | ||
}, | ||
...coreFieldTypes.date, | ||
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.
I'm thinking we could update the getValue
to:
getValue( { item } ) => dateI18n(
getSettings().formats.datetimeAbbreviated,
getDate( item.date )
)
and then use the default render provided by the core date
type.
Or the other way around: make the dateI18n
part of the core's type. Does that make sense?
I guess my point is that unless we benefit from introducing the core's types, it's hard to justify?
@@ -167,6 +191,7 @@ export default function PagePages() { | |||
id: 'status', | |||
getValue: ( { item } ) => | |||
postStatuses[ item.status ] ?? item.status, | |||
...coreFieldTypes.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.
So far, this is the only change of this PR, correct? status
will now have a render
(aka cell
) while it didn't before. Presumably because tanstack handled it for us, and now we handle it directly via the core's types.
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.
Actually, given what we do at packages/edit-site/src/components/dataviews/dataviews.js
:
render: field.render?.( field.getValue ) || field.getValue,
We don't need this, do we?
What?
Part of: #55083
This PR introduces some core field types and use them for rendering of fields based on this config. If a fields needs to do more than the default behavior, it can override the prop.
This approach makes the field's
getValue
prop, a required one. We need to check later on the nuances of mapping this toaccessorFn
forlist
view, but that's a separate issue to tackle.The format I'm suggesting is a closure function that first gets the
getValue
function of a field, and this is needed because we normalize therender
function in the mainDataViews
component. At that point we have no access to a single data record.In the long run we will add more things to the field types, like an
edit
that could be something like:Testing Instructions