Skip to content

Commit

Permalink
CYS: fix logic to disable mover buttons (woocommerce#48502)
Browse files Browse the repository at this point in the history
* CYS: fix logic to disable mover buttons

* Add changefile(s) from automation for the following project(s): woocommerce

---------

Co-authored-by: github-actions <github-actions@github.com>
  • Loading branch information
gigitux and github-actions authored Jun 17, 2024
1 parent 4162a6e commit 317fcae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,35 @@ export const Toolbar = () => {

setIsHomepageSidebarOpen( isHomepageUrl( path ) );
}, [ query ] );
const { isPreviousBlockTemplatePart, isNextBlockTemplatePart } =
useMemo( () => {
return {
isPreviousBlockTemplatePart:
previousBlock?.name === 'core/template-part',
isNextBlockTemplatePart:
nextBlock?.name === 'core/template-part',
};
}, [ nextBlock?.name, previousBlock?.name ] );

const selectedBlockClientId =
currentBlock?.clientId ?? firstBlock?.clientId;

const { isBlockMoverUpButtonDisabled, isBlockMoverDownButtonDisabled } =
useMemo( () => {
const isPreviousBlockTemplatePart =
previousBlock?.name === 'core/template-part';
const isNextBlockTemplatePart =
nextBlock?.name === 'core/template-part';

return {
isBlockMoverUpButtonDisabled:
isPreviousBlockTemplatePart ||
// The first block is the header, which is not movable.
allBlocks[ 1 ]?.clientId === selectedBlockClientId,
isBlockMoverDownButtonDisabled:
isNextBlockTemplatePart ||
// The last block is the footer, which is not movable.
allBlocks[ allBlocks.length - 2 ]?.clientId ===
selectedBlockClientId,
};
}, [
allBlocks,
nextBlock?.name,
previousBlock?.name,
selectedBlockClientId,
] );

const isNoBlocksPlaceholderPresent =
useIsNoBlocksPlaceholderPresent( allBlocks );

Expand Down Expand Up @@ -136,10 +152,10 @@ export const Toolbar = () => {
<BlockMover
clientIds={ [ selectedBlockClientId ] }
isBlockMoverUpButtonDisabled={
isPreviousBlockTemplatePart
isBlockMoverUpButtonDisabled
}
isBlockMoverDownButtonDisabled={
isNextBlockTemplatePart
isBlockMoverDownButtonDisabled
}
/>
</ToolbarGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: fix

CYS: fix logic to disable mover buttons. </details> <details> <summary>Changelog Entry Comment</summary>

0 comments on commit 317fcae

Please sign in to comment.