Skip to content

Commit

Permalink
Lodash: Remove completely from site editor (#52480)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla committed Jul 11, 2023
1 parent ec66d6c commit 0c28bc2
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 deletions.
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
"downloadjs": "^1.4.7",
"fast-deep-equal": "^3.1.3",
"is-plain-object": "^5.0.0",
"lodash": "^4.17.21",
"memize": "^2.1.0",
"react-autosize-textarea": "^7.1.0",
"rememo": "^4.0.2",
Expand Down
15 changes: 9 additions & 6 deletions packages/edit-site/src/components/add-new-template/utils.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { get } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -20,6 +15,14 @@ import { blockMeta, post, archive } from '@wordpress/icons';
* @property {string} name The entity's name.
*/

const getValueFromObjectPath = ( object, path ) => {
let value = object;
path.split( '.' ).forEach( ( fieldName ) => {
value = value?.[ fieldName ];
} );
return value;
};

/**
* Helper util to map records to add a `name` prop from a
* provided path, in order to handle all entities in the same
Expand All @@ -32,7 +35,7 @@ import { blockMeta, post, archive } from '@wordpress/icons';
export const mapToIHasNameAndId = ( entities, path ) => {
return ( entities || [] ).map( ( entity ) => ( {
...entity,
name: decodeEntities( get( entity, path ) ),
name: decodeEntities( getValueFromObjectPath( entity, path ) ),
} ) );
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { get } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -96,6 +91,14 @@ const STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {

const SUPPORTED_STYLES = [ 'border', 'color', 'spacing', 'typography' ];

const getValueFromObjectPath = ( object, path ) => {
let value = object;
path.forEach( ( fieldName ) => {
value = value?.[ fieldName ];
} );
return value;
};

function useChangesToPush( name, attributes ) {
const supports = useSupportedStyles( name );

Expand All @@ -115,7 +118,7 @@ function useChangesToPush( name, attributes ) {
];
const value = presetAttributeValue
? `var:preset|${ STYLE_PATH_TO_CSS_VAR_INFIX[ presetAttributeKey ] }|${ presetAttributeValue }`
: get( attributes.style, path );
: getValueFromObjectPath( attributes.style, path );
return value ? [ { path, value } ] : [];
} ),
[ supports, name, attributes ]
Expand Down

1 comment on commit 0c28bc2

@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 0c28bc2.
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/5516835587
📝 Reported issues:

Please sign in to comment.