[Experimental] Add Widget support to new collection filter blocks (#43153)

This commit is contained in:
Tung Du 2024-01-04 11:56:24 +07:00 committed by GitHub
parent 73160b3c41
commit de1d60ebe4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 59 additions and 5 deletions

View File

@ -1,7 +1,12 @@
/**
* External dependencies
*/
import { store, navigate, getContext } from '@woocommerce/interactivity';
import { store, getContext } from '@woocommerce/interactivity';
/**
* Internal dependencies
*/
import { navigate } from '../../utils';
type ActiveFiltersContext = {
queryId: number;

View File

@ -1,10 +1,15 @@
/**
* External dependencies
*/
import { store, navigate, getContext } from '@woocommerce/interactivity';
import { store, getContext } from '@woocommerce/interactivity';
import { DropdownContext } from '@woocommerce/interactivity-components/dropdown';
import { HTMLElementEvent } from '@woocommerce/types';
/**
* Internal dependencies
*/
import { navigate } from '../../utils';
type AttributeFilterContext = {
attributeSlug: string;
queryType: 'or' | 'and';

View File

@ -1,13 +1,14 @@
/**
* External dependencies
*/
import { store, navigate, getContext } from '@woocommerce/interactivity';
import { store, getContext } from '@woocommerce/interactivity';
import { formatPrice, getCurrency } from '@woocommerce/price-format';
import { HTMLElementEvent } from '@woocommerce/types';
/**
* Internal dependencies
*/
import { navigate } from '../../utils';
import type { PriceFilterContext, PriceFilterStore } from './types';
const getUrl = ( context: PriceFilterContext ) => {

View File

@ -1,10 +1,15 @@
/**
* External dependencies
*/
import { getContext, navigate, store } from '@woocommerce/interactivity';
import { getContext, store } from '@woocommerce/interactivity';
import { CheckboxListContext } from '@woocommerce/interactivity-components/checkbox-list';
import { DropdownContext } from '@woocommerce/interactivity-components/dropdown';
/**
* Internal dependencies
*/
import { navigate } from '../../utils';
function getUrl( filters: Array< string | null > ) {
filters = filters.filter( Boolean );
const url = new URL( window.location.href );

View File

@ -1,11 +1,16 @@
/**
* External dependencies
*/
import { store, navigate, getContext } from '@woocommerce/interactivity';
import { store, getContext } from '@woocommerce/interactivity';
import { DropdownContext } from '@woocommerce/interactivity-components/dropdown';
import { HTMLElementEvent } from '@woocommerce/types';
import { CheckboxListContext } from '@woocommerce/interactivity-components/checkbox-list';
/**
* Internal dependencies
*/
import { navigate } from '../../utils';
const getUrl = ( activeFilters: string ) => {
const url = new URL( window.location.href );
const { searchParams } = url;

View File

@ -0,0 +1,15 @@
/**
* External dependencies
*/
import { navigate as navigateFn } from '@woocommerce/interactivity';
import { getSetting } from '@woocommerce/settings';
const isBlockTheme = getSetting< boolean >( 'isBlockTheme' );
const isProductArchive = getSetting< boolean >( 'isProductArchive' );
export function navigate( href: string, options = {} ) {
if ( ! isBlockTheme && isProductArchive ) {
return ( window.location.href = href );
}
return navigateFn( href, options );
}

View File

@ -0,0 +1,4 @@
Significance: patch
Type: add
Comment: Add Widget support to new collection filter blocks.

View File

@ -53,6 +53,20 @@ final class CollectionFilters extends AbstractBlock {
add_action( 'render_block_context', array( $this, 'modify_inner_blocks_context' ), 10, 3 );
}
/**
* Extra data passed through from server to client for block.
*
* @param array $attributes Any attributes that currently are available from the block.
* Note, this will be empty in the editor context when the block is
* not in the post content on editor load.
*/
protected function enqueue_data( array $attributes = [] ) {
parent::enqueue_data( $attributes );
$this->asset_data_registry->add( 'isBlockTheme', wc_current_theme_is_fse_theme(), true );
$this->asset_data_registry->add( 'isProductArchive', is_shop() || is_product_taxonomy(), true );
}
/**
* Render the block.
*