Skip to content
Prev Previous commit
Import from getWidgetIdFromBlock
  • Loading branch information
kevin940726 committed May 4, 2021
commit 7a00a02cd9ec490c52633ea6596e4d9b1502d30f
7 changes: 4 additions & 3 deletions packages/edit-widgets/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import { __, sprintf } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';
import { store as interfaceStore } from '@wordpress/interface';
import { getWidgetIdFromBlock } from '@wordpress/widgets';

/**
* Internal dependencies
*/
Expand Down Expand Up @@ -122,8 +124,7 @@ export function* saveWidgetArea( widgetAreaId ) {
const deletedWidgets = areaWidgets.filter(
( { id } ) =>
! widgetsBlocks.some(
( { attributes: { __internalWidgetId } } ) =>
__internalWidgetId === id
( widgetBlock ) => getWidgetIdFromBlock( widgetBlock ) === id
)
);

Expand All @@ -132,7 +133,7 @@ export function* saveWidgetArea( widgetAreaId ) {
const sidebarWidgetsIds = [];
for ( let i = 0; i < widgetsBlocks.length; i++ ) {
const block = widgetsBlocks[ i ];
const widgetId = block.attributes.__internalWidgetId;
const widgetId = getWidgetIdFromBlock( block );
const oldWidget = widgets[ widgetId ];
const widget = transformBlockToWidget( block, oldWidget );
// We'll replace the null widgetId after save, but we track it here
Expand Down
5 changes: 3 additions & 2 deletions packages/edit-widgets/src/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { keyBy } from 'lodash';
* WordPress dependencies
*/
import { createRegistrySelector } from '@wordpress/data';
import { getWidgetIdFromBlock } from '@wordpress/widgets';

/**
* Internal dependencies
Expand Down Expand Up @@ -68,8 +69,8 @@ export const getWidgetAreaForWidgetId = createRegistrySelector(
POST_TYPE,
buildWidgetAreaPostId( widgetArea.id )
);
const blockWidgetIds = post.blocks.map(
( block ) => block.attributes.__internalWidgetId
const blockWidgetIds = post.blocks.map( ( block ) =>
getWidgetIdFromBlock( block )
);
return blockWidgetIds.includes( widgetId );
} );
Expand Down