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 completely from @wordpress/edit-widgets package #43682

Merged
merged 1 commit into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions packages/edit-widgets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@
"@wordpress/reusable-blocks": "file:../reusable-blocks",
"@wordpress/url": "file:../url",
"@wordpress/widgets": "file:../widgets",
"classnames": "^2.3.1",
"lodash": "^4.17.21"
"classnames": "^2.3.1"
},
"peerDependencies": {
"react": "^17.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { castArray } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -20,13 +15,14 @@ function KeyCombination( { keyCombination, forceAriaLabel } ) {
keyCombination.character
)
: keyCombination.character;
const shortcuts = Array.isArray( shortcut ) ? shortcut : [ shortcut ];

return (
<kbd
className="edit-widgets-keyboard-shortcut-help-modal__shortcut-key-combination"
aria-label={ forceAriaLabel || ariaLabel }
>
{ castArray( shortcut ).map( ( character, index ) => {
{ shortcuts.map( ( character, index ) => {
if ( character === '+' ) {
return <Fragment key={ index }>{ character }</Fragment>;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -14,7 +9,7 @@ const { Fill: ToolsMoreMenuGroup, Slot } = createSlotFill(

ToolsMoreMenuGroup.Slot = ( { fillProps } ) => (
<Slot fillProps={ fillProps }>
{ ( fills ) => ! isEmpty( fills ) && fills }
{ ( fills ) => fills.length > 0 && fills }
Copy link
Contributor

Choose a reason for hiding this comment

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

Can fills be undefined?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for double-checking, but nope, it's always an array:

const fills = ( getFills( name, this ) ?? [] )
.map( ( fill ) => {
const fillChildren = isFunction( fill.children )
? fill.children( fillProps )
: fill.children;
return Children.map( fillChildren, ( child, childIndex ) => {
if ( ! child || typeof child === 'string' ) {
return child;
}
const childKey = child.key || childIndex;
return cloneElement( child, { key: childKey } );
} );
} )
.filter(
// In some cases fills are rendered only when some conditions apply.
// This ensures that we only use non-empty fills when rendering, i.e.,
// it allows us to render wrappers only when the fills are actually present.
( element ) => ! isEmptyElement( element )
);
return <>{ isFunction( children ) ? children( fills ) : fills }</>;

Copy link
Member

Choose a reason for hiding this comment

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

Well, then I don't understand why we needed the second fills here 😅? It probably would be safe also to delete it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, then I don't understand why we needed the second fills here 😅? It probably would be safe also to delete it.

I left it as-is, but I can open a follow-up PR if you feel strongly about it 😅

</Slot>
);

Expand Down
25 changes: 9 additions & 16 deletions packages/edit-widgets/src/components/notices/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { filter } from 'lodash';

/**
* WordPress dependencies
*/
Expand All @@ -18,17 +13,15 @@ function Notices() {
};
}, [] );

const dismissibleNotices = filter( notices, {
isDismissible: true,
type: 'default',
} );
const nonDismissibleNotices = filter( notices, {
isDismissible: false,
type: 'default',
} );
const snackbarNotices = filter( notices, {
type: 'snackbar',
} );
const dismissibleNotices = notices.filter(
( { isDismissible, type } ) => isDismissible && type === 'default'
);
const nonDismissibleNotices = notices.filter(
( { isDismissible, type } ) => ! isDismissible && type === 'default'
);
const snackbarNotices = notices.filter(
( { type } ) => type === 'snackbar'
);

return (
<>
Expand Down