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

Components: Remove Lodash from DropdownMenu #42218

Merged
merged 4 commits into from
Jul 12, 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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -24,6 +24,7 @@
- `ComboboxControl`: Refactor away from `_.deburr()` ([#42169](https://github.com/WordPress/gutenberg/pull/42169/)).
- `FormTokenField`: Refactor away from `_.identity()` ([#42215](https://github.com/WordPress/gutenberg/pull/42215/)).
- `SelectControl`: Use roles and `@testing-library/user-event` in unit tests ([#42308](https://github.com/WordPress/gutenberg/pull/42308)).
- `DropdownMenu`: Refactor away from Lodash ([#42218](https://github.com/WordPress/gutenberg/pull/42218/)).
- `ToolbarGroup`: Refactor away from `_.flatMap()` ([#42223](https://github.com/WordPress/gutenberg/pull/42223/)).
- `TreeSelect`: Refactor away from `_.flatMap()` ([#42223](https://github.com/WordPress/gutenberg/pull/42223/)).
- `Autocomplete`: Refactor away from `_.deburr()` ([#42266](https://github.com/WordPress/gutenberg/pull/42266/)).
7 changes: 3 additions & 4 deletions packages/components/src/dropdown-menu/index.js
Original file line number Diff line number Diff line change
@@ -3,7 +3,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { flatMap, isEmpty } from 'lodash';

/**
* WordPress dependencies
@@ -59,13 +58,13 @@ function DropdownMenu( dropdownMenuProps ) {
noIcons,
} = dropdownMenuProps;

if ( isEmpty( controls ) && ! isFunction( children ) ) {
if ( ! controls?.length && ! isFunction( children ) ) {
return null;
}

// Normalize controls to nested array of objects (sets of controls)
let controlSets;
if ( ! isEmpty( controls ) ) {
if ( controls?.length ) {
controlSets = controls;
if ( ! Array.isArray( controlSets[ 0 ] ) ) {
controlSets = [ controlSets ];
@@ -146,7 +145,7 @@ function DropdownMenu( dropdownMenuProps ) {
return (
<NavigableMenu { ...mergedMenuProps } role="menu">
{ isFunction( children ) ? children( props ) : null }
{ flatMap( controlSets, ( controlSet, indexOfSet ) =>
{ controlSets?.flatMap( ( controlSet, indexOfSet ) =>
controlSet.map( ( control, indexOfControl ) => (
<Button
key={ [
8 changes: 3 additions & 5 deletions packages/components/src/dropdown-menu/index.native.js
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@
* External dependencies
*/
import classnames from 'classnames';
import { flatMap, isEmpty } from 'lodash';
import { Platform } from 'react-native';
/**
* WordPress dependencies
@@ -53,13 +52,13 @@ function DropdownMenu( {
popoverProps,
toggleProps,
} ) {
if ( isEmpty( controls ) && ! isFunction( children ) ) {
if ( ! controls?.length && ! isFunction( children ) ) {
return null;
}

// Normalize controls to nested array of objects (sets of controls)
let controlSets;
if ( ! isEmpty( controls ) ) {
if ( controls?.length ) {
controlSets = controls;
if ( ! Array.isArray( controlSets[ 0 ] ) ) {
controlSets = [ controlSets ];
@@ -131,8 +130,7 @@ function DropdownMenu( {
title={ label }
style={ { paddingLeft: 0, paddingRight: 0 } }
>
{ flatMap(
controlSets,
{ controlSets?.flatMap(
( controlSet, indexOfSet ) =>
controlSet.map(
( control, indexOfControl ) => (