Skip to content

Commit

Permalink
Update: For synced entities the icon should be purple. (WordPress#62024)
Browse files Browse the repository at this point in the history
Co-authored-by: jorgefilipecosta <[email protected]>
Co-authored-by: jameskoster <[email protected]>
  • Loading branch information
3 people authored and patil-vipul committed Jun 17, 2024
1 parent 236412f commit 36d6f97
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
9 changes: 1 addition & 8 deletions packages/editor/src/components/document-bar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { useReducedMotion } from '@wordpress/compose';
/**
* Internal dependencies
*/
import { TEMPLATE_POST_TYPES, GLOBAL_POST_TYPES } from '../../store/constants';
import { store as editorStore } from '../../store';
import { unlock } from '../../lock-unlock';

Expand All @@ -39,14 +40,6 @@ const TYPE_LABELS = {
wp_template_part: __( 'Editing template part: %s' ),
};

const TEMPLATE_POST_TYPES = [ 'wp_template', 'wp_template_part' ];

const GLOBAL_POST_TYPES = [
...TEMPLATE_POST_TYPES,
'wp_block',
'wp_navigation',
];

const MotionButton = motion( Button );

/**
Expand Down
30 changes: 28 additions & 2 deletions packages/editor/src/components/post-card-panel/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* External dependencies
*/
import clsx from 'clsx';
/**
* WordPress dependencies
*/
Expand All @@ -18,11 +22,13 @@ 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';

export default function PostCardPanel( { actions } ) {
const { title, icon } = useSelect( ( select ) => {
const { title, icon, isSync } = useSelect( ( select ) => {
const {
getEditedPostAttribute,
getCurrentPostType,
Expand All @@ -36,11 +42,26 @@ export default function PostCardPanel( { actions } ) {
const _templateInfo =
[ TEMPLATE_POST_TYPE, TEMPLATE_PART_POST_TYPE ].includes( _type ) &&
__experimentalGetTemplateInfo( _record );
let _isSync = false;
if ( GLOBAL_POST_TYPES.includes( _type ) ) {
if ( PATTERN_POST_TYPE === _type ) {
// When the post is first created, the top level wp_pattern_sync_status is not set so get meta value instead.
const currentSyncStatus =
getEditedPostAttribute( 'meta' )?.wp_pattern_sync_status ===
'unsynced'
? 'unsynced'
: getEditedPostAttribute( 'wp_pattern_sync_status' );
_isSync = currentSyncStatus !== 'unsynced';
} else {
_isSync = true;
}
}
return {
title: _templateInfo?.title || getEditedPostAttribute( 'title' ),
icon: unlock( select( editorStore ) ).getPostIcon( _type, {
area: _record?.area,
} ),
isSync: _isSync,
};
}, [] );
return (
Expand All @@ -50,7 +71,12 @@ export default function PostCardPanel( { actions } ) {
className="editor-post-card-panel__header"
align="flex-start"
>
<Icon className="editor-post-card-panel__icon" icon={ icon } />
<Icon
className={ clsx( 'editor-post-card-panel__icon', {
'is-sync': isSync,
} ) }
icon={ icon }
/>
<Text
numberOfLines={ 2 }
truncate
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/components/post-card-panel/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@
margin-bottom: $grid-unit-10;
}
}

.editor-post-card-panel__icon.is-sync {
fill: var(--wp-block-synced-color);
}
6 changes: 6 additions & 0 deletions packages/editor/src/store/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ export const TEMPLATE_ORIGINS = {
theme: 'theme',
plugin: 'plugin',
};
export const TEMPLATE_POST_TYPES = [ 'wp_template', 'wp_template_part' ];
export const GLOBAL_POST_TYPES = [
...TEMPLATE_POST_TYPES,
'wp_block',
'wp_navigation',
];

0 comments on commit 36d6f97

Please sign in to comment.