Skip to content

Commit

Permalink
Do not extend the block when the AI Assistant block is hidden on the …
Browse files Browse the repository at this point in the history
…editor
  • Loading branch information
lhkowalski committed Jul 29, 2024
1 parent 39c6b7a commit 0eb07bc
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { GeneratorModal } from '@automattic/jetpack-ai-client';
import { BlockControls } from '@wordpress/block-editor';
import { getBlockType } from '@wordpress/blocks';
import { createHigherOrderComponent } from '@wordpress/compose';
import { useDispatch, useSelect } from '@wordpress/data';
import { useDispatch, useSelect, select } from '@wordpress/data';
import { useCallback, useEffect, useState } from '@wordpress/element';
import { addFilter } from '@wordpress/hooks';
/*
Expand Down Expand Up @@ -70,8 +70,8 @@ const useSetLogo = () => {
};

const useSiteDetails = () => {
const siteSettings = useSelect( select => {
return ( select( 'core' ) as CoreSelect ).getEntityRecord( 'root', 'site' );
const siteSettings = useSelect( selectData => {
return ( selectData( 'core' ) as CoreSelect ).getEntityRecord( 'root', 'site' );
}, [] );

return {
Expand Down Expand Up @@ -160,6 +160,19 @@ function canExtendBlock( name: string ): boolean {
return false;
}

/*
* Do not extend if the AI Assistant block is hidden,
* as a way for the user to hide the extension.
* TODO: the `editPostStore` is undefined for P2 sites.
* Let's find a way to check if the block is hidden there.
*/
const { getHiddenBlockTypes } = select( 'core/edit-post' ) || {};
const hiddenBlocks = getHiddenBlockTypes?.() || []; // It will extend the block if the function is undefined

if ( hiddenBlocks.includes( 'jetpack/ai-assistant' ) ) {
return false;
}

return true;
}

Expand Down

0 comments on commit 0eb07bc

Please sign in to comment.