Skip to content

Commit

Permalink
Lodash: Remove _.pickBy() from editor hooks (#46982)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored Jan 10, 2023
1 parent 1c1cd7b commit f0834e5
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions packages/editor/src/hooks/custom-sources-backwards-compatibility.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { pickBy, mapValues, isEmpty } from 'lodash';
import { mapValues, isEmpty } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -70,18 +70,17 @@ const createWithMetaAttributeSource = ( metaAttributes ) =>
attributes={ mergedAttributes }
setAttributes={ ( nextAttributes ) => {
const nextMeta = Object.fromEntries(
Object.entries(
// Filter to intersection of keys between the updated
// attributes and those with an associated meta key.
pickBy(
nextAttributes,
( value, key ) => metaAttributes[ key ]
Object.entries( nextAttributes ?? {} )
.filter(
// Filter to intersection of keys between the updated
// attributes and those with an associated meta key.
( [ key ] ) => key in metaAttributes
)
).map( ( [ attributeKey, value ] ) => [
// Rename the keys to the expected meta key name.
metaAttributes[ attributeKey ],
value,
] )
.map( ( [ attributeKey, value ] ) => [
// Rename the keys to the expected meta key name.
metaAttributes[ attributeKey ],
value,
] )
);

if ( ! isEmpty( nextMeta ) ) {
Expand All @@ -108,7 +107,11 @@ const createWithMetaAttributeSource = ( metaAttributes ) =>
function shimAttributeSource( settings ) {
/** @type {WPMetaAttributeMapping} */
const metaAttributes = mapValues(
pickBy( settings.attributes, { source: 'meta' } ),
Object.fromEntries(
Object.entries( settings.attributes ?? {} ).filter(
( [ , { source } ] ) => source === 'meta'
)
),
'meta'
);
if ( ! isEmpty( metaAttributes ) ) {
Expand Down

1 comment on commit f0834e5

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in f0834e5.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3881178259
📝 Reported issues:

Please sign in to comment.