-
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: Removing mapping of user patterns to temporary object #63042
Changes from 1 commit
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 |
---|---|---|
|
@@ -117,6 +117,7 @@ function PreviewWrapper( { item, onClick, ariaDescribedBy, children } ) { | |
|
||
function Preview( { item, viewType } ) { | ||
const descriptionId = useId(); | ||
const description = item.description || item?.excerpt?.raw; | ||
const isUserPattern = item.type === PATTERN_TYPES.user; | ||
const isTemplatePart = item.type === TEMPLATE_PART_POST_TYPE; | ||
const [ backgroundColor ] = useGlobalStyle( 'color.background' ); | ||
|
@@ -143,7 +144,7 @@ function Preview( { item, viewType } ) { | |
<PreviewWrapper | ||
item={ item } | ||
onClick={ onClick } | ||
ariaDescribedBy={ item.description ? descriptionId : undefined } | ||
ariaDescribedBy={ !! description ? descriptionId : undefined } | ||
> | ||
{ isEmpty && isTemplatePart && __( 'Empty template part' ) } | ||
{ isEmpty && ! isTemplatePart && __( 'Empty pattern' ) } | ||
|
@@ -156,9 +157,9 @@ function Preview( { item, viewType } ) { | |
</Async> | ||
) } | ||
</PreviewWrapper> | ||
{ item.description && ( | ||
{ !! description && ( | ||
<div hidden id={ descriptionId }> | ||
{ item.description } | ||
{ description } | ||
</div> | ||
) } | ||
</div> | ||
|
@@ -222,7 +223,7 @@ function Title( { item } ) { | |
// See https://github.com/WordPress/gutenberg/pull/51898#discussion_r1243399243. | ||
tabIndex="-1" | ||
> | ||
{ title || item.name } | ||
{ title } | ||
</Button> | ||
) } | ||
</Flex> | ||
|
@@ -300,6 +301,8 @@ export default function DataviewsPatterns() { | |
header: __( 'Sync status' ), | ||
id: 'sync-status', | ||
render: ( { item } ) => { | ||
const syncStatus = | ||
item.wp_pattern_sync_status || PATTERN_SYNC_TYPES.full; | ||
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. It seems we need to check if it's a user pattern, similarly with the search. 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. If you see a few lines above, this field is only added for "user" patterns. 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. Will check now, but the rendering of the label is wrong for patterns.. 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 pushed a fix for this, but feel free to revert/update if you have a better solution.. |
||
// User patterns can have their sync statuses checked directly. | ||
// Non-user patterns are all unsynced for the time being. | ||
return ( | ||
|
@@ -309,8 +312,7 @@ export default function DataviewsPatterns() { | |
{ | ||
( | ||
SYNC_FILTERS.find( | ||
( { value } ) => | ||
value === item.syncStatus | ||
( { value } ) => value === syncStatus | ||
) || | ||
SYNC_FILTERS.find( | ||
( { value } ) => | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import { privateApis as patternsPrivateApis } from '@wordpress/patterns'; | |
* Internal dependencies | ||
*/ | ||
import { unlock } from '../../lock-unlock'; | ||
import { getItemTitle } from '../../dataviews/actions/utils'; | ||
|
||
// Patterns. | ||
const { PATTERN_TYPES } = unlock( patternsPrivateApis ); | ||
|
@@ -23,9 +24,9 @@ function getJsonFromItem( item ) { | |
return JSON.stringify( | ||
{ | ||
__file: item.type, | ||
title: item.title || item.name, | ||
content: item.patternPost.content.raw, | ||
syncStatus: item.patternPost.wp_pattern_sync_status, | ||
title: getItemTitle( item ), | ||
content: item.content.raw, | ||
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. In the DataViews, pattern content is indeed present in However, pattern export from the sidebar doesn't seem to have worked before. See this comment for more details. 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 have a small PR here: |
||
syncStatus: item.wp_pattern_sync_status, | ||
}, | ||
null, | ||
2 | ||
|
@@ -45,14 +46,16 @@ export const exportPatternAsJSONAction = { | |
callback: async ( items ) => { | ||
if ( items.length === 1 ) { | ||
return downloadBlob( | ||
`${ kebabCase( items[ 0 ].title || items[ 0 ].name ) }.json`, | ||
`${ kebabCase( | ||
getItemTitle( items[ 0 ] ) || items[ 0 ].slug | ||
) }.json`, | ||
getJsonFromItem( items[ 0 ] ), | ||
'application/json' | ||
); | ||
} | ||
const nameCount = {}; | ||
const filesToZip = items.map( ( item ) => { | ||
const name = kebabCase( item.title || item.name ); | ||
const name = kebabCase( getItemTitle( item ) || item.slug ); | ||
nameCount[ name ] = ( nameCount[ name ] || 0 ) + 1; | ||
return { | ||
name: `${ | ||
|
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 know this was from before, but it surprized me to see
raw
and notrendered
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.
Same :) I think there's some consistency work to be done on the REST API.