This repository has been archived by the owner on Feb 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add/attributes filter count display toggle (#9833)
* Default show product counts to false for filter by attributes block * Default show product counts to false for filter by stock block * Default show product counts to false for filter by rating block * Refactor deprecation * Refactor deprecation * Refactor deprecation
- Loading branch information
Showing
9 changed files
with
196 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
import { isFeaturePluginBuild } from '@woocommerce/block-settings'; | ||
import classNames from 'classnames'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import type { BlockAttributes } from './types'; | ||
import { blockAttributes } from './attributes'; | ||
import metadata from './block.json'; | ||
|
||
const v1 = { | ||
supports: { | ||
...metadata.supports, | ||
...( isFeaturePluginBuild() && { | ||
__experimentalBorder: { | ||
radius: false, | ||
color: true, | ||
width: false, | ||
}, | ||
} ), | ||
}, | ||
attributes: { | ||
...metadata.attributes, | ||
showCounts: { | ||
type: 'boolean', | ||
default: true, | ||
}, | ||
...blockAttributes, | ||
}, | ||
save: ( { attributes }: { attributes: BlockAttributes } ) => { | ||
const { | ||
className, | ||
showCounts, | ||
queryType, | ||
attributeId, | ||
heading, | ||
headingLevel, | ||
displayStyle, | ||
showFilterButton, | ||
selectType, | ||
} = attributes; | ||
const data: Record< string, unknown > = { | ||
'data-attribute-id': attributeId, | ||
'data-show-counts': showCounts, | ||
'data-query-type': queryType, | ||
'data-heading': heading, | ||
'data-heading-level': headingLevel, | ||
}; | ||
if ( displayStyle !== 'list' ) { | ||
data[ 'data-display-style' ] = displayStyle; | ||
} | ||
if ( showFilterButton ) { | ||
data[ 'data-show-filter-button' ] = showFilterButton; | ||
} | ||
if ( selectType === 'single' ) { | ||
data[ 'data-select-type' ] = selectType; | ||
} | ||
return ( | ||
<div | ||
{ ...useBlockProps.save( { | ||
className: classNames( 'is-loading', className ), | ||
} ) } | ||
{ ...data } | ||
> | ||
<span | ||
aria-hidden | ||
className="wc-block-product-attribute-filter__placeholder" | ||
/> | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
const deprecated = [ v1 ]; | ||
|
||
export default deprecated; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classNames from 'classnames'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import type { Attributes } from './types'; | ||
|
||
const v1 = { | ||
attributes: { | ||
...metadata.attributes, | ||
showCounts: { | ||
type: 'boolean', | ||
default: true, | ||
}, | ||
}, | ||
save: ( { attributes }: { attributes: Attributes } ) => { | ||
const { className, showCounts } = attributes; | ||
const data: Record< string, unknown > = { | ||
'data-show-counts': showCounts, | ||
}; | ||
return ( | ||
<div | ||
{ ...useBlockProps.save( { | ||
className: classNames( 'is-loading', className ), | ||
} ) } | ||
{ ...data } | ||
> | ||
<span | ||
aria-hidden | ||
className="wc-block-product-rating-filter__placeholder" | ||
/> | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
const deprecated = [ v1 ]; | ||
|
||
export default deprecated; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import classNames from 'classnames'; | ||
import { useBlockProps } from '@wordpress/block-editor'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import metadata from './block.json'; | ||
import { blockAttributes } from './attributes'; | ||
import type { Attributes } from './types'; | ||
|
||
const v1 = { | ||
attributes: { | ||
...metadata.attributes, | ||
showCounts: { | ||
type: 'boolean', | ||
default: true, | ||
}, | ||
...blockAttributes, | ||
}, | ||
save: ( { attributes }: { attributes: Attributes } ) => { | ||
const { | ||
className, | ||
showCounts, | ||
heading, | ||
headingLevel, | ||
showFilterButton, | ||
} = attributes; | ||
const data: Record< string, unknown > = { | ||
'data-show-counts': showCounts, | ||
'data-heading': heading, | ||
'data-heading-level': headingLevel, | ||
}; | ||
if ( showFilterButton ) { | ||
data[ 'data-show-filter-button' ] = showFilterButton; | ||
} | ||
return ( | ||
<div | ||
{ ...useBlockProps.save( { | ||
className: classNames( 'is-loading', className ), | ||
} ) } | ||
{ ...data } | ||
> | ||
<span | ||
aria-hidden | ||
className="wc-block-product-stock-filter__placeholder" | ||
/> | ||
</div> | ||
); | ||
}, | ||
}; | ||
|
||
const deprecated = [ v1 ]; | ||
|
||
export default deprecated; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters