Skip to content

Commit

Permalink
Lodash: Remove more _.isEmpty() from block editor (#51098)
Browse files Browse the repository at this point in the history
* Lodash: Remove more _.isEmpty() from block editor

* Remove unnecessary boolean check

* Remove unnecessary optional chaining
  • Loading branch information
tyxla authored Jun 1, 2023
1 parent 95aa73f commit 1a61aa0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -23,7 +18,8 @@ export default createHigherOrderComponent( ( WrappedComponent ) => {
props.disableCustomColors === undefined
? disableCustomColorsFeature
: props.disableCustomColors;
const hasColorsToChoose = ! isEmpty( colors ) || ! disableCustomColors;
const hasColorsToChoose =
( colors && colors.length > 0 ) || ! disableCustomColors;
return (
<WrappedComponent
{ ...{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -58,10 +57,11 @@ function ColorGradientControlInner( {
headingLevel,
} ) {
const canChooseAColor =
onColorChange && ( ! isEmpty( colors ) || ! disableCustomColors );
onColorChange &&
( ( colors && colors.length > 0 ) || ! disableCustomColors );
const canChooseAGradient =
onGradientChange &&
( ! isEmpty( gradients ) || ! disableCustomGradients );
( ( gradients && gradients.length > 0 ) || ! disableCustomGradients );

if ( ! canChooseAColor && ! canChooseAGradient ) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -43,14 +42,14 @@ export const PanelColorGradientSettingsInner = ( {
const panelId = useInstanceId( PanelColorGradientSettingsInner );
const { batch } = useRegistry();
if (
isEmpty( colors ) &&
isEmpty( gradients ) &&
( ! colors || colors.length === 0 ) &&
( ! gradients || gradients.length === 0 ) &&
disableCustomColors &&
disableCustomGradients &&
settings?.every(
( setting ) =>
isEmpty( setting.colors ) &&
isEmpty( setting.gradients ) &&
( ! setting.colors || setting.colors.length === 0 ) &&
( ! setting.gradients || setting.gradients.length === 0 ) &&
( setting.disableCustomColors === undefined ||
setting.disableCustomColors ) &&
( setting.disableCustomGradients === undefined ||
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { get, isEmpty } from 'lodash';
import { get } from 'lodash';

/**
* Internal dependencies
Expand Down Expand Up @@ -31,7 +31,7 @@ export function getBlockCSSSelector(
const { fallback = false } = options;
const { name, selectors, supports } = blockType;

const hasSelectors = ! isEmpty( selectors );
const hasSelectors = selectors && Object.keys( selectors ).length > 0;
const path = Array.isArray( target ) ? target.join( '.' ) : target;

// Root selector.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { get, isEmpty, kebabCase, set } from 'lodash';
import { get, kebabCase, set } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -697,7 +697,7 @@ export const getNodesWithSettings = ( tree, blockSelectors ) => {
// Top-level.
const presets = pickPresets( tree.settings );
const custom = tree.settings?.custom;
if ( ! isEmpty( presets ) || custom ) {
if ( Object.keys( presets ).length > 0 || custom ) {
nodes.push( {
presets,
custom,
Expand All @@ -710,7 +710,7 @@ export const getNodesWithSettings = ( tree, blockSelectors ) => {
( [ blockName, node ] ) => {
const blockPresets = pickPresets( node );
const blockCustom = node.custom;
if ( ! isEmpty( blockPresets ) || blockCustom ) {
if ( Object.keys( blockPresets ).length > 0 || blockCustom ) {
nodes.push( {
presets: blockPresets,
custom: blockCustom,
Expand Down Expand Up @@ -976,7 +976,7 @@ export const toStyles = (
}

const classes = getPresetsClasses( selector, presets );
if ( ! isEmpty( classes ) ) {
if ( classes.length > 0 ) {
ruleset += classes;
}
} );
Expand All @@ -992,7 +992,10 @@ export function toSvgFilters( tree, blockSelectors ) {
}

const getSelectorsConfig = ( blockType, rootSelector ) => {
if ( ! isEmpty( blockType?.selectors ) ) {
if (
blockType?.selectors &&
Object.keys( blockType.selectors ).length > 0
) {
return blockType.selectors;
}

Expand Down

1 comment on commit 1a61aa0

@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 1a61aa0.
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/5143639638
📝 Reported issues:

Please sign in to comment.