-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathindex.js
121 lines (119 loc) · 3.09 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
import {
Icon,
__experimentalHStack as HStack,
__experimentalText as Text,
} from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { useSelect } from '@wordpress/data';
import { __ } from '@wordpress/i18n';
import { decodeEntities } from '@wordpress/html-entities';
/**
* Internal dependencies
*/
import { store as editorStore } from '../../store';
import {
TEMPLATE_POST_TYPE,
TEMPLATE_PART_POST_TYPE,
PATTERN_POST_TYPE,
GLOBAL_POST_TYPES,
} from '../../store/constants';
import { unlock } from '../../lock-unlock';
import PostActions from '../post-actions';
export default function PostCardPanel( {
postType,
postId,
onActionPerformed,
} ) {
const { isFrontPage, isPostsPage, title, icon, isSync } = useSelect(
( select ) => {
const { __experimentalGetTemplateInfo } = select( editorStore );
const { canUser, getEditedEntityRecord } = select( coreStore );
const siteSettings = canUser( 'read', {
kind: 'root',
name: 'site',
} )
? getEditedEntityRecord( 'root', 'site' )
: undefined;
const _record = getEditedEntityRecord(
'postType',
postType,
postId
);
const _templateInfo =
[ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE ].includes(
postType
) && __experimentalGetTemplateInfo( _record );
let _isSync = false;
if ( GLOBAL_POST_TYPES.includes( postType ) ) {
if ( PATTERN_POST_TYPE === postType ) {
// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.
const currentSyncStatus =
_record?.meta?.wp_pattern_sync_status === 'unsynced'
? 'unsynced'
: _record?.wp_pattern_sync_status;
_isSync = currentSyncStatus !== 'unsynced';
} else {
_isSync = true;
}
}
return {
title: _templateInfo?.title || _record?.title,
icon: unlock( select( editorStore ) ).getPostIcon( postType, {
area: _record?.area,
} ),
isSync: _isSync,
isFrontPage: siteSettings?.page_on_front === postId,
isPostsPage: siteSettings?.page_for_posts === postId,
};
},
[ postId, postType ]
);
return (
<div className="editor-post-card-panel">
<HStack
spacing={ 2 }
className="editor-post-card-panel__header"
align="flex-start"
>
<Icon
className={ clsx( 'editor-post-card-panel__icon', {
'is-sync': isSync,
} ) }
icon={ icon }
/>
<Text
numberOfLines={ 2 }
truncate
className="editor-post-card-panel__title"
weight={ 500 }
as="h2"
lineHeight="20px"
>
{ title ? decodeEntities( title ) : __( 'No title' ) }
{ isFrontPage && (
<span className="editor-post-card-panel__title-badge">
{ __( 'Homepage' ) }
</span>
) }
{ isPostsPage && (
<span className="editor-post-card-panel__title-badge">
{ __( 'Posts Page' ) }
</span>
) }
</Text>
<PostActions
postType={ postType }
postId={ postId }
onActionPerformed={ onActionPerformed }
/>
</HStack>
</div>
);
}