Skip to content

Commit

Permalink
Lodash: Remove _.isEmpty() from site editor (#50917)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyxla authored May 25, 2023
1 parent 40a9d7c commit f10f85f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import { useSelect } from '@wordpress/data';
import { store as coreStore } from '@wordpress/core-data';
import { useContext, useMemo } from '@wordpress/element';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -75,7 +72,12 @@ export default function useGlobalStylesRevisions() {
}

// Adds an item for unsaved changes.
if ( isDirty && ! isEmpty( userConfig ) && currentUser ) {
if (
isDirty &&
userConfig &&
Object.keys( userConfig ).length > 0 &&
currentUser
) {
const unsavedRevision = {
id: 'unsaved',
styles: userConfig?.styles,
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 && fills.length > 0 }
</Slot>
);

Expand Down
13 changes: 6 additions & 7 deletions packages/edit-site/src/components/revisions/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* External dependencies
*/
import { isEmpty } from 'lodash';

/**
* WordPress dependencies
*/
Expand Down Expand Up @@ -30,6 +25,10 @@ import EditorCanvasContainer from '../editor-canvas-container';
const { ExperimentalBlockEditorProvider, useGlobalStylesOutputWithConfig } =
unlock( blockEditorPrivateApis );

function isObjectEmpty( object ) {
return ! object || Object.keys( object ).length === 0;
}

function Revisions( { onClose, userConfig, blocks } ) {
const { baseConfig } = useSelect(
( select ) => ( {
Expand All @@ -42,7 +41,7 @@ function Revisions( { onClose, userConfig, blocks } ) {
);

const mergedConfig = useMemo( () => {
if ( ! isEmpty( userConfig ) && ! isEmpty( baseConfig ) ) {
if ( ! isObjectEmpty( userConfig ) && ! isObjectEmpty( baseConfig ) ) {
return mergeBaseAndUserConfigs( baseConfig, userConfig );
}
return {};
Expand All @@ -65,7 +64,7 @@ function Revisions( { onClose, userConfig, blocks } ) {
const [ globalStyles ] = useGlobalStylesOutputWithConfig( mergedConfig );

const editorStyles =
! isEmpty( globalStyles ) && ! isEmpty( userConfig )
! isObjectEmpty( globalStyles ) && ! isObjectEmpty( userConfig )
? globalStyles
: settings.styles;

Expand Down

1 comment on commit f10f85f

@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 f10f85f.
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/5076770672
📝 Reported issues:

Please sign in to comment.