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

Lodash: Remove from block registration API #43558

Merged
merged 1 commit into from
Aug 24, 2022
Merged
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
20 changes: 11 additions & 9 deletions packages/blocks/src/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* External dependencies
*/
import { camelCase } from 'change-case';
import { isEmpty, pick, pickBy } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -174,12 +173,11 @@ export function unstable__bootstrapServerSideBlockDefinitions( definitions ) {
}

serverSideBlockDefinitions[ blockName ] = Object.fromEntries(
Object.entries(
pickBy(
definitions[ blockName ],
( value ) => value !== null && value !== undefined
Object.entries( definitions[ blockName ] )
.filter(
( [ , value ] ) => value !== null && value !== undefined
)
).map( ( [ key, value ] ) => [ camelCase( key ), value ] )
.map( ( [ key, value ] ) => [ camelCase( key ), value ] )
);
}
}
Expand Down Expand Up @@ -211,7 +209,11 @@ function getBlockSettingsFromMetadata( { textdomain, ...metadata } ) {
'variations',
];

const settings = pick( metadata, allowedFields );
const settings = Object.fromEntries(
Object.entries( metadata ).filter( ( [ key ] ) =>
allowedFields.includes( key )
)
);

if ( textdomain ) {
Object.keys( i18nBlockSchema ).forEach( ( key ) => {
Expand Down Expand Up @@ -321,7 +323,7 @@ function translateBlockSettingUsingI18nSchema(
}
if (
Array.isArray( i18nSchema ) &&
! isEmpty( i18nSchema ) &&
i18nSchema.length &&
Array.isArray( settingValue )
) {
return settingValue.map( ( value ) =>
Expand All @@ -334,7 +336,7 @@ function translateBlockSettingUsingI18nSchema(
}
if (
isObject( i18nSchema ) &&
! isEmpty( i18nSchema ) &&
Object.entries( i18nSchema ).length &&
isObject( settingValue )
) {
return Object.keys( settingValue ).reduce( ( accumulator, key ) => {
Expand Down