Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export function BlockInvalidWarning( {
block,
} ) {
const hasHTMLBlock = !! getBlockType( 'core/html' );
const hasClassicBlock = !! getBlockType( 'core/freeform' );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this component should really use canInsertBlockType.

Copy link
Contributor

@talldan talldan Mar 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to add, I can push a PR that does this as a follow up, as this solves the immediate issue in the UI for the user.

(I accidentally started looking at the same issue in parallel, and already started writing the code, also refactoring it to hooks).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that would be ideal for both core/html and core/freeform checks. However, I only decided to reuse the method since this is targeted for WP 6.2 RC.

We should also refactor away from withDispatch|Select hooks in the future.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR here - #49052

const [ compare, setCompare ] = useState( false );

const onCompare = useCallback( () => setCompare( true ), [] );
Expand All @@ -41,12 +42,18 @@ export function BlockInvalidWarning( {
title: __( 'Convert to HTML' ),
onClick: convertToHTML,
},
{
hasClassicBlock && {
title: __( 'Convert to Classic Block' ),
onClick: convertToClassic,
},
].filter( Boolean ),
[ onCompare, convertToHTML, convertToClassic ]
[
onCompare,
hasHTMLBlock,
convertToHTML,
hasClassicBlock,
convertToClassic,
]
);

return (
Expand Down