Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 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
4 changes: 4 additions & 0 deletions assets/js/blocks/attribute-filter/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
"type": "boolean",
"default": false
},
"selectType": {
"type": "string",
"default": "multiple"
},
"isPreview": {
"type": "boolean",
"default": false
Expand Down
4 changes: 1 addition & 3 deletions assets/js/blocks/attribute-filter/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,7 @@ const AttributeFilterBlock = ( {
updateCheckedFilters,
] );

const multiple =
blockAttributes.displayStyle !== 'dropdown' ||
blockAttributes.queryType === 'or';
const multiple = blockAttributes.selectType !== 'single';

/**
* When a checkbox in the list changes, update state.
Expand Down
69 changes: 51 additions & 18 deletions assets/js/blocks/attribute-filter/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak }: EditProps ) => {
queryType,
showCounts,
showFilterButton,
selectType,
} = attributes;

const [ isEditing, setIsEditing ] = useState(
Expand Down Expand Up @@ -214,39 +215,71 @@ const Edit = ( { attributes, setAttributes, debouncedSpeak }: EditProps ) => {
>
<ToggleGroupControl
label={ __(
'Query Type',
'Allow selecting multiple options?',
'woo-gutenberg-products-block'
) }
help={
queryType === 'and'
? __(
'Products that have all of the selected attributes will be shown.',
'woo-gutenberg-products-block'
)
: __(
'Products that have any of the selected attributes will be shown.',
'woo-gutenberg-products-block'
)
}
value={ queryType }
value={ selectType || 'multiple' }
onChange={ ( value: string ) =>
setAttributes( {
queryType: value,
selectType: value,
} )
}
>
<ToggleGroupControlOption
value="and"
value="multiple"
label={ __(
'And',
'Multiple',
'woo-gutenberg-products-block'
) }
/>
<ToggleGroupControlOption
value="or"
label={ __( 'Or', 'woo-gutenberg-products-block' ) }
value="single"
label={ __(
'Single',
'woo-gutenberg-products-block'
) }
/>
</ToggleGroupControl>
{ selectType === 'multiple' && (
<ToggleGroupControl
label={ __(
'Query Type',
'woo-gutenberg-products-block'
) }
help={
queryType === 'and'
? __(
'Products that have all of the selected attributes will be shown.',
'woo-gutenberg-products-block'
)
: __(
'Products that have any of the selected attributes will be shown.',
'woo-gutenberg-products-block'
)
}
value={ queryType }
onChange={ ( value: string ) =>
setAttributes( {
queryType: value,
} )
}
>
<ToggleGroupControlOption
value="and"
label={ __(
'And',
'woo-gutenberg-products-block'
) }
/>
<ToggleGroupControlOption
value="or"
label={ __(
'Or',
'woo-gutenberg-products-block'
) }
/>
</ToggleGroupControl>
) }
<ToggleGroupControl
label={ __(
'Display Style',
Expand Down
4 changes: 2 additions & 2 deletions assets/js/blocks/attribute-filter/frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const getProps = ( el: HTMLElement ) => {
el.dataset.displayStyle ||
metadata.attributes.displayStyle.default,
showFilterButton: el.dataset.showFilterButton === 'true',
isPreview: false,
className: el.dataset.className || '',
selectType:
el.dataset.selectType || metadata.attributes.selectType.default,
},
};
};
Expand Down
5 changes: 5 additions & 0 deletions assets/js/blocks/attribute-filter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ registerBlockType( metadata, {
headingLevel: 3,
displayStyle: instance?.raw?.display_type || 'list',
showFilterButton: false,
selectType: instance?.raw?.select_type || 'multiple',
isPreview: false,
} ),
},
Expand All @@ -83,6 +84,7 @@ registerBlockType( metadata, {
headingLevel,
displayStyle,
showFilterButton,
selectType,
} = attributes;
const data: Record< string, unknown > = {
'data-attribute-id': attributeId,
Expand All @@ -97,6 +99,9 @@ registerBlockType( metadata, {
if ( showFilterButton ) {
data[ 'data-show-filter-button' ] = showFilterButton;
}
if ( selectType === 'single' ) {
data[ 'data-select-type' ] = selectType;
}
return (
<div
{ ...useBlockProps.save( {
Expand Down
5 changes: 3 additions & 2 deletions assets/js/blocks/attribute-filter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@
import type { BlockEditProps } from '@wordpress/blocks';

export interface BlockAttributes {
className: string;
className?: string;
attributeId: number;
showCounts: boolean;
queryType: string;
heading: string;
headingLevel: number;
displayStyle: string;
showFilterButton: boolean;
isPreview: boolean;
selectType: string;
isPreview?: boolean;
}

export interface EditProps extends BlockEditProps< BlockAttributes > {
Expand Down