Refactor client-side usesContext augmentation

This commit is contained in:
Matt Sherman 2023-10-17 10:23:24 -04:00
parent a4002105a4
commit 6b55e7c096
1 changed files with 7 additions and 1 deletions

View File

@ -38,6 +38,12 @@ function useEvaluationContext( context: Record< string, unknown > ) {
};
}
function augmentUsesContext( usesContext?: string[] ) {
// Note: If you modify this function, also update the server-side
// Automattic\WooCommerce\Admin\Features\ProductBlockEditor\BlockRegistry::augment_uses_context() function.
return [ ...( usesContext || [] ), 'productType' ];
}
export function registerProductEditorBlockType<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
T extends Record< string, any > = Record< string, any >
@ -46,7 +52,7 @@ export function registerProductEditorBlockType<
const augmentedMetadata = {
...metadata,
usesContext: [ ...( metadata.usesContext || [] ), 'productType' ],
usesContext: augmentUsesContext( metadata.usesContext ),
};
return registerWooBlockType(