Skip to content

Commit

Permalink
Merge pull request #5617 from Automattic/add/handle-course-list-filte…
Browse files Browse the repository at this point in the history
…r-added-to-non-course-list-block

Fix issues for when course list filter is added to non course list blocks
  • Loading branch information
Imran92 authored Sep 9, 2022
2 parents 68cb4e1 + 8c8c771 commit a798f97
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ function CourseListFilter( {
const blockProps = useBlockProps();

if ( 'course' !== query?.postType ) {
setAttributes( {
align: false,
className: 'wp-block-sensei-lms-course-list-filter__warning',
} );
return (
<InvalidUsageError
message={ __(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe( 'CourseListFilterBlockEdit', () => {
clientId="some-client-id"
attributes={ { types: [ 'activity' ] } }
context={ { query: { postType: 'post' } } }
setAttributes={ jest.fn() }
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
display: flex;
flex-wrap: wrap;
justify-content: space-between;
&__warning {
display: block;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ private function register_block() {
* @return string
*/
public function render_block( $attributes, $content, WP_Block $block ): string {
if ( ! isset( $attributes['types'] ) || ! is_array( $attributes['types'] ) ) {
if (
! isset( $attributes['types'] ) ||
! is_array( $attributes['types'] ) ||
! isset( $block->context['queryId'] ) ||
'course' !== $block->context['query']['postType']
) {
return '';
}
$content = '';
Expand Down

0 comments on commit a798f97

Please sign in to comment.