diff --git a/CHANGELOG.md b/CHANGELOG.md index e7562df4..7040f1b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to `WP Curate` will be documented in this file. +## 1.4.3 - 2023-11-28 + +- Bug fix: Adds in a temporary fix for https://github.com/alleyinteractive/alley-scripts/issues/473 +- Bug fix: Lock [nunomaduro/collision](https://github.com/nunomaduro/collision) at v6.0. Fixes failing tests via Github Actions. + ## 1.4.2 - 2023-11-01 - Bug fix: PHP tax_query wants `AND` or `IN` for `operator`. REST API wants `AND` or `OR`. diff --git a/composer.json b/composer.json index 09ae51b2..b0f11f74 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,8 @@ "php": "^8.1", "alleyinteractive/composer-wordpress-autoloader": "^1.0", "alleyinteractive/traverse-reshape": "^2.0", - "alleyinteractive/wp-type-extensions": "dev-main" + "alleyinteractive/wp-type-extensions": "dev-main", + "nunomaduro/collision": "^6.0" }, "require-dev": { "alleyinteractive/alley-coding-standards": "^2.0", diff --git a/entries/slotfills/deduplication/deduplication.tsx b/entries/slotfills/deduplication/deduplication.tsx index 51d5bcc7..424c3dad 100644 --- a/entries/slotfills/deduplication/deduplication.tsx +++ b/entries/slotfills/deduplication/deduplication.tsx @@ -3,8 +3,29 @@ import { PluginDocumentSettingPanel } from '@wordpress/edit-post'; import { __ } from '@wordpress/i18n'; import { usePostMetaValue } from '@alleyinteractive/block-editor-tools'; +/** + * The following code is a temporary fix. + * + * Once the issue linked below is resolved, this code can be removed. + * @link https://github.com/alleyinteractive/alley-scripts/issues/473 + */ +// @ts-ignore This is a temporary assignment. +// eslint-disable-next-line import/no-extraneous-dependencies +import { cloneDeep } from 'lodash'; +import { useSelect } from '@wordpress/data'; +import countBlocksByName from '@/services/countBlocksByName'; +// @ts-ignore This is a temporary assignment. +window.cloneDeepTemp = cloneDeep; + function Deduplication() { const [deduplication, setDeduplication] = usePostMetaValue('wp_curate_deduplication'); + // @ts-ignore - useSelect doesn't export proper types + const blocks = useSelect((select) => select('core/block-editor').getBlocks(), []); + const queryBlocksFound = countBlocksByName(blocks, 'wp-curate/query'); + + if (queryBlocksFound < 2) { + return null; + } return ( { + it('should return 3 when there are 3 query blocks', () => { + const count = countBlocksByName(blocksWithColumns, 'wp-curate/query'); + expect(count).toBe(3); + }); + + it('should return 0 when there are no query blocks', () => { + const count = countBlocksByName(blocksWithNoQueryBlocks, 'wp-curate/query'); + expect(count).toBe(0); + }); +}); diff --git a/services/countBlocksByName/index.ts b/services/countBlocksByName/index.ts new file mode 100644 index 00000000..b9940f00 --- /dev/null +++ b/services/countBlocksByName/index.ts @@ -0,0 +1,29 @@ +interface Block { + clientId: string; + name: string; + innerBlocks: Block[]; +} + +/** + * Count blocks by name. + * + * @param blocks An array of blocks. + * @param blockName The name of the block to count. + * @param count The current count. + */ +export default function countBlocksByName( + blocks: Block[], + blockName: string, + count = 0, +): number { + let newCount = count; + for (const block of blocks) { + if (block.name === blockName) { + newCount += 1; + } + if (block.innerBlocks && block.innerBlocks.length > 0) { + newCount = countBlocksByName(block.innerBlocks, blockName, newCount); + } + } + return newCount; +} diff --git a/wp-curate.php b/wp-curate.php index 36e68023..99161808 100644 --- a/wp-curate.php +++ b/wp-curate.php @@ -3,7 +3,7 @@ * Plugin Name: WP Curate * Plugin URI: https://github.com/alleyinteractive/wp-curate * Description: Plugin to curate homepages and other landing pages - * Version: 1.4.2 + * Version: 1.4.3 * Author: Alley Interactive * Author URI: https://github.com/alleyinteractive/wp-curate * Requires at least: 6.3