From ea3504b37225b74bf2ab288832eca77250d5a3b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Su=C3=A1rez?= Date: Tue, 16 Jan 2024 10:05:04 -0300 Subject: [PATCH] [Product Block Editor]: exclude the current product from the suggested ones to use in the Linked Product tab (#43662) * exclude the current product from the suggested list * changelog --- ...update-product-editor-remove-current-from-products-list | 4 ++++ .../src/blocks/generic/linked-product-list/edit.tsx | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 packages/js/product-editor/changelog/update-product-editor-remove-current-from-products-list diff --git a/packages/js/product-editor/changelog/update-product-editor-remove-current-from-products-list b/packages/js/product-editor/changelog/update-product-editor-remove-current-from-products-list new file mode 100644 index 00000000000..67ce3fd6b1c --- /dev/null +++ b/packages/js/product-editor/changelog/update-product-editor-remove-current-from-products-list @@ -0,0 +1,4 @@ +Significance: patch +Type: add + +[Product Block Editor]: exclude the current product from the suggested ones to use in the Linked Product tab diff --git a/packages/js/product-editor/src/blocks/generic/linked-product-list/edit.tsx b/packages/js/product-editor/src/blocks/generic/linked-product-list/edit.tsx index 9e57ded9315..ae34fedc413 100644 --- a/packages/js/product-editor/src/blocks/generic/linked-product-list/edit.tsx +++ b/packages/js/product-editor/src/blocks/generic/linked-product-list/edit.tsx @@ -98,7 +98,12 @@ export function LinkedProductListBlockEdit( { const filter = useCallback( ( search = '' ) => { - return searchProductsDispatcher( linkedProductIds ?? [], search ); + // Exclude the current product and any already linked products. + const exclude = [ productId ]; + if ( linkedProductIds ) { + exclude.push( ...linkedProductIds ); + } + return searchProductsDispatcher( exclude, search ); }, [ linkedProductIds ] );