Skip to content

Commit

Permalink
Refactor PositionControlsPanel to simplify block attribute retrieval
Browse files Browse the repository at this point in the history
  • Loading branch information
yogeshbhutkar committed Jan 20, 2025
1 parent 6aa96a2 commit fbee655
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,26 +19,19 @@ import { store as blockEditorStore } from '../../store';
const PositionControlsPanel = () => {
const { selectedClientIDs, positionAttribute, isShownByDefault } =
useSelect( ( select ) => {
const {
getBlocksByClientId,
getSelectedBlockClientIds,
getBlockAttributes,
} = select( blockEditorStore );
const { getBlocksByClientId, getSelectedBlockClientIds } =
select( blockEditorStore );

const selectedBlockClientIds = getSelectedBlockClientIds();
const multiSelectedBlocks = getBlocksByClientId(
const selectedBlocks = getBlocksByClientId(
selectedBlockClientIds
);

// If multiple blocks are selected, the position value will be the value of the first block.
const blockAttributes = getBlockAttributes(
selectedBlockClientIds[ 0 ]
);

return {
selectedClientIDs: selectedBlockClientIds,
positionAttribute: blockAttributes?.style?.position?.type,
isShownByDefault: multiSelectedBlocks.some(
positionAttribute:
selectedBlocks?.[ 0 ]?.attributes?.style?.position?.type,
isShownByDefault: selectedBlocks?.some(
( { attributes } ) => !! attributes?.style?.position?.type
),
};
Expand Down

0 comments on commit fbee655

Please sign in to comment.