Skip to content
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

Site editor: add global styles changes to save flow #57470

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,18 @@ import { __ } from '@wordpress/i18n';
import { useSelect } from '@wordpress/data';
import { PanelBody, PanelRow } from '@wordpress/components';
import { store as coreStore } from '@wordpress/core-data';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
import { useContext } from '@wordpress/element';

/**
* Internal dependencies
*/
import EntityRecordItem from './entity-record-item';
import { unlock } from '../../lock-unlock';

const { getGlobalStylesChanges, GlobalStylesContext } = unlock(
blockEditorPrivateApis
);

function getEntityDescription( entity, count ) {
switch ( entity ) {
Expand All @@ -27,6 +34,44 @@ function getEntityDescription( entity, count ) {
}
}

function GlobalStylesDescription( { record } ) {
const { user: currentEditorGlobalStyles } =
useContext( GlobalStylesContext );
const savedRecord = useSelect(
( select ) =>
select( coreStore ).getEntityRecord(
record.kind,
record.name,
record.key
),
[ record.kind, record.name, record.key ]
);

const globalStylesChanges = getGlobalStylesChanges(
currentEditorGlobalStyles,
savedRecord,
{
maxResults: 10,
}
);
return globalStylesChanges.length ? (
<>
<h3 className="entities-saved-states__description-heading">
{ __( 'Changes made to:' ) }
</h3>
<PanelRow>{ globalStylesChanges.join( ', ' ) }</PanelRow>
</>
) : null;
}

function EntityDescription( { record, count } ) {
if ( 'globalStyles' === record?.name ) {
return <GlobalStylesDescription record={ record } />;
}
const description = getEntityDescription( record?.name, count );
return description ? <PanelRow>{ description }</PanelRow> : null;
}

export default function EntityTypeList( {
list,
unselectedEntities,
Expand All @@ -42,19 +87,16 @@ export default function EntityTypeList( {
),
[ firstRecord.kind, firstRecord.name ]
);
const { name } = firstRecord;

let entityLabel = entityConfig.label;
if ( name === 'wp_template_part' ) {
if ( firstRecord?.name === 'wp_template_part' ) {
entityLabel =
1 === count ? __( 'Template Part' ) : __( 'Template Parts' );
}
// Set description based on type of entity.
const description = getEntityDescription( name, count );

return (
<PanelBody title={ entityLabel } initialOpen={ true }>
{ description && <PanelRow>{ description }</PanelRow> }
<EntityDescription record={ firstRecord } count={ count } />
{ list.map( ( record ) => {
return (
<EntityRecordItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
margin-bottom: $grid-unit-15;
}
}

.entities-saved-states__description-heading {
font-size: $default-font-size;
}
Loading