-
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 2 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,12 @@ export default function PagePages() { | |
field: 'date', | ||
direction: 'desc', | ||
}, | ||
fields: { | ||
// All fields are visible by default, so it's | ||
// better to keep track of the hidden ones. | ||
hidden: new Set( [ 'date' ] ), | ||
ntsekouras marked this conversation as resolved.
Show resolved
Hide resolved
|
||
hidable: [ 'author', 'status', 'date' ], | ||
}, | ||
} ); | ||
// Request post statuses to get the proper labels. | ||
const { records: statuses } = useEntityRecords( 'root', 'status' ); | ||
|
@@ -95,7 +102,6 @@ export default function PagePages() { | |
}, | ||
maxWidth: 400, | ||
sortingFn: 'alphanumeric', | ||
enableHiding: false, | ||
}, | ||
{ | ||
header: __( 'Author' ), | ||
|
@@ -117,6 +123,18 @@ export default function PagePages() { | |
postStatuses[ page.status ] ?? page.status, | ||
enableSorting: false, | ||
}, | ||
{ | ||
header: 'Date', | ||
id: 'date', | ||
cell: ( props ) => { | ||
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. Following up this rationale, what do you think of doing this instead (pseudo-code): accessorFn: ( page ) => {
return dateI18n(
getSettings().formats.datetimeAbbreviated,
getDate( props.row.original.date )
);
}
cell: ( props ) => { return <time>{props.row.getValue()}</time> } 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. I think we need to redo 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. I'd echo Riad on this. We need to start forming the API that will map internally to tanstack. |
||
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.
I'm not sure this assumption is true for all the views. I'd think that it's probably the opposite: most fields should be hidden by default but I'm ok starting this way.