-
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
[DataViews]: Update the view config to include fields visibility #55247
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import { __ } from '@wordpress/i18n'; | |
import { useEntityRecords } from '@wordpress/core-data'; | ||
import { decodeEntities } from '@wordpress/html-entities'; | ||
import { useState, useMemo } from '@wordpress/element'; | ||
import { dateI18n, getDate, getSettings } from '@wordpress/date'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -31,6 +32,9 @@ export default function PagePages() { | |
field: 'date', | ||
direction: 'desc', | ||
}, | ||
// All fields are visible by default, so it's | ||
// better to keep track of the hidden ones. | ||
hiddenFields: [ 'date' ], | ||
} ); | ||
// Request post statuses to get the proper labels. | ||
const { records: statuses } = useEntityRecords( 'root', 'status' ); | ||
|
@@ -117,6 +121,18 @@ export default function PagePages() { | |
postStatuses[ page.status ] ?? page.status, | ||
enableSorting: false, | ||
}, | ||
{ | ||
header: 'Date', | ||
id: 'date', | ||
cell: ( props ) => { | ||
const formattedDate = dateI18n( | ||
getSettings().formats.datetimeAbbreviated, | ||
getDate( props.row.original.date ) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default edit.php page seems to fallback to the modified data for drafts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
); | ||
return <time>{ formattedDate }</time>; | ||
}, | ||
enableSorting: false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This field is used to sort the table by default. Why a user shouldn't be able to? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe a user can do it in the future, but it might be more convoluted when we have composite fields or something that would need to provide the sorting args. I think more of the APIs will evolve/created per iteration and use case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow-up in #55388 |
||
}, | ||
], | ||
[ postStatuses ] | ||
); | ||
|
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.
Following up this rationale, what do you think of doing this instead (pseudo-code):
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 we need to redo
accessorFn
andcell
to be less tied to the API of tanstack at some point, and yeah we need to agree on a given way of retrieving the fields data.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'd echo Riad on this. We need to start forming the API that will map internally to tanstack.