From 1c68e2dd9f67aabc181859df137faa7857eb74c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alba=20Rinc=C3=B3n?= Date: Tue, 5 Mar 2024 18:21:44 +0100 Subject: [PATCH] [CYS] Fix the selected pattern in footer, header and homepage (#45240) * Check also the number of inner blocks before checking the attributes * Add classes to assembler footer patterns * Add classes to assembler header patterns * Add changefile(s) from automation for the following project(s): woocommerce * Mark the current homepage template as selected * Remove unused import --------- Co-authored-by: github-actions --- .../sidebar-navigation-screen-homepage.tsx | 17 ++++++++++++++++- .../assembler-hub/sidebar/utils.ts | 10 +++++++--- .../changelog/45240-45215-fix-selected-footer | 4 ++++ plugins/woocommerce/patterns/footer-large.php | 2 +- .../woocommerce/patterns/footer-simple-menu.php | 2 +- .../patterns/footer-with-3-menus.php | 2 +- .../patterns/header-centered-pattern.php | 2 +- .../woocommerce/patterns/header-essential.php | 2 +- plugins/woocommerce/patterns/header-large.php | 2 +- plugins/woocommerce/patterns/header-minimal.php | 2 +- 10 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 plugins/woocommerce/changelog/45240-45215-fix-selected-footer diff --git a/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/sidebar-navigation-screen-homepage.tsx b/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/sidebar-navigation-screen-homepage.tsx index 38826cbbb880..744b07968f25 100644 --- a/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/sidebar-navigation-screen-homepage.tsx +++ b/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/sidebar-navigation-screen-homepage.tsx @@ -92,8 +92,23 @@ export const SidebarNavigationScreenHomepage = () => { return; } - setSelectedPattern( selectedPattern ); + const currentSelectedPattern = homePatterns.find( ( patterns ) => { + //'blocks' contains all blocks in the template, including the + // header and footer blocks, while the 'patterns.blocks' does + // not. For that reason we are removing the first and last + // blocks from the 'blocks' to be able to compare then + const homeBlocks = blocks.slice( 1, blocks.length - 1 ); + if ( patterns.blocks.length !== homeBlocks.length ) { + return false; + } + + return homeBlocks.every( + ( block, i ) => block.name === patterns.blocks[ i ].name + ); + } ); + + setSelectedPattern( currentSelectedPattern ); // eslint-disable-next-line react-hooks/exhaustive-deps -- we don't want to re-run this effect when currentSelectedPattern changes }, [ blocks, homePatterns ] ); diff --git a/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/utils.ts b/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/utils.ts index 535c84d9c60e..25096c886a38 100644 --- a/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/utils.ts +++ b/plugins/woocommerce-admin/client/customize-store/assembler-hub/sidebar/utils.ts @@ -24,8 +24,12 @@ export const findPatternByBlock = ( '' ); } + return patterns.find( ( pattern ) => { + const patternBlocks = pattern.blocks[ 0 ]; + if ( patternBlocks.innerBlocks.length !== block.innerBlocks.length ) { + return false; + } - return patterns.find( ( pattern ) => - isEqual( pattern.blocks[ 0 ].attributes, blockAttributes ) - ); + return isEqual( patternBlocks.attributes, blockAttributes ); + } ); }; diff --git a/plugins/woocommerce/changelog/45240-45215-fix-selected-footer b/plugins/woocommerce/changelog/45240-45215-fix-selected-footer new file mode 100644 index 000000000000..0ae0fbecfb3f --- /dev/null +++ b/plugins/woocommerce/changelog/45240-45215-fix-selected-footer @@ -0,0 +1,4 @@ +Significance: minor +Type: fix + +CYS - Fix the selected pattern in footer in the assembler. \ No newline at end of file diff --git a/plugins/woocommerce/patterns/footer-large.php b/plugins/woocommerce/patterns/footer-large.php index 10a495f976ab..a82fd7d62349 100644 --- a/plugins/woocommerce/patterns/footer-large.php +++ b/plugins/woocommerce/patterns/footer-large.php @@ -8,7 +8,7 @@ ?> -